Skip to content

Commit

Permalink
Working tools calls on AWS.
Browse files Browse the repository at this point in the history
Add adapter instructions to the Adapter and instructions.
  • Loading branch information
scosman committed Sep 8, 2024
1 parent 867759f commit 9e9cca9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion libs/core/kiln_ai/adapters/base_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ async def invoke(self, input: str) -> Dict | str:
async def _run(self, input: str) -> Dict | str:
pass

# override for provider specific instructions (e.g. json format instead of tool call)
def adapter_specific_instructions(self) -> str | None:
if self._is_structured:
return "Always respond with a tool call. Never respond with a human readable message."
return None


class BasePromptBuilder(metaclass=ABCMeta):
def __init__(self, task: Task):
def __init__(self, task: Task, adapter: BaseAdapter | None = None):
self.task = task
self.adapter = adapter

@abstractmethod
def build_prompt(self, input: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions libs/core/kiln_ai/adapters/langchain_adapters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Dict

import kiln_ai.datamodel.models as models
Expand Down Expand Up @@ -47,8 +46,9 @@ def __init__(
output_schema, include_raw=True
)
if prompt_builder is None:
self.prompt_builder = SimplePromptBuilder(kiln_task)
self.prompt_builder = SimplePromptBuilder(task=kiln_task, adapter=self)
else:
prompt_builder.adapter = self
self.prompt_builder = prompt_builder

async def _run(self, input: str) -> Dict | str:
Expand Down
5 changes: 5 additions & 0 deletions libs/core/kiln_ai/adapters/prompt_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def build_prompt(self, input: str) -> str:
for i, requirement in enumerate(self.task.requirements()):
base_prompt += f"{i+1}) {requirement.instruction}\n"

if self.adapter is not None:
adapter_instructions = self.adapter.adapter_specific_instructions()
if adapter_instructions is not None:
base_prompt += f"\n\n{adapter_instructions}\n\n"

# TODO: should be another message, not just appended to prompt
base_prompt += f"\n\nThe input is:\n{input}"
return base_prompt
2 changes: 1 addition & 1 deletion libs/core/kiln_ai/adapters/test_structured_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def test_structured_output_groq(tmp_path):

@pytest.mark.paid
async def test_structured_output_bedrock(tmp_path):
await run_structured_output_test(tmp_path, "mistral_large", "amazon_bedrock")
await run_structured_output_test(tmp_path, "llama_3_1_8b", "amazon_bedrock")


@pytest.mark.ollama
Expand Down
1 change: 0 additions & 1 deletion libs/core/kiln_ai/datamodel/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from enum import Enum, IntEnum
from typing import Dict

Expand Down

0 comments on commit 9e9cca9

Please sign in to comment.