-
Notifications
You must be signed in to change notification settings - Fork 63
fix: OpenAI base_url default and reasoning effort model option.
#271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Requested a comment.
@avinash2692 : after adding the comment please feel free to break glass and merge without a code review.
@avinash2692: FYI, NVM. I'm rolling the fix to #274 into this PR. That fix requires discussion with the rest of the core team to make sure there are no objections or subtle bugs introduced by defaulting to self._base_url = None for the OpenAI backend.
| # Build optional reasoning parameters | ||
| reasoning_params = {} | ||
| if thinking is not None: | ||
| reasoning_params["reasoning_effort"] = thinking | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a comment noting that OpenAI doesn't like it when non-reasoning models get reasoning parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
|
FYI @jakelorocco and @HendrikStrobelt: We currently default to ollama when the user instantiates the OpenAI backend without a Now, if the user types: import mellea
mellea.start_session(backend_name="openai", api_key="...")then the OpenAI SDK's default endpoint will be used. However, if the user types: import mellea
mellea.start_session(backend_name="openai")without an API key argument, then the ollama backend will be used and a warning will be printed. Note that the user must still explicitly provide an |
base_url default and reasoning effort model option.
This default is changed because the default base_url is also changed.
The OpenAI response_format only accepts a limited set of schemas and will error out with a 400 if you do not follow their guidelines. One of these guidelines is that additionalProperties is set and is set to False. This commit monkey-patches the response_format provided to OpenAI platform backends, and leaves other OpenAI-"compatible" backends with the existing default behavior. This is a debatable choice. See https://community.openai.com/t/api-rejects-valid-json-schema/906163 and https://platform.openai.com/docs/guides/structured-outputs?api-mode=chat
|
We should also review @jakelorocco 's notes in #141 before merging. |
| if api_key is None: | ||
| FancyLogger.get_logger().warning( | ||
| "You are using an OpenAI backend with no api_key. Because no API key was provided, mellea assumes you intend to use the openai-compatible interface to your local ollama instance. If you intend to use OpenAI's platform you must specify your API key when instantiating your Mellea session/backend object." | ||
| ) | ||
| self._base_url: str | None = "http://localhost:11434/v1" # ollama | ||
| self._api_key = "ollama" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are close to defaults that make sense here. I think if the user specifies a base_url we should always use that base_url (even if no apikey is set). I also wonder if we should default the apikey to ollama in those situations.
Otherwise, we have no way to target arbitrary localhost ports that don't require an apikey.
For example (and this isn't the best since it uses LiteLLM and we have a separate backend for that), LiteLLM has a proxy that you can run locally. This proxy stores the apikey information itself; so you can target an arbitrary localhost port without an apikey.
My proposed solution would be to just set the parameter default values to work for the ollama version (ie api_key="ollama" and base_url="http://localhost:11434/v1"). Then users can override these values. I think this would also allow users to explicitly set api_key / base_url to None and have the underlying OpenAI SDK still automatically pick up their env vars (without the risk of users accidentally incurring expenses).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consensus: just pass the args through to the openai sdk. Don't do argument handling such as this.
This issues fixes everything but the model id selection mentioned in #141. I'm ambivalent on if we actually want to handle that "smartly" or just make users choose the specific name themselves when we pick wrongly. We could develop a heuristic for it based on base_urls, but that seems prone to errors. If others agree, we can close #141 when this PR is merged. |
…generative-computing/mellea into fix/270-openai-reasoning-effort
Discussed in leads. In the initializer, these lines of code need to change: New logic:
Also ensure that this is dead code and then delete: mellea/mellea/backends/openai.py Lines 1009 to 1029 in e7e161b
Resolution assigned to @avinash2692 |
additionalPropertiesis not set toFalseonresponse_formats generated byGenerativeSlot. This causedGenerativeSlotto not work with OpenAI platform's API.