Skip to content
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

Merged
merged 3 commits into from
Dec 10, 2024
Merged

Conversation

maykcaldas
Copy link
Collaborator

@maykcaldas maykcaldas commented Dec 9, 2024

LDP had updated since llmclient project started. Mainly, ldp.llms was changed. This PR brings the changes from chat.py and test_llms.py to llmclient.

This PR is blocking Future-House/ldp#175

@maykcaldas maykcaldas changed the title Updated llmclient with newest ldp implementations Updated llmclient with the newest ldp implementations Dec 10, 2024
@maykcaldas maykcaldas marked this pull request as ready for review December 10, 2024 00:27
Copy link
Contributor

@jamesbraza jamesbraza left a 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

Comment on lines +111 to +112
if isinstance(output_type, Mapping): # JSON schema
litellm.litellm_core_utils.json_validation_rule.validate_schema(
Copy link
Contributor

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
Copy link
Contributor

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:

  1. Moving chat_kwargs = self.config | chat_kwargs above this part of the code
  2. 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?

Copy link
Collaborator Author

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?

Copy link
Contributor

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

Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

@maykcaldas maykcaldas merged commit e8c51ee into main Dec 10, 2024
5 checks passed
@maykcaldas maykcaldas deleted the update_ldp branch December 10, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants