Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Sep 10, 2024
1 parent 6416c78 commit 65ca1ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libs/core/kiln_ai/adapters/base_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
class BaseAdapter(metaclass=ABCMeta):
def __init__(self, kiln_task: Task):
self.kiln_task = kiln_task
self._is_structured = self.kiln_task.output_json_schema is not None
self._is_structured_output = self.kiln_task.output_json_schema is not None

async def invoke(self, input: str) -> Dict | str:
result = await self._run(input)
if self._is_structured:
if self._is_structured_output:
if not isinstance(result, dict):
raise RuntimeError(f"structured response is not a dict: {result}")
if self.kiln_task.output_json_schema is None:
Expand Down
6 changes: 3 additions & 3 deletions libs/core/kiln_ai/adapters/langchain_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
raise ValueError(
"model_name and provider must be provided if custom_model is not provided"
)
if self._is_structured:
if self._is_structured_output:
if not hasattr(self.model, "with_structured_output") or not callable(
getattr(self.model, "with_structured_output")
):
Expand All @@ -54,7 +54,7 @@ def __init__(

def adapter_specific_instructions(self) -> str | None:
# TODO: would be better to explicitly use bind_tools:tool_choice="task_response" here
if self._is_structured:
if self._is_structured_output:
return "Always respond with a tool call. Never respond with a human readable message."
return None

Expand All @@ -66,7 +66,7 @@ async def _run(self, input: str) -> Dict | str:
HumanMessage(content=user_msg),
]
response = self.model.invoke(messages)
if self._is_structured:
if self._is_structured_output:
if (
not isinstance(response, dict)
or "parsed" not in response
Expand Down
4 changes: 2 additions & 2 deletions libs/core/kiln_ai/adapters/prompt_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def build_prompt(self) -> str:
# TODO: this is just a quick version. Formatting and best practices TBD
if len(self.task.requirements()) > 0:
base_prompt += (
"\n\nYour response should respectthe following requirements:\n"
"\n\nYour response should respect the following requirements:\n"
)
# iterate requirements, formatting them in numbereed list like 1) task.instruction\n2)...
for i, requirement in enumerate(self.task.requirements()):
Expand All @@ -17,7 +17,7 @@ def build_prompt(self) -> str:
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"
base_prompt += f"\n\n{adapter_instructions}"

return base_prompt

Expand Down

0 comments on commit 65ca1ac

Please sign in to comment.