mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-09 06:53:59 +00:00
community[patch]: support named arguments in github toolkit (#24986)
Parameters may be passed in by name if generated from tool calls.
This commit is contained in:
@@ -8,7 +8,7 @@ To use this tool, you must first set as environment variables:
|
||||
|
||||
"""
|
||||
|
||||
from typing import Optional, Type
|
||||
from typing import Any, Optional, Type
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||
@@ -30,9 +30,23 @@ class GitHubAction(BaseTool):
|
||||
self,
|
||||
instructions: Optional[str] = "",
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
**kwargs: Any,
|
||||
) -> str:
|
||||
"""Use the GitHub API to run an operation."""
|
||||
if not instructions or instructions == "{}":
|
||||
# Catch other forms of empty input that GPT-4 likes to send.
|
||||
instructions = ""
|
||||
return self.api_wrapper.run(self.mode, instructions)
|
||||
if self.args_schema is not None:
|
||||
field_names = list(self.args_schema.schema()["properties"].keys())
|
||||
if len(field_names) > 1:
|
||||
raise AssertionError(
|
||||
f"Expected one argument in tool schema, got {field_names}."
|
||||
)
|
||||
if field_names:
|
||||
field = field_names[0]
|
||||
else:
|
||||
field = ""
|
||||
query = str(kwargs.get(field, ""))
|
||||
else:
|
||||
query = instructions
|
||||
return self.api_wrapper.run(self.mode, query)
|
||||
|
Reference in New Issue
Block a user