Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit fe30be6
Author: Ankush Gola <9536492+agola11@users.noreply.github.com>
Date:   Wed Mar 1 21:55:43 2023 -0800

    add async and streaming support to `OpenAIChat` (langchain-ai#1378)

    title says it all

commit cfed049
Author: Lakshya Agarwal <lakshyajannu@gmail.com>
Date:   Thu Mar 2 10:48:09 2023 +0530

    Minor grammatical fixes (langchain-ai#1325)

    Fixed typos and links in a few places across documents

commit 59157b6
Author: Ryan Dao <daoduyducduong@gmail.com>
Date:   Wed Mar 1 21:15:27 2023 -0800

    Bug: Fix Python version validation in PythonAstREPLTool (langchain-ai#1373)

    The current logic checks if the Python major version is < 8, which is
    wrong. This checks if the major and minor version is < 3.9.

commit e178008
Author: Harrison Chase <hw.chase.17@gmail.com>
Date:   Wed Mar 1 21:15:13 2023 -0800

    Harrison/track token usage (langchain-ai#1382)

    Co-authored-by: Zak King <zaking17@gmail.com>

commit 1cd8996
Author: Harrison Chase <hw.chase.17@gmail.com>
Date:   Wed Mar 1 20:59:07 2023 -0800

    Harrison/summarizer chain (langchain-ai#1356)

    Co-authored-by: Tim Asp <707699+timothyasp@users.noreply.github.com>

commit cfae030
Author: yakigac <10434946+yakigac@users.noreply.github.com>
Date:   Thu Mar 2 11:24:32 2023 +0900

    Fix the openaichat example (langchain-ai#1377)

    The example was wrong.

commit 4b5e850
Author: Harrison Chase <hw.chase.17@gmail.com>
Date:   Wed Mar 1 11:47:01 2023 -0800

    chatgpt wrapper (langchain-ai#1367)

commit 4d4b43c
Author: Harrison Chase <hw.chase.17@gmail.com>
Date:   Wed Mar 1 09:40:31 2023 -0800

    fix doc names (langchain-ai#1354)

commit c01f910
Author: Harrison Chase <hw.chase.17@gmail.com>
Date:   Wed Mar 1 08:20:24 2023 -0800

    bump version to 0097 (langchain-ai#1365)

commit edb3915
Author: Christie Jacob <christeejacobs@gmail.com>
Date:   Wed Mar 1 19:21:37 2023 +0400

    typo in vectorstores (langchain-ai#1362)

commit fe7dbec
Author: Harrison Chase <hw.chase.17@gmail.com>
Date:   Tue Feb 28 22:19:11 2023 -0800

    pandas and csv agents (langchain-ai#1353)
  • Loading branch information
ash0ts committed Mar 2, 2023
1 parent 64146a0 commit 940ff0f
Show file tree
Hide file tree
Showing 51 changed files with 3,455 additions and 139 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Please see [here](https://langchain.readthedocs.io/en/latest/?) for full documen
- Getting started (installation, setting up the environment, simple examples)
- How-To examples (demos, integrations, helper functions)
- Reference (full API docs)
Resources (high-level explanation of core concepts)
- Resources (high-level explanation of core concepts)

## 🚀 What can this help with?

Expand Down
202 changes: 202 additions & 0 deletions docs/modules/agents/agent_toolkits/csv.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "7094e328",
"metadata": {},
"source": [
"# CSV Agent\n",
"\n",
"This notebook shows how to use agents to interact with a csv. It is mostly optimized for question answering.\n",
"\n",
"**NOTE: this agent calls the Pandas DataFrame agent under the hood, which in turn calls the Python agent, which executes LLM generated Python code - this can be bad if the LLM generated Python code is harmful. Use cautiously.**\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "827982c7",
"metadata": {},
"outputs": [],
"source": [
"from langchain.agents import create_csv_agent"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "caae0bec",
"metadata": {},
"outputs": [],
"source": [
"from langchain.llms import OpenAI"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "16c4dc59",
"metadata": {},
"outputs": [],
"source": [
"agent = create_csv_agent(OpenAI(temperature=0), 'titanic.csv', verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "46b9489d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mThought: I need to count the number of rows\n",
"Action: python_repl_ast\n",
"Action Input: len(df)\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3m891\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n",
"Final Answer: There are 891 rows in the dataframe.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"'There are 891 rows in the dataframe.'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"agent.run(\"how many rows are there?\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a96309be",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mThought: I need to count the number of people with more than 3 siblings\n",
"Action: python_repl_ast\n",
"Action Input: df[df['SibSp'] > 3].shape[0]\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3m30\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n",
"Final Answer: 30 people have more than 3 siblings.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"'30 people have more than 3 siblings.'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"agent.run(\"how many people have more than 3 sibligngs\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "964a09f7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mThought: I need to calculate the average age first\n",
"Action: python_repl_ast\n",
"Action Input: df['Age'].mean()\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3m29.69911764705882\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I can now calculate the square root\n",
"Action: python_repl_ast\n",
"Action Input: math.sqrt(df['Age'].mean())\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mname 'math' is not defined\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I need to import the math library\n",
"Action: python_repl_ast\n",
"Action Input: import math\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3mNone\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I can now calculate the square root\n",
"Action: python_repl_ast\n",
"Action Input: math.sqrt(df['Age'].mean())\u001b[0m\n",
"Observation: \u001b[36;1m\u001b[1;3m5.449689683556195\u001b[0m\n",
"Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n",
"Final Answer: 5.449689683556195\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"'5.449689683556195'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"agent.run(\"whats the square root of the average age?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "551de2be",
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 940ff0f

Please sign in to comment.