-
Checked other resources
Commit to Help
Example CodeIn the old version of langchain, I used the following method to register the tool:
tools = from_function({
execute_sql_tao: get_prompt_template_prompty("tools", "execute_sql-gpt4o-v1")
})
def execute_sql_tao(sql: str):
print('\n', '【execute_sql_tool_node】')
sql = sql.replace('sql', "").replace('```', "")
data = postgres_raw_sql_query(sql, db_key='GP')
df = pd.DataFrame(data)
data = df.to_markdown()
return data
After I upgraded to the new version, I found that I could not load my prompt configuration when I registered using @tool:
```python
@tool
def new_execute_sql_tao(sql: str):
print('\n', '【execute_sql_tool_node】')
sql = sql.replace('```sql', "").replace('```', "")
data = postgres_raw_sql_query(sql, db_key='PG')
df = pd.DataFrame(data)
data = df.to_markdown()
return data
|
Beta Was this translation helpful? Give feedback.
Answered by
Huyueeer
Nov 13, 2024
Replies: 1 comment 10 replies
-
As stated in the documentation, the Tool decorator uses the function's docstring as the tool's description. Therefore, a docstring must be provided. @tool
def search(query: str) -> str:
"""Look up things online."""
return "LangChain"
print(search.description) # search(query: str) -> str - Look up things online. EDIT: from langchain.tools import StructuredTool
tool = StructuredTool.from_function(
name="<name>",
func=execute_sql_tao
description=get_prompt_template_prompty("tools", "execute_sql")
) |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much for your patience and assistance, I checked it according to your idea, and then modified the code and found that it was OK. My final modification was: