mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
7b5e160d28
Follow-up of @hinthornw's PR: - Migrate the Tool abstraction to a separate file (`BaseTool`). - `Tool` implementation of `BaseTool` takes in function and coroutine to more easily maintain backwards compatibility - Add a Toolkit abstraction that can own the generation of tools around a shared concept or state --------- Co-authored-by: William FH <13333726+hinthornw@users.noreply.github.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Francisco Ingham <fpingham@gmail.com> Co-authored-by: Dhruv Anand <105786647+dhruv-anand-aintech@users.noreply.github.com> Co-authored-by: cragwolfe <cragcw@gmail.com> Co-authored-by: Anton Troynikov <atroyn@users.noreply.github.com> Co-authored-by: Oliver Klingefjord <oliver@klingefjord.com> Co-authored-by: William Fu-Hinthorn <whinthorn@Williams-MBP-3.attlocal.net> Co-authored-by: Bruno Bornsztein <bruno.bornsztein@gmail.com>
121 lines
3.0 KiB
Plaintext
121 lines
3.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "5371a9bb",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Tracing Walkthrough"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "17c04cc6-c93d-4b6c-a033-e897577f4ed1",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"os.environ[\"LANGCHAIN_HANDLER\"] = \"langchain\"\n",
|
|
"\n",
|
|
"## Uncomment this if using hosted setup.\n",
|
|
"\n",
|
|
"# os.environ[\"LANGCHAIN_ENDPOINT\"] = \"https://langchain-api-gateway-57eoxz8z.uc.gateway.dev\" \n",
|
|
"\n",
|
|
"## Uncomment this if you want traces to be recorded to \"my_session\" instead of default.\n",
|
|
"\n",
|
|
"# os.environ[\"LANGCHAIN_SESSION\"] = \"my_session\" \n",
|
|
"\n",
|
|
"## Better to set this environment variable in the terminal\n",
|
|
"## Uncomment this if using hosted version. Replace \"my_api_key\" with your actual API Key.\n",
|
|
"\n",
|
|
"# os.environ[\"LANGCHAIN_API_KEY\"] = \"my_api_key\" \n",
|
|
"\n",
|
|
"import langchain\n",
|
|
"from langchain.agents import Tool, initialize_agent, load_tools\n",
|
|
"from langchain.llms import OpenAI"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "bfa16b79-aa4b-4d41-a067-70d1f593f667",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"\n",
|
|
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
|
"\u001b[32;1m\u001b[1;3m I need to use a calculator to solve this.\n",
|
|
"Action: Calculator\n",
|
|
"Action Input: 2^.123243\u001b[0m\n",
|
|
"Observation: \u001b[36;1m\u001b[1;3mAnswer: 1.0891804557407723\n",
|
|
"\u001b[0m\n",
|
|
"Thought:\u001b[32;1m\u001b[1;3m I now know the final answer.\n",
|
|
"Final Answer: 1.0891804557407723\u001b[0m\n",
|
|
"\n",
|
|
"\u001b[1m> Finished chain.\u001b[0m\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'1.0891804557407723'"
|
|
]
|
|
},
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"# Agent run with tracing. Ensure that OPENAI_API_KEY is set appropriately to run this example.\n",
|
|
"\n",
|
|
"llm = OpenAI(temperature=0)\n",
|
|
"tools = load_tools([\"llm-math\"], llm=llm)\n",
|
|
"agent = initialize_agent(\n",
|
|
" tools, llm, agent=\"zero-shot-react-description\", verbose=True\n",
|
|
")\n",
|
|
"\n",
|
|
"agent.run(\"What is 2 raised to .123243 power?\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "25addd7f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.9"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|