langchain/docs/extras/modules/agents/toolkits/document_comparison_toolkit.ipynb

436 lines
51 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"id": "ec1d7a9a",
"metadata": {},
"source": [
"# Document Comparison\n",
"\n",
"This notebook shows how to use an agent to compare two documents.\n",
"\n",
"The high level idea is we will create a question-answering chain for each document, and then use that "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "8632a37c",
"metadata": {},
"outputs": [],
"source": [
"from pydantic import BaseModel, Field\n",
"\n",
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.agents import Tool\n",
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from langchain.text_splitter import CharacterTextSplitter\n",
"from langchain.vectorstores import FAISS\n",
"from langchain.document_loaders import PyPDFLoader\n",
"from langchain.chains import RetrievalQA"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "64f19917",
"metadata": {},
"outputs": [],
"source": [
"class DocumentInput(BaseModel):\n",
" question: str = Field()\n",
"\n",
"\n",
"llm = ChatOpenAI(temperature=0, model=\"gpt-3.5-turbo-0613\")\n",
"\n",
"tools = []\n",
"files = [\n",
" # https://abc.xyz/investor/static/pdf/2023Q1_alphabet_earnings_release.pdf\n",
" {\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
" \"name\": \"alphabet-earnings\",\n",
" \"path\": \"/Users/harrisonchase/Downloads/2023Q1_alphabet_earnings_release.pdf\",\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
" },\n",
" # https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q1-2023-Update\n",
" {\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
" \"name\": \"tesla-earnings\",\n",
" \"path\": \"/Users/harrisonchase/Downloads/TSLA-Q1-2023-Update.pdf\",\n",
" },\n",
"]\n",
"\n",
"for file in files:\n",
" loader = PyPDFLoader(file[\"path\"])\n",
" pages = loader.load_and_split()\n",
" text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
" docs = text_splitter.split_documents(pages)\n",
" embeddings = OpenAIEmbeddings()\n",
" retriever = FAISS.from_documents(docs, embeddings).as_retriever()\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
"\n",
" # Wrap retrievers in a Tool\n",
" tools.append(\n",
" Tool(\n",
" args_schema=DocumentInput,\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
" name=file[\"name\"],\n",
" description=f\"useful when you want to answer questions about {file['name']}\",\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
" func=RetrievalQA.from_chain_type(llm=llm, retriever=retriever),\n",
" )\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "eca02549",
"metadata": {},
"outputs": [],
"source": [
"from langchain.agents import initialize_agent\n",
"from langchain.agents import AgentType"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c4d56c25",
2023-06-21 14:19:52 +00:00
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\u001b[1m> Entering new chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3m\n",
"Invoking: `alphabet-earnings` with `{'question': 'revenue'}`\n",
"\n",
"\n",
2023-06-21 14:19:52 +00:00
"\u001b[0m\u001b[36;1m\u001b[1;3m{'query': 'revenue', 'result': 'The revenue for Alphabet Inc. for the quarter ended March 31, 2023, was $69,787 million.'}\u001b[0m\u001b[32;1m\u001b[1;3m\n",
"Invoking: `tesla-earnings` with `{'question': 'revenue'}`\n",
"\n",
"\n",
2023-06-21 14:19:52 +00:00
"\u001b[0m\u001b[33;1m\u001b[1;3m{'query': 'revenue', 'result': 'Total revenue for Q1-2023 was $23.3 billion.'}\u001b[0m\u001b[32;1m\u001b[1;3mAlphabet Inc. had more revenue than Tesla. Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million, while Tesla's total revenue for Q1-2023 was $23.3 billion.\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n"
]
},
{
"data": {
"text/plain": [
"{'input': 'did alphabet or tesla have more revenue?',\n",
2023-06-21 14:19:52 +00:00
" 'output': \"Alphabet Inc. had more revenue than Tesla. Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million, while Tesla's total revenue for Q1-2023 was $23.3 billion.\"}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm = ChatOpenAI(\n",
" temperature=0,\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
" model=\"gpt-3.5-turbo-0613\",\n",
")\n",
"\n",
"agent = initialize_agent(\n",
" agent=AgentType.OPENAI_FUNCTIONS,\n",
" tools=tools,\n",
" llm=llm,\n",
" verbose=True,\n",
")\n",
"\n",
"agent({\"input\": \"did alphabet or tesla have more revenue?\"})"
]
},
2023-06-21 14:19:52 +00:00
{
"cell_type": "markdown",
"id": "6f512043",
"metadata": {},
"source": [
"## OpenAI Multi Functions\n",
"\n",
"This type of agent allows calling multiple functions at once. This is really useful when some steps can be computed in parallel - like when asked to compare multiple documents"
]
},
{
"cell_type": "code",
2023-06-21 14:19:52 +00:00
"execution_count": 5,
"id": "0fb099d2",
"metadata": {},
"outputs": [],
2023-06-21 14:19:52 +00:00
"source": [
"import langchain\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
"\n",
2023-06-21 14:19:52 +00:00
"langchain.debug = True"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6db4c853",
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor] Entering Chain run with input:\n",
"\u001b[0m{\n",
" \"input\": \"did alphabet or tesla have more revenue?\"\n",
"}\n",
"\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 2:llm:ChatOpenAI] Entering LLM run with input:\n",
"\u001b[0m{\n",
" \"prompts\": [\n",
" \"System: You are a helpful AI assistant.\\nHuman: did alphabet or tesla have more revenue?\"\n",
" ]\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 2:llm:ChatOpenAI] [2.66s] Exiting LLM run with output:\n",
"\u001b[0m{\n",
" \"generations\": [\n",
" [\n",
" {\n",
" \"text\": \"\",\n",
" \"generation_info\": null,\n",
" \"message\": {\n",
" \"content\": \"\",\n",
" \"additional_kwargs\": {\n",
" \"function_call\": {\n",
" \"name\": \"tool_selection\",\n",
" \"arguments\": \"{\\n \\\"actions\\\": [\\n {\\n \\\"action_name\\\": \\\"alphabet-earnings\\\",\\n \\\"action\\\": {\\n \\\"question\\\": \\\"What was Alphabet's revenue?\\\"\\n }\\n },\\n {\\n \\\"action_name\\\": \\\"tesla-earnings\\\",\\n \\\"action\\\": {\\n \\\"question\\\": \\\"What was Tesla's revenue?\\\"\\n }\\n }\\n ]\\n}\"\n",
" }\n",
" },\n",
" \"example\": false\n",
" }\n",
" }\n",
" ]\n",
" ],\n",
" \"llm_output\": {\n",
" \"token_usage\": {\n",
" \"prompt_tokens\": 99,\n",
" \"completion_tokens\": 82,\n",
" \"total_tokens\": 181\n",
" },\n",
" \"model_name\": \"gpt-3.5-turbo-0613\"\n",
" },\n",
" \"run\": null\n",
"}\n",
"\u001b[32;1m\u001b[1;3m[tool/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings] Entering Tool run with input:\n",
"\u001b[0m\"{'question': \"What was Alphabet's revenue?\"}\"\n",
"\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA] Entering Chain run with input:\n",
"\u001b[0m{\n",
" \"query\": \"What was Alphabet's revenue?\"\n",
"}\n",
"\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA > 5:chain:StuffDocumentsChain] Entering Chain run with input:\n",
"\u001b[0m[inputs]\n",
"\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA > 5:chain:StuffDocumentsChain > 6:chain:LLMChain] Entering Chain run with input:\n",
"\u001b[0m{\n",
" \"question\": \"What was Alphabet's revenue?\",\n",
" \"context\": \"Alphabet Inc.\\nCONSOLIDATED STATEMENTS OF INCOME\\n(In millions, except per share amounts, unaudited)\\nQuarter Ended March 31,\\n2022 2023\\nRevenues $ 68,011 $ 69,787 \\nCosts and expenses:\\nCost of revenues 29,599 30,612 \\nResearch and development 9,119 11,468 \\nSales and marketing 5,825 6,533 \\nGeneral and administrative 3,374 3,759 \\nTotal costs and expenses 47,917 52,372 \\nIncome from operations 20,094 17,415 \\nOther income (expense), net (1,160) 790 \\nIncome before income taxes 18,934 18,205 \\nProvision for income taxes 2,498 3,154 \\nNet income $ 16,436 $ 15,051 \\nBasic earnings per share of Class A, Class B, and Class C stock $ 1.24 $ 1.18 \\nDiluted earnings per share of Class A, Class B, and Class C stock $ 1.23 $ 1.17 \\nNumber of shares used in basic earnings per share calculation 13,203 12,781 \\nNumber of shares used in diluted earnings per share calculation 13,351 12,823 \\n6\\n\\nAlphabet Announces First Quarter 2023 Results\\nMOUNTAIN VIEW, Calif. April 25, 2023 Alphabet Inc. (NASDAQ: GOOG, GOOGL) today announced financial \\nresults for the quarter ended March 31, 2023 .\\nSundar Pichai, CEO of Alphabet and Google, said: “We are pleased with our business performance in the first \\nquarter, with Search performing well and momentum in Cloud. We introduced important product updates anchored \\nin deep computer science and AI. Our North Star is providing the most helpful answers for our users, and we see \\nhuge opportunities ahead, continuing our long track record of innovation.”\\nRuth Porat, CFO of Alphabet and Google, said: “Resilience in Search and momentum in Cloud resulted in Q1 \\nconsolidated revenues of $69.8 billion, up 3% year over year, or up 6% in constant currency. We remain committed \\nto delivering long-term growth and creating capacity to invest in our most compelling growth areas by re-engineering \\nour cost base.”\\nQ1 2023 financial highlights (unaudited)\\nOur first quarter 2023 results reflect:\\ni.$2.6 billion in charges related to reductions in our workforce and office space; \\nii.a $988 million reduction in depreciation expense from the change in estimated useful life of our servers and \\ncertain network equipment; and\\niii.a shift in the timing of our annual employee stock-based compensation awards resulting in relatively less \\nstock-based compensation expense recognized in the first quarter compared to the remaining quarters of \\nthe ye ar. The shift in timing itself will not affect the amount of stock-based compensation expense over the \\nfull fiscal year 2023.\\nFor further information, please refer to our blog post also filed with the SEC via Form 8-K on April 20, 2023.\\nThe following table summarizes our consolidated financial results for the quarters ended March 31, 2022 and 2023 \\n(in millions, except for per share information and percentages). \\nQuarter Ended March 31,\\n2022 2023\\nRevenues $ 68,011 $ 69,787 \\nChange in revenues year over year 23 % 3 %\\nChange in constant currency revenues year over year(1) 26 % 6 %\\nOperating income $ 20,094 $ 17,415 \\nOperating margin 30 % 25 %\\nOther income (expense), net $ (1,160) $ 790 \\nNet income $ 16,436 $ 15,051 \\nDiluted EPS $ 1.23 $ 1.17 \\n(1) Non-GAAP measure. See the table captioned “Reconciliation from GAAP revenues to non-GAAP constant currency \\nrevenues and GAAP percentage change in revenues to non-GAAP percentage change in constant currency revenues” for \\nmore details.\\n\\nQ1 2023 supplemental information (in millions, except for number of employees; unaudited)\\nRevenues, T raffic Acquisition Costs (TAC), and number of employees\\nQuarter Ended March 31,\\n2022 2023\\nGoogle Search & other $ 39,618 $ 40,359 \\nYouTube ads 6,869 6,693 \\nGoogle Network 8,174 7,496 \\nGoogle advertising 54,661 54,548 \\nGoogle other 6,811 7,413 \\nGoogle Services total 61,472 61,961 \\nGoogle Cloud 5,821 7,454 \\nOther Bets 440 288 \\nHedging gains (losses) 278 84 \\nTotal revenues $ 68,011 $ 69,787 \
"}\n",
"\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA > 5:chain:StuffDocumentsChain > 6:chain:LLMChain > 7:llm:ChatOpenAI] Entering LLM run with input:\n",
"\u001b[0m{\n",
" \"prompts\": [\n",
" \"System: Use the following pieces of context to answer the users question. \\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\\n----------------\\nAlphabet Inc.\\nCONSOLIDATED STATEMENTS OF INCOME\\n(In millions, except per share amounts, unaudited)\\nQuarter Ended March 31,\\n2022 2023\\nRevenues $ 68,011 $ 69,787 \\nCosts and expenses:\\nCost of revenues 29,599 30,612 \\nResearch and development 9,119 11,468 \\nSales and marketing 5,825 6,533 \\nGeneral and administrative 3,374 3,759 \\nTotal costs and expenses 47,917 52,372 \\nIncome from operations 20,094 17,415 \\nOther income (expense), net (1,160) 790 \\nIncome before income taxes 18,934 18,205 \\nProvision for income taxes 2,498 3,154 \\nNet income $ 16,436 $ 15,051 \\nBasic earnings per share of Class A, Class B, and Class C stock $ 1.24 $ 1.18 \\nDiluted earnings per share of Class A, Class B, and Class C stock $ 1.23 $ 1.17 \\nNumber of shares used in basic earnings per share calculation 13,203 12,781 \\nNumber of shares used in diluted earnings per share calculation 13,351 12,823 \\n6\\n\\nAlphabet Announces First Quarter 2023 Results\\nMOUNTAIN VIEW, Calif. April 25, 2023 Alphabet Inc. (NASDAQ: GOOG, GOOGL) today announced financial \\nresults for the quarter ended March 31, 2023 .\\nSundar Pichai, CEO of Alphabet and Google, said: “We are pleased with our business performance in the first \\nquarter, with Search performing well and momentum in Cloud. We introduced important product updates anchored \\nin deep computer science and AI. Our North Star is providing the most helpful answers for our users, and we see \\nhuge opportunities ahead, continuing our long track record of innovation.”\\nRuth Porat, CFO of Alphabet and Google, said: “Resilience in Search and momentum in Cloud resulted in Q1 \\nconsolidated revenues of $69.8 billion, up 3% year over year, or up 6% in constant currency. We remain committed \\nto delivering long-term growth and creating capacity to invest in our most compelling growth areas by re-engineering \\nour cost base.”\\nQ1 2023 financial highlights (unaudited)\\nOur first quarter 2023 results reflect:\\ni.$2.6 billion in charges related to reductions in our workforce and office space; \\nii.a $988 million reduction in depreciation expense from the change in estimated useful life of our servers and \\ncertain network equipment; and\\niii.a shift in the timing of our annual employee stock-based compensation awards resulting in relatively less \\nstock-based compensation expense recognized in the first quarter compared to the remaining quarters of \\nthe ye ar. The shift in timing itself will not affect the amount of stock-based compensation expense over the \\nfull fiscal year 2023.\\nFor further information, please refer to our blog post also filed with the SEC via Form 8-K on April 20, 2023.\\nThe following table summarizes our consolidated financial results for the quarters ended March 31, 2022 and 2023 \\n(in millions, except for per share information and percentages). \\nQuarter Ended March 31,\\n2022 2023\\nRevenues $ 68,011 $ 69,787 \\nChange in revenues year over year 23 % 3 %\\nChange in constant currency revenues year over year(1) 26 % 6 %\\nOperating income $ 20,094 $ 17,415 \\nOperating margin 30 % 25 %\\nOther income (expense), net $ (1,160) $ 790 \\nNet income $ 16,436 $ 15,051 \\nDiluted EPS $ 1.23 $ 1.17 \\n(1) Non-GAAP measure. See the table captioned “Reconciliation from GAAP revenues to non-GAAP constant currency \\nrevenues and GAAP percentage change in revenues to non-GAAP percentage change in constant currency revenues” for \\nmore details.\\n\\nQ1 2023 supplemental information (in millions, except for number of employees; unaudited)\\nRevenues, T raffic Acquisition Costs (TAC), and number of employees\\nQuarter Ended March 31,\\n2022 2023\\nGoogle Search & other $ 39,618 $ 40,359 \\nYouTube ads 6,869 6,693 \\nGoogle Network 8,174 7,496 \\nGoogle advertising 54,661 54,548 \\nGoogle other 6
" ]\n",
"}\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA > 5:chain:StuffDocumentsChain > 6:chain:LLMChain > 7:llm:ChatOpenAI] [1.61s] Exiting LLM run with output:\n",
"\u001b[0m{\n",
" \"generations\": [\n",
" [\n",
" {\n",
" \"text\": \"Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million.\",\n",
" \"generation_info\": null,\n",
" \"message\": {\n",
" \"content\": \"Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million.\",\n",
" \"additional_kwargs\": {},\n",
" \"example\": false\n",
" }\n",
" }\n",
" ]\n",
" ],\n",
" \"llm_output\": {\n",
" \"token_usage\": {\n",
" \"prompt_tokens\": 2335,\n",
" \"completion_tokens\": 23,\n",
" \"total_tokens\": 2358\n",
" },\n",
" \"model_name\": \"gpt-3.5-turbo-0613\"\n",
" },\n",
" \"run\": null\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA > 5:chain:StuffDocumentsChain > 6:chain:LLMChain] [1.61s] Exiting Chain run with output:\n",
"\u001b[0m{\n",
" \"text\": \"Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million.\"\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA > 5:chain:StuffDocumentsChain] [1.61s] Exiting Chain run with output:\n",
"\u001b[0m{\n",
" \"output_text\": \"Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million.\"\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings > 4:chain:RetrievalQA] [1.85s] Exiting Chain run with output:\n",
"\u001b[0m{\n",
" \"result\": \"Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million.\"\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[tool/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:alphabet-earnings] [1.86s] Exiting Tool run with output:\n",
"\u001b[0m\"{'query': \"What was Alphabet's revenue?\", 'result': \"Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million.\"}\"\n",
"\u001b[32;1m\u001b[1;3m[tool/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings] Entering Tool run with input:\n",
"\u001b[0m\"{'question': \"What was Tesla's revenue?\"}\"\n",
"\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA] Entering Chain run with input:\n",
"\u001b[0m{\n",
" \"query\": \"What was Tesla's revenue?\"\n",
"}\n",
"\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA > 10:chain:StuffDocumentsChain] Entering Chain run with input:\n",
"\u001b[0m[inputs]\n",
"\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA > 10:chain:StuffDocumentsChain > 11:chain:LLMChain] Entering Chain run with input:\n",
"\u001b[0m{\n",
" \"question\": \"What was Tesla's revenue?\",\n",
" \"context\": \"S U M M A R Y H I G H L I G H T S \\n(1) Excludes SBC (stock -based compensation).\\n(2) Free cash flow = operating cash flow less capex.\\n(3) Includes cash, cash equivalents and investments.Profitability 11.4% operating margin in Q1\\n$2.7B GAAP operating income in Q1\\n$2.5B GAAP net income in Q1\\n$2.9B non -GAAP net income1in Q1In the current macroeconomic environment, we see this year as a unique \\nopportunity for Tesla. As many carmakers are working through challenges with the \\nunit economics of their EV programs, we aim to leverage our position as a cost \\nleader. We are focused on rapidly growing production, investments in autonomy \\nand vehicle software, and remaining on track with our growth investments.\\nOur near -term pricing strategy considers a long -term view on per vehicle \\nprofitability given the potential lifetime value of a Tesla vehicle through autonomy, \\nsupercharging, connectivity and service. We expect that our product pricing will \\ncontinue to evolve, upwards or downwards, depending on a number of factors.\\nAlthough we implemented price reductions on many vehicle models across regions \\nin the first quarter, our operating margins reduced at a manageable rate. We \\nexpect ongoing cost reduction of our vehicles, including improved production \\nefficiency at our newest factories and lower logistics costs, and remain focused on \\noperating leverage as we scale.\\nWe are rapidly growing energy storage production capacity at our Megafactory in \\nLathrop and we recently announced a new Megafactory in Shanghai. We are also \\ncontinuing to execute on our product roadmap, including Cybertruck, our next \\ngeneration vehicle platform, autonomy and other AI enabled products. \\nOur balance sheet and net income enable us to continue to make these capital \\nexpenditures in line with our future growth. In this environment, we believe it \\nmakes sense to push forward to ensure we lay a proper foundation for the best \\npossible future.Cash Operating cash flow of $2.5B\\nFree cash flow2of $0.4B in Q1\\n$0.2B increase in our cash and investments3in Q1 to $22.4B\\nOperations Cybertruck factory tooling on track; producing Alpha versions\\nModel Y was the best -selling vehicle in Europe in Q1\\nModel Y was the best -selling vehicle in the US in Q1 (ex -pickups)\\n\\n01234O T H E R H I G H L I G H T S\\n9Services & Other gross margin\\nEnergy Storage deployments (GWh)Energy Storage\\nEnergy storage deployments increased by 360% YoY in Q1 to 3.9 GWh, the highest \\nlevel of deployments we have achieved due to ongoing Megafactory ramp. The ramp of our 40 GWh Megapack factory in Lathrop, California has been successful with still more room to reach full capacity. This Megapack factory will be the first of many. We recently announced our second 40 GWh Megafactory, this time in Shanghai, with construction starting later this year. \\nSolar\\nSolar deployments increased by 40% YoY in Q1 to 67 MW, but declined sequentially in \\nthe quarter, predominantly due to volatile weather and other factors. In addition, the solar industry has been impacted by supply chain challenges.\\nServices and Other\\nBoth revenue and gross profit from Services and Other reached an all -time high in Q1 \\n2023. Within this business division, growth of used vehicle sales remained strong YoY and had healthy margins. Supercharging, while still a relatively small part of the business, continued to grow as we gradually open up the network to non- Tesla \\nvehicles. \\n-4%-2%0%2%4%6%8%\\nQ3'21 Q4'21 Q1'22 Q2'22 Q3'22 Q4'22 Q1'23\\n\\nIn millions of USD or shares as applicable, except per share data Q1-2022 Q2-2022 Q3-2022 Q4-2022 Q1-2023\\nREVENUES\\nAutomotive sales 15,514 13,670 17,785 20,241 18,878 \\nAutomotive regulatory credits 679 344 286 467 521 \\nAutomotive leasing 668 588 621 599 564 \\nTotal automotive revenues 16,861 14,602 18,692 21,307 19,963 \\nEnergy generation and storage 616 866 1,117 1,310 1,529 \\nServices and other 1,279 1,466 1,645 1,701 1,837 \\nTotal revenues 18,756 16,934 21,454
"}\n",
"\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA > 10:chain:StuffDocumentsChain > 11:chain:LLMChain > 12:llm:ChatOpenAI] Entering LLM run with input:\n",
"\u001b[0m{\n",
" \"prompts\": [\n",
" \"System: Use the following pieces of context to answer the users question. \\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\\n----------------\\nS U M M A R Y H I G H L I G H T S \\n(1) Excludes SBC (stock -based compensation).\\n(2) Free cash flow = operating cash flow less capex.\\n(3) Includes cash, cash equivalents and investments.Profitability 11.4% operating margin in Q1\\n$2.7B GAAP operating income in Q1\\n$2.5B GAAP net income in Q1\\n$2.9B non -GAAP net income1in Q1In the current macroeconomic environment, we see this year as a unique \\nopportunity for Tesla. As many carmakers are working through challenges with the \\nunit economics of their EV programs, we aim to leverage our position as a cost \\nleader. We are focused on rapidly growing production, investments in autonomy \\nand vehicle software, and remaining on track with our growth investments.\\nOur near -term pricing strategy considers a long -term view on per vehicle \\nprofitability given the potential lifetime value of a Tesla vehicle through autonomy, \\nsupercharging, connectivity and service. We expect that our product pricing will \\ncontinue to evolve, upwards or downwards, depending on a number of factors.\\nAlthough we implemented price reductions on many vehicle models across regions \\nin the first quarter, our operating margins reduced at a manageable rate. We \\nexpect ongoing cost reduction of our vehicles, including improved production \\nefficiency at our newest factories and lower logistics costs, and remain focused on \\noperating leverage as we scale.\\nWe are rapidly growing energy storage production capacity at our Megafactory in \\nLathrop and we recently announced a new Megafactory in Shanghai. We are also \\ncontinuing to execute on our product roadmap, including Cybertruck, our next \\ngeneration vehicle platform, autonomy and other AI enabled products. \\nOur balance sheet and net income enable us to continue to make these capital \\nexpenditures in line with our future growth. In this environment, we believe it \\nmakes sense to push forward to ensure we lay a proper foundation for the best \\npossible future.Cash Operating cash flow of $2.5B\\nFree cash flow2of $0.4B in Q1\\n$0.2B increase in our cash and investments3in Q1 to $22.4B\\nOperations Cybertruck factory tooling on track; producing Alpha versions\\nModel Y was the best -selling vehicle in Europe in Q1\\nModel Y was the best -selling vehicle in the US in Q1 (ex -pickups)\\n\\n01234O T H E R H I G H L I G H T S\\n9Services & Other gross margin\\nEnergy Storage deployments (GWh)Energy Storage\\nEnergy storage deployments increased by 360% YoY in Q1 to 3.9 GWh, the highest \\nlevel of deployments we have achieved due to ongoing Megafactory ramp. The ramp of our 40 GWh Megapack factory in Lathrop, California has been successful with still more room to reach full capacity. This Megapack factory will be the first of many. We recently announced our second 40 GWh Megafactory, this time in Shanghai, with construction starting later this year. \\nSolar\\nSolar deployments increased by 40% YoY in Q1 to 67 MW, but declined sequentially in \\nthe quarter, predominantly due to volatile weather and other factors. In addition, the solar industry has been impacted by supply chain challenges.\\nServices and Other\\nBoth revenue and gross profit from Services and Other reached an all -time high in Q1 \\n2023. Within this business division, growth of used vehicle sales remained strong YoY and had healthy margins. Supercharging, while still a relatively small part of the business, continued to grow as we gradually open up the network to non- Tesla \\nvehicles. \\n-4%-2%0%2%4%6%8%\\nQ3'21 Q4'21 Q1'22 Q2'22 Q3'22 Q4'22 Q1'23\\n\\nIn millions of USD or shares as applicable, except per share data Q1-2022 Q2-2022 Q3-2022 Q4-2022 Q1-2023\\nREVENUES\\nAutomotive sales 15,514 13,670 17,785 20,241 18,878 \\nAutomotive regulatory credits 679 344 286 467 521 \\nAutomotive leasing 668 588 621 599 564 \\nTotal automotive revenues 16,86
" ]\n",
"}\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA > 10:chain:StuffDocumentsChain > 11:chain:LLMChain > 12:llm:ChatOpenAI] [1.17s] Exiting LLM run with output:\n",
"\u001b[0m{\n",
" \"generations\": [\n",
" [\n",
" {\n",
" \"text\": \"Tesla's revenue for Q1-2023 was $23.329 billion.\",\n",
" \"generation_info\": null,\n",
" \"message\": {\n",
" \"content\": \"Tesla's revenue for Q1-2023 was $23.329 billion.\",\n",
" \"additional_kwargs\": {},\n",
" \"example\": false\n",
" }\n",
" }\n",
" ]\n",
" ],\n",
" \"llm_output\": {\n",
" \"token_usage\": {\n",
" \"prompt_tokens\": 2246,\n",
" \"completion_tokens\": 16,\n",
" \"total_tokens\": 2262\n",
" },\n",
" \"model_name\": \"gpt-3.5-turbo-0613\"\n",
" },\n",
" \"run\": null\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA > 10:chain:StuffDocumentsChain > 11:chain:LLMChain] [1.17s] Exiting Chain run with output:\n",
"\u001b[0m{\n",
" \"text\": \"Tesla's revenue for Q1-2023 was $23.329 billion.\"\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA > 10:chain:StuffDocumentsChain] [1.17s] Exiting Chain run with output:\n",
"\u001b[0m{\n",
" \"output_text\": \"Tesla's revenue for Q1-2023 was $23.329 billion.\"\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings > 9:chain:RetrievalQA] [1.61s] Exiting Chain run with output:\n",
"\u001b[0m{\n",
" \"result\": \"Tesla's revenue for Q1-2023 was $23.329 billion.\"\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[tool/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 8:tool:tesla-earnings] [1.61s] Exiting Tool run with output:\n",
"\u001b[0m\"{'query': \"What was Tesla's revenue?\", 'result': \"Tesla's revenue for Q1-2023 was $23.329 billion.\"}\"\n",
"\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 13:llm:ChatOpenAI] Entering LLM run with input:\n",
"\u001b[0m{\n",
" \"prompts\": [\n",
" \"System: You are a helpful AI assistant.\\nHuman: did alphabet or tesla have more revenue?\\nAI: {'name': 'tool_selection', 'arguments': '{\\\\n \\\"actions\\\": [\\\\n {\\\\n \\\"action_name\\\": \\\"alphabet-earnings\\\",\\\\n \\\"action\\\": {\\\\n \\\"question\\\": \\\"What was Alphabet\\\\'s revenue?\\\"\\\\n }\\\\n },\\\\n {\\\\n \\\"action_name\\\": \\\"tesla-earnings\\\",\\\\n \\\"action\\\": {\\\\n \\\"question\\\": \\\"What was Tesla\\\\'s revenue?\\\"\\\\n }\\\\n }\\\\n ]\\\\n}'}\\nFunction: {\\\"query\\\": \\\"What was Alphabet's revenue?\\\", \\\"result\\\": \\\"Alphabet's revenue for the quarter ended March 31, 2023, was $69,787 million.\\\"}\\nAI: {'name': 'tool_selection', 'arguments': '{\\\\n \\\"actions\\\": [\\\\n {\\\\n \\\"action_name\\\": \\\"alphabet-earnings\\\",\\\\n \\\"action\\\": {\\\\n \\\"question\\\": \\\"What was Alphabet\\\\'s revenue?\\\"\\\\n }\\\\n },\\\\n {\\\\n \\\"action_name\\\": \\\"tesla-earnings\\\",\\\\n \\\"action\\\": {\\\\n \\\"question\\\": \\\"What was Tesla\\\\'s revenue?\\\"\\\\n }\\\\n }\\\\n ]\\\\n}'}\\nFunction: {\\\"query\\\": \\\"What was Tesla's revenue?\\\", \\\"result\\\": \\\"Tesla's revenue for Q1-2023 was $23.329 billion.\\\"}\"\n",
" ]\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 13:llm:ChatOpenAI] [1.69s] Exiting LLM run with output:\n",
"\u001b[0m{\n",
" \"generations\": [\n",
" [\n",
" {\n",
" \"text\": \"Alphabet had a revenue of $69,787 million, while Tesla had a revenue of $23.329 billion. Therefore, Alphabet had more revenue than Tesla.\",\n",
" \"generation_info\": null,\n",
" \"message\": {\n",
" \"content\": \"Alphabet had a revenue of $69,787 million, while Tesla had a revenue of $23.329 billion. Therefore, Alphabet had more revenue than Tesla.\",\n",
" \"additional_kwargs\": {},\n",
" \"example\": false\n",
" }\n",
" }\n",
" ]\n",
" ],\n",
" \"llm_output\": {\n",
" \"token_usage\": {\n",
" \"prompt_tokens\": 353,\n",
" \"completion_tokens\": 34,\n",
" \"total_tokens\": 387\n",
" },\n",
" \"model_name\": \"gpt-3.5-turbo-0613\"\n",
" },\n",
" \"run\": null\n",
"}\n",
"\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor] [7.83s] Exiting Chain run with output:\n",
"\u001b[0m{\n",
" \"output\": \"Alphabet had a revenue of $69,787 million, while Tesla had a revenue of $23.329 billion. Therefore, Alphabet had more revenue than Tesla.\"\n",
"}\n"
]
},
{
"data": {
"text/plain": [
"{'input': 'did alphabet or tesla have more revenue?',\n",
" 'output': 'Alphabet had a revenue of $69,787 million, while Tesla had a revenue of $23.329 billion. Therefore, Alphabet had more revenue than Tesla.'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"llm = ChatOpenAI(\n",
" temperature=0,\n",
Fix `make docs_build` and related scripts (#7276) **Description: a description of the change** Fixed `make docs_build` and related scripts which caused errors. There are several changes. First, I made the build of the documentation and the API Reference into two separate commands. This is because it takes less time to build. The commands for documents are `make docs_build`, `make docs_clean`, and `make docs_linkcheck`. The commands for API Reference are `make api_docs_build`, `api_docs_clean`, and `api_docs_linkcheck`. It looked like `docs/.local_build.sh` could be used to build the documentation, so I used that. Since `.local_build.sh` was also building API Rerefence internally, I removed that process. `.local_build.sh` also added some Bash options to stop in error or so. Futher more added `cd "${SCRIPT_DIR}"` at the beginning so that the script will work no matter which directory it is executed in. `docs/api_reference/api_reference.rst` is removed, because which is generated by `docs/api_reference/create_api_rst.py`, and added it to .gitignore. Finally, the description of CONTRIBUTING.md was modified. **Issue: the issue # it fixes (if applicable)** https://github.com/hwchase17/langchain/issues/6413 **Dependencies: any dependencies required for this change** `nbdoc` was missing in group docs so it was added. I installed it with the `poetry add --group docs nbdoc` command. I am concerned if any modifications are needed to poetry.lock. I would greatly appreciate it if you could pay close attention to this file during the review. **Tag maintainer** - General / Misc / if you don't know who to tag: @baskaryan If this PR needs any additional changes, I'll be happy to make them! --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
2023-07-12 02:05:14 +00:00
" model=\"gpt-3.5-turbo-0613\",\n",
2023-06-21 14:19:52 +00:00
")\n",
"\n",
"agent = initialize_agent(\n",
" agent=AgentType.OPENAI_MULTI_FUNCTIONS,\n",
" tools=tools,\n",
" llm=llm,\n",
" verbose=True,\n",
")\n",
"\n",
"agent({\"input\": \"did alphabet or tesla have more revenue?\"})"
]
}
],
"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
}