Spaces:
No application file
No application file
ENUGANDHULA NILESH
commited on
Delete tools_agents1.ipynb
Browse files- tools_agents1.ipynb +0 -542
tools_agents1.ipynb
DELETED
@@ -1,542 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": 1,
|
6 |
-
"metadata": {},
|
7 |
-
"outputs": [],
|
8 |
-
"source": [
|
9 |
-
"# arxiv-Research\n",
|
10 |
-
"from langchain_community.tools import ArxivQueryRun,WikipediaQueryRun\n",
|
11 |
-
"from langchain_community.utilities import WikipediaAPIWrapper,ArxivAPIWrapper"
|
12 |
-
]
|
13 |
-
},
|
14 |
-
{
|
15 |
-
"cell_type": "code",
|
16 |
-
"execution_count": 2,
|
17 |
-
"metadata": {},
|
18 |
-
"outputs": [
|
19 |
-
{
|
20 |
-
"data": {
|
21 |
-
"text/plain": [
|
22 |
-
"'wikipedia'"
|
23 |
-
]
|
24 |
-
},
|
25 |
-
"execution_count": 2,
|
26 |
-
"metadata": {},
|
27 |
-
"output_type": "execute_result"
|
28 |
-
}
|
29 |
-
],
|
30 |
-
"source": [
|
31 |
-
"# we used the inbulit tool of wikipedia\n",
|
32 |
-
"api_wrapper_wiki=WikipediaAPIWrapper(top_k_results=1,doc_content_chars_max=250)\n",
|
33 |
-
"wiki=WikipediaQueryRun(api_wrapper=api_wrapper_wiki)\n",
|
34 |
-
"wiki.name\n"
|
35 |
-
]
|
36 |
-
},
|
37 |
-
{
|
38 |
-
"cell_type": "code",
|
39 |
-
"execution_count": 3,
|
40 |
-
"metadata": {},
|
41 |
-
"outputs": [
|
42 |
-
{
|
43 |
-
"data": {
|
44 |
-
"text/plain": [
|
45 |
-
"'arxiv'"
|
46 |
-
]
|
47 |
-
},
|
48 |
-
"execution_count": 3,
|
49 |
-
"metadata": {},
|
50 |
-
"output_type": "execute_result"
|
51 |
-
}
|
52 |
-
],
|
53 |
-
"source": [
|
54 |
-
"# using inbulit arxiv tool\n",
|
55 |
-
"api_wrapper_arxiv=ArxivAPIWrapper(top_k_results=1,doc_content_chars_max=250)\n",
|
56 |
-
"arxiv=ArxivQueryRun(api_wrapper=api_wrapper_arxiv)\n",
|
57 |
-
"arxiv.name"
|
58 |
-
]
|
59 |
-
},
|
60 |
-
{
|
61 |
-
"cell_type": "code",
|
62 |
-
"execution_count": 4,
|
63 |
-
"metadata": {},
|
64 |
-
"outputs": [
|
65 |
-
{
|
66 |
-
"data": {
|
67 |
-
"text/plain": [
|
68 |
-
"[WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper(wiki_client=<module 'wikipedia' from 'd:\\\\RAG-Doc-Q&A\\\\venv\\\\lib\\\\site-packages\\\\wikipedia\\\\__init__.py'>, top_k_results=1, lang='en', load_all_available_meta=False, doc_content_chars_max=250)),\n",
|
69 |
-
" ArxivQueryRun(api_wrapper=ArxivAPIWrapper(arxiv_search=<class 'arxiv.Search'>, arxiv_exceptions=(<class 'arxiv.ArxivError'>, <class 'arxiv.UnexpectedEmptyPageError'>, <class 'arxiv.HTTPError'>), top_k_results=1, ARXIV_MAX_QUERY_LENGTH=300, continue_on_failure=False, load_max_docs=100, load_all_available_meta=False, doc_content_chars_max=250))]"
|
70 |
-
]
|
71 |
-
},
|
72 |
-
"execution_count": 4,
|
73 |
-
"metadata": {},
|
74 |
-
"output_type": "execute_result"
|
75 |
-
}
|
76 |
-
],
|
77 |
-
"source": [
|
78 |
-
"tools=[wiki,arxiv]\n",
|
79 |
-
"tools"
|
80 |
-
]
|
81 |
-
},
|
82 |
-
{
|
83 |
-
"cell_type": "code",
|
84 |
-
"execution_count": 6,
|
85 |
-
"metadata": {},
|
86 |
-
"outputs": [],
|
87 |
-
"source": [
|
88 |
-
"# creating custom tools[RAG Tool]\n",
|
89 |
-
"import os\n",
|
90 |
-
"from dotenv import load_dotenv\n",
|
91 |
-
"load_dotenv()\n",
|
92 |
-
"from langchain_groq import ChatGroq\n",
|
93 |
-
"groq_api_key=os.getenv(\"GROQ_API_KEY\")\n",
|
94 |
-
"from langchain_community.document_loaders import WebBaseLoader\n",
|
95 |
-
"from langchain_community.vectorstores import FAISS\n",
|
96 |
-
"\n",
|
97 |
-
"from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
|
98 |
-
"\n"
|
99 |
-
]
|
100 |
-
},
|
101 |
-
{
|
102 |
-
"cell_type": "code",
|
103 |
-
"execution_count": 7,
|
104 |
-
"metadata": {},
|
105 |
-
"outputs": [],
|
106 |
-
"source": [
|
107 |
-
"from langchain_community.embeddings import OllamaEmbeddings\n",
|
108 |
-
"embeddings=(\n",
|
109 |
-
" OllamaEmbeddings(model=\"gemma2:2b\")\n",
|
110 |
-
")"
|
111 |
-
]
|
112 |
-
},
|
113 |
-
{
|
114 |
-
"cell_type": "code",
|
115 |
-
"execution_count": 8,
|
116 |
-
"metadata": {},
|
117 |
-
"outputs": [
|
118 |
-
{
|
119 |
-
"data": {
|
120 |
-
"text/plain": [
|
121 |
-
"VectorStoreRetriever(tags=['FAISS', 'OllamaEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x00000168C52FDFC0>)"
|
122 |
-
]
|
123 |
-
},
|
124 |
-
"execution_count": 8,
|
125 |
-
"metadata": {},
|
126 |
-
"output_type": "execute_result"
|
127 |
-
}
|
128 |
-
],
|
129 |
-
"source": [
|
130 |
-
"loader=WebBaseLoader(\"https://docs.smith.langchain.com/\")\n",
|
131 |
-
"docs=loader.load()\n",
|
132 |
-
"documents=RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=200).split_documents(docs)\n",
|
133 |
-
"vectordb=FAISS.from_documents(documents,embeddings)\n",
|
134 |
-
"retriever=vectordb.as_retriever()\n",
|
135 |
-
"retriever"
|
136 |
-
]
|
137 |
-
},
|
138 |
-
{
|
139 |
-
"cell_type": "code",
|
140 |
-
"execution_count": 9,
|
141 |
-
"metadata": {},
|
142 |
-
"outputs": [
|
143 |
-
{
|
144 |
-
"data": {
|
145 |
-
"text/plain": [
|
146 |
-
"'langsmith-search'"
|
147 |
-
]
|
148 |
-
},
|
149 |
-
"execution_count": 9,
|
150 |
-
"metadata": {},
|
151 |
-
"output_type": "execute_result"
|
152 |
-
}
|
153 |
-
],
|
154 |
-
"source": [
|
155 |
-
"# making the retriever as retriever tool\n",
|
156 |
-
"from langchain.tools.retriever import create_retriever_tool\n",
|
157 |
-
"retriever_tool=create_retriever_tool(retriever,\"langsmith-search\",\"search any information about langsmith\")\n",
|
158 |
-
"retriever_tool.name"
|
159 |
-
]
|
160 |
-
},
|
161 |
-
{
|
162 |
-
"cell_type": "code",
|
163 |
-
"execution_count": 10,
|
164 |
-
"metadata": {},
|
165 |
-
"outputs": [
|
166 |
-
{
|
167 |
-
"data": {
|
168 |
-
"text/plain": [
|
169 |
-
"[WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper(wiki_client=<module 'wikipedia' from 'd:\\\\RAG-Doc-Q&A\\\\venv\\\\lib\\\\site-packages\\\\wikipedia\\\\__init__.py'>, top_k_results=1, lang='en', load_all_available_meta=False, doc_content_chars_max=250)),\n",
|
170 |
-
" ArxivQueryRun(api_wrapper=ArxivAPIWrapper(arxiv_search=<class 'arxiv.Search'>, arxiv_exceptions=(<class 'arxiv.ArxivError'>, <class 'arxiv.UnexpectedEmptyPageError'>, <class 'arxiv.HTTPError'>), top_k_results=1, ARXIV_MAX_QUERY_LENGTH=300, continue_on_failure=False, load_max_docs=100, load_all_available_meta=False, doc_content_chars_max=250)),\n",
|
171 |
-
" Tool(name='langsmith-search', description='search any information about langsmith', args_schema=<class 'langchain_core.tools.retriever.RetrieverInput'>, func=functools.partial(<function _get_relevant_documents at 0x00000168BD38EA70>, retriever=VectorStoreRetriever(tags=['FAISS', 'OllamaEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x00000168C52FDFC0>), document_prompt=PromptTemplate(input_variables=['page_content'], template='{page_content}'), document_separator='\\n\\n'), coroutine=functools.partial(<function _aget_relevant_documents at 0x00000168BD38EB00>, retriever=VectorStoreRetriever(tags=['FAISS', 'OllamaEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x00000168C52FDFC0>), document_prompt=PromptTemplate(input_variables=['page_content'], template='{page_content}'), document_separator='\\n\\n'))]"
|
172 |
-
]
|
173 |
-
},
|
174 |
-
"execution_count": 10,
|
175 |
-
"metadata": {},
|
176 |
-
"output_type": "execute_result"
|
177 |
-
}
|
178 |
-
],
|
179 |
-
"source": [
|
180 |
-
"tools.append(retriever_tool)\n",
|
181 |
-
"tools"
|
182 |
-
]
|
183 |
-
},
|
184 |
-
{
|
185 |
-
"cell_type": "code",
|
186 |
-
"execution_count": 11,
|
187 |
-
"metadata": {},
|
188 |
-
"outputs": [],
|
189 |
-
"source": [
|
190 |
-
"# run all this tools with agents with ll models\n",
|
191 |
-
"llm=ChatGroq(groq_api_key=groq_api_key,model_name=\"Gemma2-9b-It\")\n",
|
192 |
-
"\n"
|
193 |
-
]
|
194 |
-
},
|
195 |
-
{
|
196 |
-
"cell_type": "code",
|
197 |
-
"execution_count": 12,
|
198 |
-
"metadata": {},
|
199 |
-
"outputs": [
|
200 |
-
{
|
201 |
-
"name": "stderr",
|
202 |
-
"output_type": "stream",
|
203 |
-
"text": [
|
204 |
-
"d:\\RAG-Doc-Q&A\\venv\\lib\\site-packages\\langsmith\\client.py:5431: LangChainBetaWarning: The function `loads` is in beta. It is actively being worked on, so the API may change.\n",
|
205 |
-
" prompt = loads(json.dumps(prompt_object.manifest))\n"
|
206 |
-
]
|
207 |
-
}
|
208 |
-
],
|
209 |
-
"source": [
|
210 |
-
"# creating the prompt template\n",
|
211 |
-
"# hub a prompt templated already created and uploaded inn hub\n",
|
212 |
-
"from langchain import hub\n",
|
213 |
-
"prompt=hub.pull(\"hwchase17/openai-functions-agent\")\n",
|
214 |
-
"\n"
|
215 |
-
]
|
216 |
-
},
|
217 |
-
{
|
218 |
-
"cell_type": "code",
|
219 |
-
"execution_count": 13,
|
220 |
-
"metadata": {},
|
221 |
-
"outputs": [
|
222 |
-
{
|
223 |
-
"data": {
|
224 |
-
"text/plain": [
|
225 |
-
"[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], template='You are a helpful assistant')),\n",
|
226 |
-
" MessagesPlaceholder(variable_name='chat_history', optional=True),\n",
|
227 |
-
" HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], template='{input}')),\n",
|
228 |
-
" MessagesPlaceholder(variable_name='agent_scratchpad')]"
|
229 |
-
]
|
230 |
-
},
|
231 |
-
"execution_count": 13,
|
232 |
-
"metadata": {},
|
233 |
-
"output_type": "execute_result"
|
234 |
-
}
|
235 |
-
],
|
236 |
-
"source": [
|
237 |
-
"prompt.messages"
|
238 |
-
]
|
239 |
-
},
|
240 |
-
{
|
241 |
-
"cell_type": "code",
|
242 |
-
"execution_count": 14,
|
243 |
-
"metadata": {},
|
244 |
-
"outputs": [
|
245 |
-
{
|
246 |
-
"data": {
|
247 |
-
"text/plain": [
|
248 |
-
"RunnableAssign(mapper={\n",
|
249 |
-
" agent_scratchpad: RunnableLambda(lambda x: format_to_openai_tool_messages(x['intermediate_steps']))\n",
|
250 |
-
"})\n",
|
251 |
-
"| ChatPromptTemplate(input_variables=['agent_scratchpad', 'input'], optional_variables=['chat_history'], input_types={'chat_history': typing.List[typing.Union[langchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage]], 'agent_scratchpad': typing.List[typing.Union[langchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage]]}, partial_variables={'chat_history': []}, metadata={'lc_hub_owner': 'hwchase17', 'lc_hub_repo': 'openai-functions-agent', 'lc_hub_commit_hash': 'a1655024b06afbd95d17449f21316291e0726f13dcfaf990cc0d18087ad689a5'}, messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], template='You are a helpful assistant')), MessagesPlaceholder(variable_name='chat_history', optional=True), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], template='{input}')), MessagesPlaceholder(variable_name='agent_scratchpad')])\n",
|
252 |
-
"| RunnableBinding(bound=ChatGroq(client=<groq.resources.chat.completions.Completions object at 0x00000168DD512CE0>, async_client=<groq.resources.chat.completions.AsyncCompletions object at 0x00000168DD511A20>, model_name='Gemma2-9b-It', groq_api_key=SecretStr('**********')), kwargs={'tools': [{'type': 'function', 'function': {'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.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'query to look up on wikipedia', 'type': 'string'}}, 'required': ['query']}}}, {'type': 'function', 'function': {'name': 'arxiv', 'description': 'A wrapper around Arxiv.org Useful for when you need to answer questions about Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, Statistics, Electrical Engineering, and Economics from scientific articles on arxiv.org. Input should be a search query.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'search query to look up', 'type': 'string'}}, 'required': ['query']}}}, {'type': 'function', 'function': {'name': 'langsmith-search', 'description': 'search any information about langsmith', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'query to look up in retriever', 'type': 'string'}}, 'required': ['query']}}}]})\n",
|
253 |
-
"| OpenAIToolsAgentOutputParser()"
|
254 |
-
]
|
255 |
-
},
|
256 |
-
"execution_count": 14,
|
257 |
-
"metadata": {},
|
258 |
-
"output_type": "execute_result"
|
259 |
-
}
|
260 |
-
],
|
261 |
-
"source": [
|
262 |
-
"from langchain.agents import create_openai_tools_agent\n",
|
263 |
-
"agent=create_openai_tools_agent(llm,tools,prompt)\n",
|
264 |
-
"agent"
|
265 |
-
]
|
266 |
-
},
|
267 |
-
{
|
268 |
-
"cell_type": "code",
|
269 |
-
"execution_count": 15,
|
270 |
-
"metadata": {},
|
271 |
-
"outputs": [
|
272 |
-
{
|
273 |
-
"data": {
|
274 |
-
"text/plain": [
|
275 |
-
"AgentExecutor(verbose=True, agent=RunnableMultiActionAgent(runnable=RunnableAssign(mapper={\n",
|
276 |
-
" agent_scratchpad: RunnableLambda(lambda x: format_to_openai_tool_messages(x['intermediate_steps']))\n",
|
277 |
-
"})\n",
|
278 |
-
"| ChatPromptTemplate(input_variables=['agent_scratchpad', 'input'], optional_variables=['chat_history'], input_types={'chat_history': typing.List[typing.Union[langchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage]], 'agent_scratchpad': typing.List[typing.Union[langchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage]]}, partial_variables={'chat_history': []}, metadata={'lc_hub_owner': 'hwchase17', 'lc_hub_repo': 'openai-functions-agent', 'lc_hub_commit_hash': 'a1655024b06afbd95d17449f21316291e0726f13dcfaf990cc0d18087ad689a5'}, messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], template='You are a helpful assistant')), MessagesPlaceholder(variable_name='chat_history', optional=True), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['input'], template='{input}')), MessagesPlaceholder(variable_name='agent_scratchpad')])\n",
|
279 |
-
"| RunnableBinding(bound=ChatGroq(client=<groq.resources.chat.completions.Completions object at 0x00000168DD512CE0>, async_client=<groq.resources.chat.completions.AsyncCompletions object at 0x00000168DD511A20>, model_name='Gemma2-9b-It', groq_api_key=SecretStr('**********')), kwargs={'tools': [{'type': 'function', 'function': {'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.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'query to look up on wikipedia', 'type': 'string'}}, 'required': ['query']}}}, {'type': 'function', 'function': {'name': 'arxiv', 'description': 'A wrapper around Arxiv.org Useful for when you need to answer questions about Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, Statistics, Electrical Engineering, and Economics from scientific articles on arxiv.org. Input should be a search query.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'search query to look up', 'type': 'string'}}, 'required': ['query']}}}, {'type': 'function', 'function': {'name': 'langsmith-search', 'description': 'search any information about langsmith', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'query to look up in retriever', 'type': 'string'}}, 'required': ['query']}}}]})\n",
|
280 |
-
"| OpenAIToolsAgentOutputParser(), input_keys_arg=[], return_keys_arg=[], stream_runnable=True), tools=[WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper(wiki_client=<module 'wikipedia' from 'd:\\\\RAG-Doc-Q&A\\\\venv\\\\lib\\\\site-packages\\\\wikipedia\\\\__init__.py'>, top_k_results=1, lang='en', load_all_available_meta=False, doc_content_chars_max=250)), ArxivQueryRun(api_wrapper=ArxivAPIWrapper(arxiv_search=<class 'arxiv.Search'>, arxiv_exceptions=(<class 'arxiv.ArxivError'>, <class 'arxiv.UnexpectedEmptyPageError'>, <class 'arxiv.HTTPError'>), top_k_results=1, ARXIV_MAX_QUERY_LENGTH=300, continue_on_failure=False, load_max_docs=100, load_all_available_meta=False, doc_content_chars_max=250)), Tool(name='langsmith-search', description='search any information about langsmith', args_schema=<class 'langchain_core.tools.retriever.RetrieverInput'>, func=functools.partial(<function _get_relevant_documents at 0x00000168BD38EA70>, retriever=VectorStoreRetriever(tags=['FAISS', 'OllamaEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x00000168C52FDFC0>), document_prompt=PromptTemplate(input_variables=['page_content'], template='{page_content}'), document_separator='\\n\\n'), coroutine=functools.partial(<function _aget_relevant_documents at 0x00000168BD38EB00>, retriever=VectorStoreRetriever(tags=['FAISS', 'OllamaEmbeddings'], vectorstore=<langchain_community.vectorstores.faiss.FAISS object at 0x00000168C52FDFC0>), document_prompt=PromptTemplate(input_variables=['page_content'], template='{page_content}'), document_separator='\\n\\n'))])"
|
281 |
-
]
|
282 |
-
},
|
283 |
-
"execution_count": 15,
|
284 |
-
"metadata": {},
|
285 |
-
"output_type": "execute_result"
|
286 |
-
}
|
287 |
-
],
|
288 |
-
"source": [
|
289 |
-
"# to run the we create a agent executer\n",
|
290 |
-
"from langchain.agents import AgentExecutor\n",
|
291 |
-
"agent_executer=AgentExecutor(agent=agent,tools=tools,verbose=True)\n",
|
292 |
-
"agent_executer\n"
|
293 |
-
]
|
294 |
-
},
|
295 |
-
{
|
296 |
-
"cell_type": "code",
|
297 |
-
"execution_count": 23,
|
298 |
-
"metadata": {},
|
299 |
-
"outputs": [],
|
300 |
-
"source": [
|
301 |
-
"# from langchain_experimental.llms.ollama_functions import OllamaFunctions\n",
|
302 |
-
"\n",
|
303 |
-
"# model = OllamaFunctions(model=\"llama3\", format=\"json\")"
|
304 |
-
]
|
305 |
-
},
|
306 |
-
{
|
307 |
-
"cell_type": "code",
|
308 |
-
"execution_count": 16,
|
309 |
-
"metadata": {},
|
310 |
-
"outputs": [
|
311 |
-
{
|
312 |
-
"name": "stdout",
|
313 |
-
"output_type": "stream",
|
314 |
-
"text": [
|
315 |
-
"\n",
|
316 |
-
"\n",
|
317 |
-
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
318 |
-
"\u001b[32;1m\u001b[1;3m\n",
|
319 |
-
"Invoking: `langsmith-search` with `{'query': 'Langsmith'}`\n",
|
320 |
-
"\n",
|
321 |
-
"\n",
|
322 |
-
"\u001b[0m\u001b[38;5;200m\u001b[1;3mGet started with LangSmith | ü¶úÔ∏èüõ†Ô∏è LangSmith\n",
|
323 |
-
"\n",
|
324 |
-
"description=\"A sample dataset in LangSmith.\")client.create_examples( inputs=[ {\"postfix\": \"to LangSmith\"}, {\"postfix\": \"to Evaluations in LangSmith\"}, ], outputs=[ {\"output\": \"Welcome to LangSmith\"}, {\"output\": \"Welcome to Evaluations in LangSmith\"}, ], dataset_id=dataset.id,)# Define your evaluatordef exact_match(run, example): return {\"score\": run.outputs[\"output\"] == example.outputs[\"output\"]}experiment_results = evaluate( lambda input: \"Welcome \" + input['postfix'], # Your AI system goes here data=dataset_name, # The data to predict and grade over evaluators=[exact_match], # The evaluators to score the results experiment_prefix=\"sample-experiment\", # The name of the experiment metadata={ \"version\": \"1.0.0\", \"revision_id\": \"beta\" },)import { Client, Run, Example } from \"langsmith\";import { evaluate } from \"langsmith/evaluation\";import { EvaluationResult } from \"langsmith/evaluation\";const client = new\n",
|
325 |
-
"\n",
|
326 |
-
"OPENAI_API_KEY=<your-openai-api-key>4. Log your first trace‚ÄãTracing to LangSmith for LangChain usersThere is no need to use the LangSmith SDK directly if your application is built entirely on LangChain (either Python and JS).We've outlined a tracing guide specifically for LangChain users here.We provide multiple ways to log traces to LangSmith. Below, we'll highlight\n",
|
327 |
-
"\n",
|
328 |
-
"Skip to main contentGo to API DocsSearchRegionUSEUGo to AppQuick startTutorialsHow-to guidesConceptsReferencePricingSelf-hostingLangGraph CloudQuick startOn this pageGet started with LangSmithLangSmith is a platform for building production-grade LLM applications. It allows you to closely monitor and evaluate your application, so you can ship quickly and with confidence. Use of LangChain is not necessary - LangSmith works on its own!1. Install LangSmith‚ÄãPythonTypeScriptpip install -U langsmithyarn add langsmith2. Create an API key‚ÄãTo create an API key head to the Settings page. Then click Create API Key.3. Set up your environment‚ÄãShellexport LANGCHAIN_TRACING_V2=trueexport LANGCHAIN_API_KEY=<your-api-key># The below examples use the OpenAI API, though it's not necessary in generalexport OPENAI_API_KEY=<your-openai-api-key>4. Log your first trace‚ÄãTracing to LangSmith for LangChain usersThere is no need to use the LangSmith SDK directly if your application is built entirely on\u001b[0m\u001b[32;1m\u001b[1;3mLangSmith is a platform for building production-grade LLM applications. It allows you to closely monitor and evaluate your application, so you can ship quickly and with confidence.\u001b[0m\n",
|
329 |
-
"\n",
|
330 |
-
"\u001b[1m> Finished chain.\u001b[0m\n"
|
331 |
-
]
|
332 |
-
},
|
333 |
-
{
|
334 |
-
"data": {
|
335 |
-
"text/plain": [
|
336 |
-
"{'input': 'Tell me about Langsmith',\n",
|
337 |
-
" 'output': 'LangSmith is a platform for building production-grade LLM applications. It allows you to closely monitor and evaluate your application, so you can ship quickly and with confidence.'}"
|
338 |
-
]
|
339 |
-
},
|
340 |
-
"execution_count": 16,
|
341 |
-
"metadata": {},
|
342 |
-
"output_type": "execute_result"
|
343 |
-
}
|
344 |
-
],
|
345 |
-
"source": [
|
346 |
-
"agent_executer.invoke({\"input\":\"Tell me about Langsmith\"})"
|
347 |
-
]
|
348 |
-
},
|
349 |
-
{
|
350 |
-
"cell_type": "code",
|
351 |
-
"execution_count": 17,
|
352 |
-
"metadata": {},
|
353 |
-
"outputs": [
|
354 |
-
{
|
355 |
-
"name": "stdout",
|
356 |
-
"output_type": "stream",
|
357 |
-
"text": [
|
358 |
-
"\n",
|
359 |
-
"\n",
|
360 |
-
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
361 |
-
"\u001b[32;1m\u001b[1;3m\n",
|
362 |
-
"Invoking: `wikipedia` with `{'query': 'Large language model'}`\n",
|
363 |
-
"\n",
|
364 |
-
"\n",
|
365 |
-
"\u001b[0m\u001b[36;1m\u001b[1;3mPage: Large language model\n",
|
366 |
-
"Summary: A large language model (LLM) is a computational model capable of language generation or other natural language processing tasks. As language models, LLMs acquire these abilities by learning statistical relationship\u001b[0m\u001b[32;1m\u001b[1;3mLarge language models (LLMs) are a type of artificial intelligence that excel at understanding and generating human language. \n",
|
367 |
-
"\n",
|
368 |
-
"They are trained on massive datasets of text and code, allowing them to learn patterns and relationships within language. This enables them to perform a wide range of tasks, including:\n",
|
369 |
-
"\n",
|
370 |
-
"* **Text Generation:** Writing stories, articles, poems, and other types of creative content.\n",
|
371 |
-
"* **Translation:** Converting text from one language to another.\n",
|
372 |
-
"* **Summarization:** Condensing large amounts of text into shorter summaries.\n",
|
373 |
-
"* **Question Answering:** Providing answers to questions based on given information.\n",
|
374 |
-
"* **Code Generation:** Writing computer code in various programming languages.\n",
|
375 |
-
"\n",
|
376 |
-
"LLMs have the potential to revolutionize many industries, from customer service and education to research and entertainment.\n",
|
377 |
-
"\n",
|
378 |
-
"\n",
|
379 |
-
"\n",
|
380 |
-
"\u001b[0m\n",
|
381 |
-
"\n",
|
382 |
-
"\u001b[1m> Finished chain.\u001b[0m\n"
|
383 |
-
]
|
384 |
-
},
|
385 |
-
{
|
386 |
-
"data": {
|
387 |
-
"text/plain": [
|
388 |
-
"{'input': 'tell me about llm models',\n",
|
389 |
-
" 'output': 'Large language models (LLMs) are a type of artificial intelligence that excel at understanding and generating human language. \\n\\nThey are trained on massive datasets of text and code, allowing them to learn patterns and relationships within language. This enables them to perform a wide range of tasks, including:\\n\\n* **Text Generation:** Writing stories, articles, poems, and other types of creative content.\\n* **Translation:** Converting text from one language to another.\\n* **Summarization:** Condensing large amounts of text into shorter summaries.\\n* **Question Answering:** Providing answers to questions based on given information.\\n* **Code Generation:** Writing computer code in various programming languages.\\n\\nLLMs have the potential to revolutionize many industries, from customer service and education to research and entertainment.\\n\\n\\n\\n'}"
|
390 |
-
]
|
391 |
-
},
|
392 |
-
"execution_count": 17,
|
393 |
-
"metadata": {},
|
394 |
-
"output_type": "execute_result"
|
395 |
-
}
|
396 |
-
],
|
397 |
-
"source": [
|
398 |
-
"agent_executer.invoke({\"input\":\"tell me about llm models\"})"
|
399 |
-
]
|
400 |
-
},
|
401 |
-
{
|
402 |
-
"cell_type": "code",
|
403 |
-
"execution_count": 19,
|
404 |
-
"metadata": {},
|
405 |
-
"outputs": [
|
406 |
-
{
|
407 |
-
"name": "stdout",
|
408 |
-
"output_type": "stream",
|
409 |
-
"text": [
|
410 |
-
"\n",
|
411 |
-
"\n",
|
412 |
-
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
413 |
-
"\u001b[32;1m\u001b[1;3m\n",
|
414 |
-
"Invoking: `arxiv` with `{'query': '1706.03762'}`\n",
|
415 |
-
"\n",
|
416 |
-
"\n",
|
417 |
-
"\u001b[0m\u001b[33;1m\u001b[1;3mPublished: 2023-08-02\n",
|
418 |
-
"Title: Attention Is All You Need\n",
|
419 |
-
"Authors: Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin\n",
|
420 |
-
"Summary: The dominant sequence transduction models are based on c\u001b[0m\u001b[32;1m\u001b[1;3m\"Attention Is All You Need\" is a groundbreaking paper in the field of natural language processing that introduces the Transformer architecture. \n",
|
421 |
-
"\n",
|
422 |
-
"This architecture relies entirely on attention mechanisms, dispensing with recurrent or convolutional networks altogether. The Transformer has revolutionized the field, leading to significant improvements in machine translation, text summarization, and other NLP tasks. \n",
|
423 |
-
"\u001b[0m\n",
|
424 |
-
"\n",
|
425 |
-
"\u001b[1m> Finished chain.\u001b[0m\n"
|
426 |
-
]
|
427 |
-
},
|
428 |
-
{
|
429 |
-
"data": {
|
430 |
-
"text/plain": [
|
431 |
-
"{'input': 'what the paper 1706.03762 about?',\n",
|
432 |
-
" 'output': '\"Attention Is All You Need\" is a groundbreaking paper in the field of natural language processing that introduces the Transformer architecture. \\n\\nThis architecture relies entirely on attention mechanisms, dispensing with recurrent or convolutional networks altogether. The Transformer has revolutionized the field, leading to significant improvements in machine translation, text summarization, and other NLP tasks. \\n'}"
|
433 |
-
]
|
434 |
-
},
|
435 |
-
"execution_count": 19,
|
436 |
-
"metadata": {},
|
437 |
-
"output_type": "execute_result"
|
438 |
-
}
|
439 |
-
],
|
440 |
-
"source": [
|
441 |
-
"agent_executer.invoke({\"input\":\"what the paper 1706.03762 about?\"})"
|
442 |
-
]
|
443 |
-
},
|
444 |
-
{
|
445 |
-
"cell_type": "code",
|
446 |
-
"execution_count": 20,
|
447 |
-
"metadata": {},
|
448 |
-
"outputs": [
|
449 |
-
{
|
450 |
-
"name": "stdout",
|
451 |
-
"output_type": "stream",
|
452 |
-
"text": [
|
453 |
-
"\n",
|
454 |
-
"\n",
|
455 |
-
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
456 |
-
"\u001b[32;1m\u001b[1;3m\n",
|
457 |
-
"Invoking: `wikipedia` with `{'query': 'what is a summary about what i asked'}`\n",
|
458 |
-
"\n",
|
459 |
-
"\n",
|
460 |
-
"\u001b[0m\u001b[36;1m\u001b[1;3mPage: What Is a Woman?\n",
|
461 |
-
"Summary: What Is a Woman? is a 2022 American online film about gender and transgender issues, directed by Justin Folk and presented by conservative political commentator Matt Walsh. The film was released by conservative website\u001b[0m\u001b[32;1m\u001b[1;3m\n",
|
462 |
-
"Invoking: `wikipedia` with `{'query': 'what is a summary about gender and transgender issues'}`\n",
|
463 |
-
"\n",
|
464 |
-
"\n",
|
465 |
-
"\u001b[0m\u001b[36;1m\u001b[1;3mPage: What Is a Woman?\n",
|
466 |
-
"Summary: What Is a Woman? is a 2022 American online film about gender and transgender issues, directed by Justin Folk and presented by conservative political commentator Matt Walsh. The film was released by conservative website\u001b[0m\u001b[32;1m\u001b[1;3mGender and transgender issues are complex and multifaceted. \n",
|
467 |
-
"\n",
|
468 |
-
"At their core, gender and transgender identities relate to a person's internal sense of their own gender, which may or may not align with the sex they were assigned at birth. \n",
|
469 |
-
"\n",
|
470 |
-
"Transgender people have a gender identity that differs from the sex they were assigned at birth. This can involve a range of experiences, including:\n",
|
471 |
-
"\n",
|
472 |
-
"* **Transgender men:** Assigned female at birth but identify as male.\n",
|
473 |
-
"* **Transgender women:** Assigned male at birth but identify as female.\n",
|
474 |
-
"* **Non-binary:** Individuals who do not identify exclusively as male or female.\n",
|
475 |
-
"\n",
|
476 |
-
"Understanding gender and transgender issues requires recognizing that:\n",
|
477 |
-
"\n",
|
478 |
-
"* **Gender is a spectrum:** It's not simply male or female, and individuals may experience their gender in various ways.\n",
|
479 |
-
"* **Gender identity is distinct from sexual orientation:** A person's gender identity does not determine who they are attracted to.\n",
|
480 |
-
"* **Transgender identities are valid:** Transgender people deserve respect and recognition for who they are.\n",
|
481 |
-
"\n",
|
482 |
-
"\n",
|
483 |
-
"\n",
|
484 |
-
"It's important to approach these topics with sensitivity and a willingness to learn. \n",
|
485 |
-
"\u001b[0m\n",
|
486 |
-
"\n",
|
487 |
-
"\u001b[1m> Finished chain.\u001b[0m\n"
|
488 |
-
]
|
489 |
-
},
|
490 |
-
{
|
491 |
-
"data": {
|
492 |
-
"text/plain": [
|
493 |
-
"{'input': 'give me the summary about what i asked',\n",
|
494 |
-
" 'output': \"Gender and transgender issues are complex and multifaceted. \\n\\nAt their core, gender and transgender identities relate to a person's internal sense of their own gender, which may or may not align with the sex they were assigned at birth. \\n\\nTransgender people have a gender identity that differs from the sex they were assigned at birth. This can involve a range of experiences, including:\\n\\n* **Transgender men:** Assigned female at birth but identify as male.\\n* **Transgender women:** Assigned male at birth but identify as female.\\n* **Non-binary:** Individuals who do not identify exclusively as male or female.\\n\\nUnderstanding gender and transgender issues requires recognizing that:\\n\\n* **Gender is a spectrum:** It's not simply male or female, and individuals may experience their gender in various ways.\\n* **Gender identity is distinct from sexual orientation:** A person's gender identity does not determine who they are attracted to.\\n* **Transgender identities are valid:** Transgender people deserve respect and recognition for who they are.\\n\\n\\n\\nIt's important to approach these topics with sensitivity and a willingness to learn. \\n\"}"
|
495 |
-
]
|
496 |
-
},
|
497 |
-
"execution_count": 20,
|
498 |
-
"metadata": {},
|
499 |
-
"output_type": "execute_result"
|
500 |
-
}
|
501 |
-
],
|
502 |
-
"source": [
|
503 |
-
"agent_executer.invoke({\"input\":\"give me the summary about what i asked\"})"
|
504 |
-
]
|
505 |
-
},
|
506 |
-
{
|
507 |
-
"cell_type": "code",
|
508 |
-
"execution_count": null,
|
509 |
-
"metadata": {},
|
510 |
-
"outputs": [],
|
511 |
-
"source": []
|
512 |
-
},
|
513 |
-
{
|
514 |
-
"cell_type": "code",
|
515 |
-
"execution_count": null,
|
516 |
-
"metadata": {},
|
517 |
-
"outputs": [],
|
518 |
-
"source": []
|
519 |
-
}
|
520 |
-
],
|
521 |
-
"metadata": {
|
522 |
-
"kernelspec": {
|
523 |
-
"display_name": "Python 3",
|
524 |
-
"language": "python",
|
525 |
-
"name": "python3"
|
526 |
-
},
|
527 |
-
"language_info": {
|
528 |
-
"codemirror_mode": {
|
529 |
-
"name": "ipython",
|
530 |
-
"version": 3
|
531 |
-
},
|
532 |
-
"file_extension": ".py",
|
533 |
-
"mimetype": "text/x-python",
|
534 |
-
"name": "python",
|
535 |
-
"nbconvert_exporter": "python",
|
536 |
-
"pygments_lexer": "ipython3",
|
537 |
-
"version": "3.10.0"
|
538 |
-
}
|
539 |
-
},
|
540 |
-
"nbformat": 4,
|
541 |
-
"nbformat_minor": 2
|
542 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|