-
Notifications
You must be signed in to change notification settings - Fork 0
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
Updated llmclient with the newest ldp implementations #21
Conversation
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.
Can we get some unit testing? I think my change had unit tests too
if isinstance(output_type, Mapping): # JSON schema | ||
litellm.litellm_core_utils.json_validation_rule.validate_schema( |
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.
To share, I used this import to work around us having to manage jsonschema
in our own deps, instead we let litellm
internals manage the implementation
@@ -705,7 +722,17 @@ async def call( # noqa: C901, PLR0915 | |||
) | |||
|
|||
# deal with specifying output type | |||
if output_type is not None: | |||
if isinstance(output_type, Mapping): # Use structured outputs |
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.
@mskarlin had a question in the original PR here: Future-House/ldp#165 (comment), which was if we can have a validation of the model name here (more or less). Since making that change, I learned of litellm.supports_response_schema("gpt-4o-2024-11-20", None)
which can enable that check. What do you think of:
- Moving
chat_kwargs = self.config | chat_kwargs
above this part of the code - Doing a brief validation here such as:
model_name: str = chat_kwargs.get("model", "")
if not litellm.supports_response_schema(model_name, None):
raise ValueError(f"Model {model_name} does not support JSON schema.")
Or, do you think we should just pass through to litellm
and either:
- If
litellm
has validations, let them check - Otherwise let the LLM API blow up with something like a 400
I am sort of in favor of the latter, which is our code here not doing validations, instead sort of "trusting the process" and letting callers get blown up with a trace terminating below llmclient
.
What do you think?
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 that allowing it to pass and blowing on the LLM API will give us more issues in the future. Because we don't know how litellm treats this, the error can be uninformative and the user will open issues here.
Since litellm already maintains a list of models that supports this schema and we can use the supports_response_schema
, wouldn't it be useful to add a brief check so we can return an informative error message?
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 guess there could be a situation where litellm
is wrong and/or out-of-date, and a validation may block us.
However, a validation also does better define the system, and add confidence in it.
I can see arguments for both sides, defer to you here
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.
Since we are using litellm as the main framework, I think it might be ok to trust it?
I added the check. Let me know what you think.
We can also remove it later if it causes any problems
@@ -724,8 +758,6 @@ async def call( # noqa: C901, PLR0915 | |||
] | |||
chat_kwargs["response_format"] = {"type": "json_object"} | |||
|
|||
# add static configuration to kwargs | |||
chat_kwargs = self.config | chat_kwargs |
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.
This was moved above to validate if the model supports the schema
LDP had updated since llmclient project started. Mainly,
ldp.llms
was changed. This PR brings the changes fromchat.py
andtest_llms.py
tollmclient
.This PR is blocking Future-House/ldp#175