Name: wikipedia Description: A wrapper around Wikipedia. Useful for when you need to answer general questions about people, places, companies, facts, historical events, or other subjects. Input should be a search query. args schema: {'query': {'title': 'Query', 'description': 'query to look up on wikipedia', 'type': 'string'}} returns directly?: False
#示例:tools_custom.py from langchain_community.tools import WikipediaQueryRun from langchain_community.utilities import WikipediaAPIWrapper from pydantic import BaseModel, Field classWikiInputs(BaseModel): """维基百科工具的输入。""" query: str = Field( description="query to look up in Wikipedia, should be 3 or less words" ) tool = WikipediaQueryRun( name="wiki-tool", description="look up things in wikipedia", args_schema=WikiInputs, api_wrapper=api_wrapper, return_direct=True, ) print(tool.run("langchain"))
1 2
Page: LangChain Summary: LangChain is a framework designed to simplify the creation of applications
Name: wiki-tool Description: look up things in wikipedia args schema: {'query': {'title': 'Query', 'description': 'query to look up in Wikipedia, should be 3 or less words', 'type': 'string'}} returns directly?: True
from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit from langchain_community.utilities import SQLDatabase from langchain_openai import ChatOpenAI from langchain_community.agent_toolkits.sql.base import create_sql_agent from langchain.agents.agent_types import AgentType
db = SQLDatabase.from_uri("sqlite:///langchain.db") toolkit = SQLDatabaseToolkit(db=db, llm=ChatOpenAI(temperature=0)) print(toolkit.get_tools())
[QuerySQLDataBaseTool(description="Input to this tool is a detailed and correct SQL query, output is a result from the database. If the query is not correct, an error message will be returned. If an error is returned, rewrite the query, check the query, and try again. If you encounter an issue with Unknown column 'xxxx' in 'field list', use sql_db_schema to query the correct table fields.", db=<langchain_community.utilities.sql_database.SQLDatabase object at 0x000001D15C9749B0>), InfoSQLDatabaseTool(description='Input to this tool is a comma-separated list of tables, output is the schema and sample rows for those tables. Be sure that the tables actually exist by calling sql_db_list_tables first! Example Input: table1, table2, table3', db=<langchain_community.utilities.sql_database.SQLDatabase object at 0x000001D15C9749B0>), ListSQLDatabaseTool(db=<langchain_community.utilities.sql_database.SQLDatabase object at 0x000001D15C9749B0>), QuerySQLCheckerTool(description='Use this tool to double check if your query is correct before executing it. Always use this tool before executing a query with sql_db_query!', db=<langchain_community.utilities.sql_database.SQLDatabase object at 0x000001D15C9749B0>, llm=ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x000001D17B4453D0>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x000001D17B446D80>, temperature=0.0, openai_api_key=SecretStr('**********'), openai_proxy=''), llm_chain=LLMChain(prompt=PromptTemplate(input_variables=['dialect', 'query'], template='\n{query}\nDouble check the {dialect} query above for common mistakes, including:\n- Using NOT IN with NULL values\n- Using UNION when UNION ALL should have been used\n- Using BETWEEN for exclusive ranges\n- Data type mismatch in predicates\n- Properly quoting identifiers\n- Using the correct number of arguments for functions\n- Casting to the correct data type\n- Using the proper columns for joins\n\nIf there are any of the above mistakes, rewrite the query. If there are no mistakes, just reproduce the original query.\n\nOutput the final SQL query only.\n\nSQL Query: '), llm=ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x000001D17B4453D0>, async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x000001D17B446D80>, temperature=0.0, openai_api_key=SecretStr('**********'), openai_proxy='')))]
执行:agent_executor.invoke(“Describe the full_llm_cache table”)
Entering new SQL Agent Executor chain... Invoking: sql_db_schema with `{'table_names': 'full_llm_cache'}` CREATE TABLE full_llm_cache ( prompt VARCHAR NOT NULL, llm VARCHAR NOT NULL, idx INTEGER NOT NULL, response VARCHAR, PRIMARY KEY (prompt, llm, idx) ) /* 3 rows from full_llm_cache table: prompt llm idx response [{"lc": 1, "type": "constructor", "id": ["langchain", "schema", "messages", "HumanMessage"], "kwargs {"id": ["langchain", "chat_models", "openai", "ChatOpenAI"], "kwargs": {"max_retries": 2, "model_nam 0 {"lc": 1, "type": "constructor", "id": ["langchain", "schema", "output", "ChatGeneration"], "kwargs" */The `full_llm_cache` table has the following structure: - `prompt`: A VARCHAR field that is part of the primary key. It cannot be NULL. - `llm`: A VARCHAR field that is also part of the primary key. It cannot be NULL. - `idx`: An INTEGER field that is part of the primary key as well. It cannot be NULL. - `response`: A VARCHAR field that can contain NULL values. Here are some sample rows from the `full_llm_cache` table: | prompt | llm | idx | response | |--------|-----|-----|----------| | [{"lc": 1, "type": "constructor", "id": ["langchain", "schema", "messages", "HumanMessage"], "kwargs | {"id": ["langchain", "chat_models", "openai", "ChatOpenAI"], "kwargs": {"max_retries": 2, "model_nam | 0 | {"lc": 1, "type": "constructor", "id": ["langchain", "schema", "output", "ChatGeneration"], "kwargs" | > Finished chain.