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

Gemini support refactor #36

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

QuinRiva
Copy link

@QuinRiva QuinRiva commented Mar 6, 2025

So this is a pretty substantial PR - happy to get some feedback on it, but basically getting trustcall working with Gemini was a fair bit of work.

Gemini Support

  • I've added support for Gemini, this required some pretty substantial changes because Gemini only supports a subset of Open API 3.0 and requires types to all be capitalised :(
  • When we load the schema, previously with schema_json = schema.model_json_schema() , we now instead run a check to see if the we are using Gemini, and if we are we create a Gemini compatible schema from the Pydantic model.
  • PatchFunctionErrors and PatchDoc require the JsonPatch be simplified (Gemini doesn't suport union/anyOf/oneOf for types), as such model factories approach is used to dynamically generate the classes (similar to the existing _create_patch_function_name_schema --> PatchFunctionName)
  • Gemini patches are processed as JSON Strings, so _ensure_patches needs to be updated to extract the json from the string.

Attempt count handling:

Minor update to the _ExtendValidationNode to pass the attempt count to the validation tool. This enables conditional fail-over: For example, if a field is required and should be in the JSON response but isn't, then on the first attempt we can ask for a patch (which often works), but if for some reason the data is actually missing from the source, then we can accept 'Not found' on the second attempt.
This can also be used to provide different instructions on different attempts, first attempt tell the LLM where it should look, second attempt: tell it to look in a different area, third attempt: tell it to look in another different area.

Overall Refactor

The _base.py was getting really big after these changes (>2000 lines), so I refactored it into components to be more manageable.

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.

1 participant