Skip to content

Commit

Permalink
Improve openrouter paramters
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Jan 31, 2025
1 parent 83507a6 commit 453ba88
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions libs/core/kiln_ai/adapters/model_adapters/openai_model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,22 @@ async def _run(self, input: Dict | str) -> RunOutput:
else:
intermediate_outputs = {}

extra_body = {}
if self.config.openrouter_style_reasoning:
extra_body = {
"include_reasoning": True,
# Only use providers that support the reasoning parameter
"provider": {
"require_parameters": True,
},
}

# Main completion call
response_format_options = await self.response_format_options()
response = await self.client.chat.completions.create(
model=provider.provider_options["model"],
messages=messages,
extra_body={"include_reasoning": True}
if self.config.openrouter_style_reasoning
else {},
extra_body=extra_body,
**response_format_options,
)

Expand Down
2 changes: 1 addition & 1 deletion libs/core/kiln_ai/adapters/parsers/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def parse_json_string(json_string: str) -> Dict[str, Any]:
try:
return json.loads(cleaned_string)
except json.JSONDecodeError as e:
raise ValueError(f"Failed to parse JSON: {str(e)}") from e
raise ValueError(f"Failed to parse JSON: {str(e)}\n\n{cleaned_string}") from e

0 comments on commit 453ba88

Please sign in to comment.