Skip to content

How to use gemini api? #2

@warmshao

Description

@warmshao

It appears that langchain-google-genai has not yet released a version beyond 2.0.9. If you need to use a fix related to function calling or schema handling before an official release, you can apply a manual patch. This workaround involves directly modifying the installed package files based on changes made in a recent pull request.

  1. Locate the langchain-google-genai Installation Path:

    • Use the command pip show langchain-google-genai to determine the installed location of the package.
    • For example, the output might show a path like D:\softwares\miniconda\envs\agent\Lib\site-packages\langchain_google_genai.
  2. Navigate to the Installation Directory:

    • Open your file explorer or command line and go to the directory obtained in step 1.
  3. Modify the _function_utils.py File:

    • Locate the file named _function_utils.py within the langchain_google_genai directory.
    • Open _function_utils.py with a text editor (like VS Code, Notepad++, etc.).
    • Find line 318, which likely looks like this:
      if properties_item.get("type_") == glm.Type.OBJECT:
         ... (original code)
    • Replace the original code block with the following:
      if properties_item.get("type_") == glm.Type.OBJECT:
          if (
                  v.get("anyOf")
                  and isinstance(v["anyOf"], list)
                  and isinstance(v["anyOf"][0], dict)
          ):
              v = v["anyOf"][0]
          v_properties = v.get("properties")
          if v_properties:
              properties_item["properties"] = _get_properties_from_schema_any(
                  v_properties
              )
              if isinstance(v_properties, dict):
                  properties_item["required"] = [
                      k for k, v in v_properties.items() if "default" not in v
                  ]
          else:
              # Providing dummy type for object without properties
              properties_item["type_"] = glm.Type.STRING
  4. Save the Changes:

    • Save the modified _function_utils.py file.

refer: https://github.com/langchain-ai/langchain-google/pull/658/files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions