Add reasoning parameter to ModelSettings (#388)
fixes #189 @rm-openai Would really appreciate if this can get a quick review. --------- Co-authored-by: Rohan Mehta <rm@openai.com>
This commit is contained in:
parent
0110f3ad96
commit
07a627e8eb
3 changed files with 12 additions and 0 deletions
|
|
@ -3,6 +3,8 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass, fields, replace
|
||||
from typing import Literal
|
||||
|
||||
from openai.types.shared import Reasoning
|
||||
|
||||
|
||||
@dataclass
|
||||
class ModelSettings:
|
||||
|
|
@ -40,6 +42,11 @@ class ModelSettings:
|
|||
max_tokens: int | None = None
|
||||
"""The maximum number of output tokens to generate."""
|
||||
|
||||
reasoning: Reasoning | None = None
|
||||
"""Configuration options for
|
||||
[reasoning models](https://platform.openai.com/docs/guides/reasoning).
|
||||
"""
|
||||
|
||||
metadata: dict[str, str] | None = None
|
||||
"""Metadata to include with the model response call."""
|
||||
|
||||
|
|
|
|||
|
|
@ -521,6 +521,8 @@ class OpenAIChatCompletionsModel(Model):
|
|||
# Match the behavior of Responses where store is True when not given
|
||||
store = model_settings.store if model_settings.store is not None else True
|
||||
|
||||
reasoning_effort = model_settings.reasoning.effort if model_settings.reasoning else None
|
||||
|
||||
ret = await self._get_client().chat.completions.create(
|
||||
model=self.model,
|
||||
messages=converted_messages,
|
||||
|
|
@ -536,6 +538,7 @@ class OpenAIChatCompletionsModel(Model):
|
|||
stream=stream,
|
||||
stream_options={"include_usage": True} if stream else NOT_GIVEN,
|
||||
store=store,
|
||||
reasoning_effort=self._non_null_or_not_given(reasoning_effort),
|
||||
extra_headers=_HEADERS,
|
||||
metadata=model_settings.metadata,
|
||||
)
|
||||
|
|
@ -556,6 +559,7 @@ class OpenAIChatCompletionsModel(Model):
|
|||
temperature=model_settings.temperature,
|
||||
tools=[],
|
||||
parallel_tool_calls=parallel_tool_calls or False,
|
||||
reasoning=model_settings.reasoning,
|
||||
)
|
||||
return response, ret
|
||||
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ class OpenAIResponsesModel(Model):
|
|||
extra_headers=_HEADERS,
|
||||
text=response_format,
|
||||
store=self._non_null_or_not_given(model_settings.store),
|
||||
reasoning=self._non_null_or_not_given(model_settings.reasoning),
|
||||
metadata=model_settings.metadata,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue