langchain-ai / langchain-google

MIT License
76 stars 79 forks source link

fix: convert_to_genai_function_declarations #233

Closed nobu007 closed 1 week ago

nobu007 commented 1 month ago

Fix #234.

I'm not sure the root cause. _function_utils.py is refactored with investigating.

Sorry, I didn't care vertexai side because no environment with me.

Test result

before

(gamebook) jinno@jinno-desktop:~/git/drill/gamebook/codeinterpreter_api_agent$ python ../test/test_shell_tool.py 
・・・
  File "/home/jinno/.local/share/virtualenvs/gamebook-7W9hF6PY/lib/python3.10/site-packages/langchain_google_genai/_function_utils.py", line 139, in <dictcomp>
    "type_": TYPE_ENUM[v["type"]],
KeyError: 'type'

after(with debug log)

(gamebook) jinno@jinno-desktop:~/git/drill/gamebook/codeinterpreter_api_agent$ python ../test/test_shell_tool.py 
_convert_pydantic_to_genai_function schema= {'title': 'ShellInput', 'description': 'Commands for the Bash Shell tool.', 'type': 'object', 'properties': {'commands': {'title': 'Commands', 'description': 'List of shell commands to run. Deserialized using json.loads', 'anyOf': [{'type': 'string'}, {'type': 'array', 'items': {'type': 'string'}}]}}, 'required': ['commands']}
_get_type_from_schema schema= {'title': 'Commands', 'description': 'List of shell commands to run. Deserialized using json.loads', 'anyOf': [{'type': 'string'}, {'type': 'array', 'items': {'type': 'string'}}]}
_get_type_from_schema schema= {'type': 'string'}
_get_type_from_schema schema= {'type': 'array', 'items': {'type': 'string'}}
types= [<Type.STRING: 1>, <Type.ARRAY: 5>]
_convert_pydantic_to_genai_function function_declaration= name: "terminal"
description: "Commands for the Bash Shell tool."
parameters {
  type_: OBJECT
  properties {
    key: "commands"
    value {
      type_: ARRAY
      description: "List of shell commands to run. Deserialized using json.loads"
    }
  }
  required: "commands"
}

_convert_pydantic_to_genai_function schema= {'title': 'ShellInput', 'description': 'Commands for the Bash Shell tool.', 'type': 'object', 'properties': {'commands': {'title': 'Commands', 'description': 'List of shell commands to run. Deserialized using json.loads', 'anyOf': [{'type': 'string'}, {'type': 'array', 'items': {'type': 'string'}}]}}, 'required': ['commands']}
_get_type_from_schema schema= {'title': 'Commands', 'description': 'List of shell commands to run. Deserialized using json.loads', 'anyOf': [{'type': 'string'}, {'type': 'array', 'items': {'type': 'string'}}]}
_get_type_from_schema schema= {'type': 'string'}
_get_type_from_schema schema= {'type': 'array', 'items': {'type': 'string'}}
types= [<Type.STRING: 1>, <Type.ARRAY: 5>]
_convert_pydantic_to_genai_function function_declaration= name: "terminal"
description: "Commands for the Bash Shell tool."
parameters {
  type_: OBJECT
  properties {
    key: "commands"
    value {
      type_: ARRAY
      description: "List of shell commands to run. Deserialized using json.loads"
    }
  }
  required: "commands"
}

/home/jinno/.local/share/virtualenvs/gamebook-7W9hF6PY/lib/python3.10/site-packages/langchain_community/tools/shell/tool.py:32: UserWarning: The shell tool has no safeguards by default. Use at your own risk.
  warnings.warn(
Executing command:
 ['pwd']
/home/jinno/.local/share/virtualenvs/gamebook-7W9hF6PY/lib/python3.10/site-packages/langchain_community/tools/shell/tool.py:32: UserWarning: The shell tool has no safeguards by default. Use at your own risk.
  warnings.warn(
Executing command:
 ['pwd']
result= {'input': 'please run pwd command.', 'agent_scratchpad': [], 'output': 'The current working directory is `/home/jinno/git/drill/gamebook/codeinterpreter_api_agent`. \n'}

Note

  1. This error also remained in my environment. https://github.com/google-gemini/generative-ai-python/issues/207

  2. libs/genai/langchain_google_genai/_function_utils.py still some problem remains.

lkuligin commented 1 month ago

@nobu007 thanks a lot for your contribution! could you check my comments, and also take a look at the linter errors, please.

nobu007 commented 1 month ago

I just rebased.

lkuligin commented 1 month ago

/gcbrun

lkuligin commented 1 month ago

/gcbrun

lkuligin commented 1 month ago

@nobu007 are you planning to finalize this one? there are a few linting errors, and the integration test is breaking.

nobu007 commented 1 month ago

@lkuligin I fixed as I can. But linting errors still remains. It may difficult all errrors fix in this PR. Do you have any request for merge?

lkuligin commented 1 month ago

/gcbrun

lkuligin commented 1 month ago

@lkuligin I fixed as I can. But linting errors still remains. It may difficult all errrors fix in this PR. Do you have any request for merge?

we need to fix all remaining linting errors, linter is green on other PRs

lkuligin commented 1 month ago

/gcbrun

lkuligin commented 1 week ago

/gcbrun

nobu007 commented 1 week ago

@lkuligin I fixed code as no linting errors.