From bf55758040c837ace4d11c9445f9643a34ed42b7 Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 2 Oct 2023 10:11:06 -0600 Subject: [PATCH] remove mentions of old LlamaToolKit (#7935) --- .../integrations/using_with_langchain.md | 27 - docs/examples/usecases/10k_graph_agent.ipynb | 618 ------- .../usecases/10q_fn_agent-react-compare.ipynb | 1484 ----------------- 3 files changed, 2129 deletions(-) delete mode 100644 docs/examples/usecases/10k_graph_agent.ipynb delete mode 100644 docs/examples/usecases/10q_fn_agent-react-compare.ipynb diff --git a/docs/community/integrations/using_with_langchain.md b/docs/community/integrations/using_with_langchain.md index ddbbfe258246b..1bfd901a81241 100644 --- a/docs/community/integrations/using_with_langchain.md +++ b/docs/community/integrations/using_with_langchain.md @@ -33,33 +33,6 @@ tool = LlamaIndexTool.from_tool_config(tool_config) ``` -You can also choose to provide a `LlamaToolkit`: - -```python -toolkit = LlamaToolkit( - index_configs=index_configs, -) -``` - -Such a toolkit can be used to create a downstream Langchain-based chat agent through -our `create_llama_agent` and `create_llama_chat_agent` commands: - -```python -from llama_index.langchain_helpers.agents import create_llama_chat_agent - -agent_chain = create_llama_chat_agent( - toolkit, - llm, - memory=memory, - verbose=True -) - -agent_chain.run(input="Query about X") -``` - -You can take a look at [the full tutorial notebook here](https://github.com/jerryjliu/llama_index/blob/main/examples/chatbot/Chatbot_SEC.ipynb). - - ### Llama Demo Notebook: Tool + Memory module We provide another demo notebook showing how you can build a chat agent with the following components. diff --git a/docs/examples/usecases/10k_graph_agent.ipynb b/docs/examples/usecases/10k_graph_agent.ipynb deleted file mode 100644 index f104130d02468..0000000000000 --- a/docs/examples/usecases/10k_graph_agent.ipynb +++ /dev/null @@ -1,618 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "id": "034e355d-83a0-4bd2-877e-0f493c5f713d", - "metadata": { - "tags": [] - }, - "source": [ - "# 10K Analysis\n", - "In this demo, we answer a compare and contrast query with two different approaches:\n", - "1. structured reasoning via index graph\n", - "2. free form reasoning via ReAct agent" - ] - }, - { - "cell_type": "code", - "execution_count": 537, - "id": "298e7dfc-be9a-49bd-8793-9a1d9fa52c8d", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index import (\n", - " SimpleDirectoryReader,\n", - " LLMPredictor,\n", - " ServiceContext,\n", - " VectorStoreIndex,\n", - ")\n", - "from llama_index.response.pprint_utils import pprint_response\n", - "from llama_index.llms import OpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 419, - "id": "35364259-f1c3-4df0-b8c9-79e0afca7436", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "llm = OpenAI(temperature=0, model=\"text-davinci-003\", max_tokens=-1)\n", - "\n", - "service_context = ServiceContext.from_defaults(llm=llm)" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "9be92b8e-1d3f-4ac9-b88a-10f69e3d6645", - "metadata": { - "jp-MarkdownHeadingCollapsed": true, - "tags": [] - }, - "source": [ - "# Lyft" - ] - }, - { - "cell_type": "code", - "execution_count": 420, - "id": "d282214f-69d2-49d4-8ab3-e1b1560f0be6", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "lyft_docs = SimpleDirectoryReader(input_files=[\"../data/10k/lyft_2021.pdf\"]).load_data()" - ] - }, - { - "cell_type": "code", - "execution_count": 240, - "id": "60826815-3282-4947-aa4f-ee75dcc033c3", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "lyft_index = VectorStoreIndex.from_documents(lyft_docs)" - ] - }, - { - "cell_type": "code", - "execution_count": 421, - "id": "a0d76160-00fe-4cab-aab9-1f227db6feca", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "lyft_engine = lyft_index.as_query_engine(similarity_top_k=3)" - ] - }, - { - "cell_type": "code", - "execution_count": 451, - "id": "c57dad40-add8-469a-aaeb-fe19900206fe", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "response = lyft_engine.query(\n", - " \"what is the revenue growth in the last year, show me the reference page number\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 452, - "id": "fe3ee56e-4209-4e43-9f92-dc0352b1afe5", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Final Response: The revenue growth in the last year is 36%, as\n", - "referenced on page 63.\n", - "______________________________________________________________________\n", - "Source Node 1/3\n", - "Document ID: 6a1711e2-51be-46c1-8152-72361c192ed9\n", - "Similarity: 0.8045102189652867\n", - "Text: page_label: 63 Results of OperationsThe following table summar\n", - "izes our historical consolidated statements of operations data:Year\n", - "Ended December 31, 2021 2020 2019 (in thousands) Revenue $ 3,208,323 $\n", - "2,364,681 $ 3,615,960 Costs and expenses Cost of revenue 1,649,532\n", - "1,447,516 2,176,469 Operations and support 402,233 453,963 636,116\n", - "Research a...\n", - "______________________________________________________________________\n", - "Source Node 2/3\n", - "Document ID: c15baf48-6db4-4892-88ba-8be2a6f195a5\n", - "Similarity: 0.8030623987053549\n", - "Text: page_label: 19 changing industries. If our assumptions\n", - "regarding these risks and uncertainties, which we use to plan and\n", - "operate ourbusiness, are incorrect or change, or if we do not address\n", - "these risks successfully, our results of operations could differ\n", - "materially from our expectations and our business,financial condition\n", - "and results of ope...\n", - "______________________________________________________________________\n", - "Source Node 3/3\n", - "Document ID: 21db4c23-fb06-48bb-91c7-2f52d158a123\n", - "Similarity: 0.8023439081890719\n", - "Text: page_label: 64 second quarter of 2021. These increases were\n", - "offset by investments in driver supply by increasing driver incentives\n", - "recorded as a reduction to revenue by $942.9 million in2021 as\n", - "compared to the prior y ear as rider demand outpaced driver supply\n", - "during certain periods of the pandemic recovery in 2021. Revenue in\n", - "2020 was also hig...\n" - ] - } - ], - "source": [ - "pprint_response(response, show_source=True)" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "e7113434-0e41-46b6-a74e-284ce211fd38", - "metadata": { - "jp-MarkdownHeadingCollapsed": true, - "tags": [] - }, - "source": [ - "# Uber" - ] - }, - { - "cell_type": "code", - "execution_count": 424, - "id": "e35842e1-b058-4e1a-8f51-4c84b42ff412", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "uber_docs = SimpleDirectoryReader(input_files=[\"../data/10k/uber_2021.pdf\"]).load_data()" - ] - }, - { - "cell_type": "code", - "execution_count": 425, - "id": "4e6c3178-6aab-4fdc-99f6-c820661e7a73", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "uber_index = VectorStoreIndex.from_documents(uber_docs)" - ] - }, - { - "cell_type": "code", - "execution_count": 429, - "id": "7b8e9d46-7d66-4a22-a9d8-4e2ce21491ce", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "uber_engine = uber_index.as_query_engine(similarity_top_k=3)" - ] - }, - { - "cell_type": "code", - "execution_count": 430, - "id": "444ff6cf-2eb6-4f5c-905a-5928d0dc8947", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "response = uber_engine.query(\n", - " \"what is the revenue growth in the last year, show me the reference page number\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 431, - "id": "71de4581-5c03-4a08-8d00-ddee08530a0f", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Final Response: The revenue growth in the last year was 57%, as\n", - "referenced on page 57.\n", - "______________________________________________________________________\n", - "Source Node 1/3\n", - "Document ID: 0c8abeea-57cd-41bf-a94c-1c5d195bb3ae\n", - "Similarity: 0.8059365413378133\n", - "Text: page_label: 57 The following table sets forth the components of\n", - "our consolidated statements of operations for each of the periods\n", - "presented as a percentage of revenue : Year Ended December 31, 2020\n", - "2021 Revenue 100 %100 %Costs and expenses Cost of revenue, exclusive\n", - "of dep reciation and amortization shown separately below46 %54\n", - "%Operations and ...\n", - "______________________________________________________________________\n", - "Source Node 2/3\n", - "Document ID: 012bb7d8-36ca-42ee-8d9e-9d4754ce599f\n", - "Similarity: 0.7980283554264312\n", - "Text: page_label: 60 Provision for (Benefit from) Income TaxesYear\n", - "Ended December 31, 2020 to 2021 % Change (In millions, except\n", - "percentages) 2020 2021 Provision for (benefit fro m) income taxes$\n", - "(192) $ (492) (156) % Effective tax rate 2.8 %48.0 % 2021 Compared to\n", - "2020 Provision for (benefit from) income taxes increased by $300\n", - "million primarily du...\n", - "______________________________________________________________________\n", - "Source Node 3/3\n", - "Document ID: 697ccb91-0b6e-4dfe-b78a-b3115a3bfbe0\n", - "Similarity: 0.792540481338011\n", - "Text: page_label: 62 All OtherFor the year ended December 31,\n", - "2021 compared to the same period in 2020, All Other revenue\n", - "decreased $127 million, or 94% and All Otheradjusted EBITDA\n", - "loss improved $450 million, or 98%. All Other revenue and All Other\n", - "adjusted EBITDA loss improved primarily due to the favorable impact\n", - "of the s...\n" - ] - } - ], - "source": [ - "pprint_response(response, show_source=True)" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "20884bcd-8120-43ed-a137-1ddb3e14d201", - "metadata": { - "tags": [] - }, - "source": [ - "# Compare and Contrast - Graph" - ] - }, - { - "cell_type": "code", - "execution_count": 149, - "id": "c67111e5-4fd3-4586-b51a-fd905486f247", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index import ComposableGraph, SummaryIndex" - ] - }, - { - "cell_type": "code", - "execution_count": 471, - "id": "13134fbb-85da-4580-871f-373f373f60df", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "graph = ComposableGraph.from_indices(\n", - " SummaryIndex,\n", - " children_indices=[lyft_index, uber_index],\n", - " index_summaries=[\n", - " \"Provides information about Lyft financials for year 2021\",\n", - " \"Provides information about Uber financials for year 2021\",\n", - " ],\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 472, - "id": "e01ddd97-3770-44de-a5c6-859d22af9842", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.query_engine.transform_query_engine import TransformQueryEngine\n", - "from llama_index.indices.query.query_transform.base import DecomposeQueryTransform\n", - "\n", - "# define decompose_transform\n", - "decompose_transform = DecomposeQueryTransform(verbose=True)\n", - "\n", - "# define custom query engines\n", - "custom_query_engines = {}\n", - "for index in [lyft_index, uber_index]:\n", - " query_engine = index.as_query_engine(service_context=service_context)\n", - " query_engine = TransformQueryEngine(\n", - " query_engine,\n", - " query_transform=decompose_transform,\n", - " transform_extra_info={\"index_summary\": index.index_struct.summary},\n", - " )\n", - " custom_query_engines[index.index_id] = query_engine\n", - "\n", - "custom_query_engines[graph.root_id] = graph.root_index.as_query_engine(\n", - " service_context=service_context,\n", - " streaming=True,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 473, - "id": "63e1f7a3-d792-4103-9351-1a11fe64f6b6", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# define graph\n", - "g_engine = graph.as_query_engine(custom_query_engines=custom_query_engines)" - ] - }, - { - "cell_type": "code", - "execution_count": 489, - "id": "071ba563-c90d-4984-b111-7fec6687d38d", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[33;1m\u001b[1;3m> Current query: Compare Uber and Lyft revenue growth in 2021.\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What is Lyft's revenue growth in 2021?\n", - "\u001b[0m\u001b[33;1m\u001b[1;3m> Current query: Compare Uber and Lyft revenue growth in 2021.\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What is Lyft's revenue growth in 2021?\n", - "\u001b[0m\u001b[33;1m\u001b[1;3m> Current query: Compare Uber and Lyft revenue growth in 2021.\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What is Uber's revenue growth in 2021?\n", - "\u001b[0m\u001b[33;1m\u001b[1;3m> Current query: Compare Uber and Lyft revenue growth in 2021.\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What is Uber's revenue growth in 2021?\n", - "\u001b[0m" - ] - } - ], - "source": [ - "response = g_engine.query(\"Compare Uber and Lyft revenue growth in 2021.\")" - ] - }, - { - "cell_type": "code", - "execution_count": 490, - "id": "593ccb02-3cab-4f22-9f59-375dc6627090", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Uber's revenue growth in 2021 is higher than Lyft's revenue growth in 2021, at 57% compared to 38.2%." - ] - } - ], - "source": [ - "response.print_response_stream()" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "1d79414d-9143-4150-a6c9-f4f59852e839", - "metadata": { - "tags": [] - }, - "source": [ - "## Compare and Contrast - Agent" - ] - }, - { - "cell_type": "code", - "execution_count": 491, - "id": "5ddff61c-8d8e-4686-b944-d879f59d4466", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "llm = OpenAI(temperature=0.0, max_tokens=-1)" - ] - }, - { - "cell_type": "code", - "execution_count": 497, - "id": "78880292-cdba-4d0c-8e1a-ca9f8f99d562", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.langchain_helpers.agents import (\n", - " IndexToolConfig,\n", - " LlamaIndexTool,\n", - " LlamaToolkit,\n", - ")\n", - "\n", - "uber_config = IndexToolConfig(\n", - " query_engine=uber_engine,\n", - " name=f\"Uber 10K 2021\",\n", - " description=f\"Provides information about Lyft financials for year 2021\",\n", - " tool_kwargs={\"return_direct\": False},\n", - ")\n", - "\n", - "lyft_config = IndexToolConfig(\n", - " query_engine=lyft_engine,\n", - " name=f\"Lyft 10K 2021\",\n", - " description=f\"Provides information about Uber financials for year 2021\",\n", - " tool_kwargs={\"return_direct\": False},\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 498, - "id": "07328a05-70d7-47f7-965d-58d4b3a5dbfa", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "toolkit = LlamaToolkit(\n", - " index_configs=[uber_config, lyft_config],\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 499, - "id": "8a37d9cb-bbb6-4b91-9c76-14a8db13c90f", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.langchain_helpers.agents import create_llama_agent\n", - "\n", - "agent_chain = create_llama_agent(toolkit, llm, memory=memory, verbose=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 500, - "id": "361ece8a-e6b8-491e-9a63-f8d3142dd743", - "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 look at the financials of both companies.\n", - "Action: Uber 10K 2021\n", - "Action Input: Revenue growth\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3min 2021 was primarily driven by what?\n", - "\n", - "Revenue growth in 2021 was primarily driven by an increase in Delivery Gross Bookings of 71%, or 66% on a constant currency basis, due to an increase in food delivery orders and higher basket sizes as a result of stay-at-home order demand related to COVID-19, as well as continued expansion across U.S. and international markets. Additionally, Mobility Gross Bookings growth of 38%, or 36% on a constant currency basis, due to increases in Trip volumes as the business recovers from the impacts of COVID-19, contributed to the revenue growth.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to compare this to Lyft's revenue growth.\n", - "Action: Lyft 10K 2021\n", - "Action Input: Revenue growth\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m\n", - "Revenue increased $843.6 million, or 36%, in 2021 as compared to the prior year, driven primarily by the significant increase in the number of Active Riders in 2021 as compared to the prior year, as vaccines became more widely distributed and more communities reopened.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer.\n", - "Final Answer: Uber's revenue growth in 2021 was primarily driven by an increase in Delivery Gross Bookings of 71%, or 66% on a constant currency basis, while Lyft's revenue increased $843.6 million, or 36%, in 2021 as compared to the prior year, driven primarily by the significant increase in the number of Active Riders in 2021 as compared to the prior year.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "\"Uber's revenue growth in 2021 was primarily driven by an increase in Delivery Gross Bookings of 71%, or 66% on a constant currency basis, while Lyft's revenue increased $843.6 million, or 36%, in 2021 as compared to the prior year, driven primarily by the significant increase in the number of Active Riders in 2021 as compared to the prior year.\"" - ] - }, - "execution_count": 500, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "agent_chain.run(input=\"Compare Uber and Lyft revenue growth in 2021.\")" - ] - }, - { - "cell_type": "code", - "execution_count": 534, - "id": "822515c6-8266-4d55-bafe-f5262103b68a", - "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 look at the financials of both Uber and Lyft\n", - "Action: Uber 10K 2021\n", - "Action Input: Customer segment and geography information\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "The information provided in the context does not include customer segment and geography information. It does, however, provide information about our reportable segments and a reconciliation of the total segment adjusted EBITDA to loss from operations, as well as information about revenue and long-lived assets, net by geographic area.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to look at the financials of Lyft\n", - "Action: Lyft 10K 2021\n", - "Action Input: Customer segment and geography information\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m\n", - "The Company's customer base is diverse, and its employees reflect that diversity. As of December 31, 2021, the ethnicity of its U.S. employees was 44% White, 30% Asian, 11% Hispanic or Latinx, 8% Black, and 5% two or more races, American Indian, Alaska Native, Native Hawaiian or other Pacific Islander. The Company generates its revenue from its multimodal transportation networks that offer access to a variety of transportation options through the Lyft Platform and mobile-based applications, primarily in the United States.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: Uber and Lyft both have diverse customer bases and generate revenue from their multimodal transportation networks in the United States. Uber does not provide customer segment and geography information, while Lyft provides information about its U.S. employees' ethnicity and the geographic area in which it generates revenue.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "\"Uber and Lyft both have diverse customer bases and generate revenue from their multimodal transportation networks in the United States. Uber does not provide customer segment and geography information, while Lyft provides information about its U.S. employees' ethnicity and the geographic area in which it generates revenue.\"" - ] - }, - "execution_count": 534, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "agent_chain.run(\n", - " input=\"Compare and contrast the customer segments and geographies that grew the fastest\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fce81d02-e07b-467a-9682-a128d508c426", - "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.16" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/examples/usecases/10q_fn_agent-react-compare.ipynb b/docs/examples/usecases/10q_fn_agent-react-compare.ipynb deleted file mode 100644 index 0db3124f7d0da..0000000000000 --- a/docs/examples/usecases/10q_fn_agent-react-compare.ipynb +++ /dev/null @@ -1,1484 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "id": "034e355d-83a0-4bd2-877e-0f493c5f713d", - "metadata": { - "tags": [] - }, - "source": [ - "# 10K Analysis\n", - "In this demo, we explore answering compare an contrast queries with two different approaches:\n", - "1. ReAct agent, using prompting over a set of Tools\n", - "2. OpenAIAgent, using the function calling API to choose Tools" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "14fdc69e-4c3a-4b4a-babf-3733a0ba2d48", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# # uncomment to turn on logging\n", - "# import logging\n", - "# import sys\n", - "\n", - "# logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n", - "# logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "1c1e705a-36f2-4272-8f98-7f3785e76e8c", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/jerryliu/Programming/gpt_index/.venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], - "source": [ - "from llama_index import (\n", - " SimpleDirectoryReader,\n", - " LLMPredictor,\n", - " ServiceContext,\n", - " GPTVectorStoreIndex,\n", - ")\n", - "from llama_index.response.pprint_utils import pprint_response\n", - "from llama_index.llms import OpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "35364259-f1c3-4df0-b8c9-79e0afca7436", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name=\"text-davinci-003\", max_tokens=-1, streaming=True))\n", - "chatgpt = OpenAI(temperature=0, model=\"gpt-3.5-turbo\")\n", - "gpt4 = OpenAI(temperature=0, model=\"gpt-4\")\n", - "service_context = ServiceContext.from_defaults(llm=chatgpt)\n", - "service_context_gpt4 = ServiceContext.from_defaults(llm=gpt4)" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "e7113434-0e41-46b6-a74e-284ce211fd38", - "metadata": { - "tags": [] - }, - "source": [ - "## Load data" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "d036819a-754e-460b-8734-8af7071287e5", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "march_2022 = SimpleDirectoryReader(\n", - " input_files=[\"../data/10q/uber_10q_march_2022.pdf\"]\n", - ").load_data()\n", - "june_2022 = SimpleDirectoryReader(\n", - " input_files=[\"../data/10q/uber_10q_june_2022.pdf\"]\n", - ").load_data()\n", - "sept_2022 = SimpleDirectoryReader(\n", - " input_files=[\"../data/10q/uber_10q_sept_2022.pdf\"]\n", - ").load_data()" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "fd541b68-c67f-4cbf-b579-5437d48e5b8f", - "metadata": {}, - "source": [ - "# Build indices" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "4e6c3178-6aab-4fdc-99f6-c820661e7a73", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "march_index = GPTVectorStoreIndex.from_documents(march_2022)\n", - "june_index = GPTVectorStoreIndex.from_documents(june_2022)\n", - "sept_index = GPTVectorStoreIndex.from_documents(sept_2022)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "3af29f86-9a18-4b8e-af38-8ddc24b550e8", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "march_engine = march_index.as_query_engine(\n", - " similarity_top_k=3, service_context=service_context\n", - ")\n", - "june_engine = june_index.as_query_engine(\n", - " similarity_top_k=3, service_context=service_context\n", - ")\n", - "sept_engine = sept_index.as_query_engine(\n", - " similarity_top_k=3, service_context=service_context\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "67cefd59-3d35-4de5-8192-9ed3127550c8", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# define agent LLM\n", - "from langchain.chat_models import ChatOpenAI\n", - "\n", - "llm = ChatOpenAI(temperature=0, model_name=\"gpt-3.5-turbo\")\n", - "llm_gpt4 = ChatOpenAI(temperature=0, model_name=\"gpt-4\")" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "1d79414d-9143-4150-a6c9-f4f59852e839", - "metadata": { - "jp-MarkdownHeadingCollapsed": true, - "tags": [] - }, - "source": [ - "## Compare and Contrast - ReAct Agent (LangChain)" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "78880292-cdba-4d0c-8e1a-ca9f8f99d562", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.langchain_helpers.agents import (\n", - " IndexToolConfig,\n", - " LlamaIndexTool,\n", - " LlamaToolkit,\n", - ")\n", - "\n", - "uber_config_sept = IndexToolConfig(\n", - " query_engine=sept_engine,\n", - " name=f\"Uber 10Q September 2022\",\n", - " description=f\"Provides information about Uber quarterly financials ending September 2022\",\n", - " tool_kwargs={\"return_direct\": False},\n", - ")\n", - "uber_config_june = IndexToolConfig(\n", - " query_engine=june_engine,\n", - " name=f\"Uber 10Q June 2022\",\n", - " description=f\"Provides information about Uber quarterly financials ending June 2022\",\n", - " tool_kwargs={\"return_direct\": False},\n", - ")\n", - "uber_config_march = IndexToolConfig(\n", - " query_engine=march_engine,\n", - " name=f\"Uber 10Q March 2022\",\n", - " description=f\"Provides information about Uber quarterly financials ending March 2022\",\n", - " tool_kwargs={\"return_direct\": False},\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "07328a05-70d7-47f7-965d-58d4b3a5dbfa", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "toolkit = LlamaToolkit(\n", - " index_configs=[uber_config_sept, uber_config_june, uber_config_march],\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "id": "8a37d9cb-bbb6-4b91-9c76-14a8db13c90f", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.langchain_helpers.agents import create_llama_agent\n", - "\n", - "# initialize both gpt-3 and gpt-4 agent chains\n", - "agent_chain = create_llama_agent(\n", - " toolkit,\n", - " llm,\n", - " # memory=memory,\n", - " verbose=True,\n", - ")\n", - "\n", - "agent_chain_gpt4 = create_llama_agent(toolkit, llm_gpt4, verbose=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "361ece8a-e6b8-491e-9a63-f8d3142dd743", - "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 compare the revenue from different quarters\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Revenue\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3mincreased in the nine months ended September 30, 2022 compared to the same period in 2021 primarily due to what?\n", - "\n", - "The increase in revenue in the nine months ended September 30, 2022 compared to the same period in 2021 was primarily due to an increase in Gross Bookings of 31%, or 36% on a constant currency basis. The increase in Gross Bookings was primarily driven by increases in Mobility Trip volumes as the business recovers from the impacts of COVID-19 and a $4.4 billion increase in Freight Gross Bookings resulting primarily from the acquisition of Transplace in the fourth quarter of 2021. Additionally, during the first nine months of 2022, we saw a $2.2 billion net increase in Mobility revenue as a result of business model changes in the UK and an accrual made for the resolution of historical claims in the UK relating to the classification of drivers. We also saw a $751 million increase in Delivery revenue resulting from an increase in certain Courier payments and incentives that are recorded in cost of revenue, exclusive of depreciation and amortization, for certain markets where we are primarily responsible for Delivery services and pay Couriers for services provided.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: Uber revenue increased in the nine months ended September 30, 2022 compared to the same period in 2021 primarily due to an increase in Gross Bookings of 31%, or 36% on a constant currency basis, an increase in Mobility Trip volumes, the acquisition of Transplace, business model changes in the UK, and an increase in certain Courier payments and incentives.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "'Uber revenue increased in the nine months ended September 30, 2022 compared to the same period in 2021 primarily due to an increase in Gross Bookings of 31%, or 36% on a constant currency basis, an increase in Mobility Trip volumes, the acquisition of Transplace, business model changes in the UK, and an increase in certain Courier payments and incentives.'" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# vague answer?\n", - "agent_chain.run(input=\"Analyze Uber revenue growth over the last few quarters\")" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "7c212f31-5a5d-46d2-94cc-16be2aa7a77d", - "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;3mI need to check the revenue figures for the last few quarters.\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Revenue for September 2022\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "$8,343 million\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI have the revenue for September 2022, now I need the revenue for June 2022 and March 2022.\n", - "Action: Uber 10Q June 2022\n", - "Action Input: Revenue for June 2022\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3mSix Months Ended June 30, 2022 Compared with the Same Period in 2021\n", - "Revenue increased $8.1 billion, or 118%, primarily attributable to an increase in Gross Bookings of 34%, or 37% on a constant currency basis.\n", - "\n", - "Answer: $14.927 billion\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI have the revenue for June 2022, now I need the revenue for March 2022.\n", - "Action: Uber 10Q March 2022\n", - "Action Input: Revenue for March 2022\u001b[0m\n", - "Observation: \u001b[38;5;200m\u001b[1;3m\n", - "Revenue for March 2022 was $6,854 million.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI now have the revenue figures for the last three quarters.\n", - "Final Answer: Uber's revenue growth over the last few quarters is as follows: March 2022 - $6,854 million, June 2022 - $14,927 billion, and September 2022 - $8,343 million.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "\"Uber's revenue growth over the last few quarters is as follows: March 2022 - $6,854 million, June 2022 - $14,927 billion, and September 2022 - $8,343 million.\"" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "agent_chain_gpt4.run(input=\"Analyze Uber revenue growth over the last few quarters\")" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "id": "618fcb2c-40c6-49fc-9bbe-44398b2f732f", - "metadata": {}, - "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 compare the risk factors across different quarters\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Risk Factors\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "The risk factors mentioned in the context information include: \n", - "• Drivers being classified as employees, workers or quasi-employees instead of independent contractors. \n", - "• High competition in the mobility, delivery, and logistics industries. \n", - "• Lowering of fares or service fees and offering significant Driver incentives and consumer discounts and promotions. \n", - "• Incurring significant losses since inception. \n", - "• Drivers obtaining additional or alternative opportunities for work. \n", - "• Increases in fuel, food, labor, energy, and other costs due to inflation and other factors. \n", - "• Decline in consumer spending. \n", - "• Poor economic conditions. \n", - "• Dependencies on third parties. \n", - "• Investment in climate commitments. \n", - "• Outbreaks of contagious disease, such as the COVID-19 pandemic. \n", - "• Occurrence of a catastrophic event.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to compare the risk factors across different quarters\n", - "Action: Uber 10Q June 2022\n", - "Action Input: Risk Factors\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m\n", - "Risk factors related to the context information include: \n", - "- Risks related to data collection, use, transfer, disclosure, and other processing\n", - "- Risks related to intellectual property\n", - "- Volatility of stock price\n", - "- Climate change risks, including physical and transitional risks\n", - "- Economic risks, including the impact of the COVID-19 pandemic\n", - "- Risk of catastrophic events, such as disease, weather events, war, or terrorist attack\n", - "- Health epidemics and outbreaks of contagious disease\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: The risk factors for Uber have changed over the past three quarters, with the most recent quarter including risks related to data collection, use, transfer, disclosure, and other processing, intellectual property, stock price volatility, climate change risks, economic risks, risk of catastrophic events, health epidemics, and outbreaks of contagious disease.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "'The risk factors for Uber have changed over the past three quarters, with the most recent quarter including risks related to data collection, use, transfer, disclosure, and other processing, intellectual property, stock price volatility, climate change risks, economic risks, risk of catastrophic events, health epidemics, and outbreaks of contagious disease.'" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# only picks september and june\n", - "agent_chain.run(input=\"Analyze changes in risk factors for Uber\")" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "59af2ccc-5187-4485-8d3e-8dddf47179a1", - "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;3mI should start by checking the most recent 10Q for any updates on risk factors.\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Risk factors\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "•Risk of Drivers being classified as employees, workers or quasi-employees instead of independent contractors. \n", - "•Highly competitive mobility, delivery, and logistics industries. \n", - "•Lowering of fares or service fees and offering of Driver incentives and consumer discounts and promotions. \n", - "•Significant losses since inception and potential for future losses. \n", - "•Decrease in consumer spending and potential for merchants to go out of business. \n", - "•Increases in fuel, food, labor, energy, and other costs due to inflation and other factors. \n", - "•Dependencies on third parties. \n", - "•Outbreaks of contagious disease, such as the COVID-19 pandemic. \n", - "•Catastrophic events, such as disease, a weather event, war, or terrorist attack. \n", - "•Failure to meet regulatory requirements related to climate change. \n", - "•Impact of actions to mitigate contagious disease or pandemic.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI should now compare these risk factors to the previous quarter to identify any changes.\n", - "Action: Uber 10Q June 2022\n", - "Action Input: Risk factors\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m\n", - "Risk factors include: \n", - "- Economic conditions and their impact on levels of discretionary consumer spending \n", - "- Increases in fuel, food, labor, energy, and other costs due to inflation and other factors \n", - "- Climate change related physical and transition risks \n", - "- Outbreaks of contagious disease, such as the COVID-19 pandemic \n", - "- Catastrophic events, such as disease, a weather event, war, or terrorist attack \n", - "- Collection, use, transfer, disclosure, and other processing of data \n", - "- Protection of intellectual property \n", - "- Volatility of stock price and investor or analyst expectations.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI now know the final answer\n", - "Final Answer: Comparing the risk factors from the Uber 10Q September 2022 and Uber 10Q June 2022, some changes include:\n", - "\n", - "1. The September 2022 report highlights the risk of drivers being classified as employees, workers, or quasi-employees instead of independent contractors, which was not mentioned in the June 2022 report.\n", - "2. The September 2022 report emphasizes the highly competitive nature of the mobility, delivery, and logistics industries, while the June 2022 report does not.\n", - "3. The September 2022 report mentions the lowering of fares or service fees and offering of driver incentives and consumer discounts and promotions as a risk factor, which was not present in the June 2022 report.\n", - "4. The September 2022 report highlights the significant losses since inception and potential for future losses, which was not mentioned in the June 2022 report.\n", - "5. The September 2022 report includes the risk of a decrease in consumer spending and potential for merchants to go out of business, which was not present in the June 2022 report.\n", - "6. The September 2022 report mentions dependencies on third parties as a risk factor, which was not present in the June 2022 report.\n", - "7. The September 2022 report includes the impact of actions to mitigate contagious disease or pandemic as a risk factor, which was not mentioned in the June 2022 report.\n", - "\n", - "Some risk factors that remained consistent between both reports include:\n", - "1. Increases in fuel, food, labor, energy, and other costs due to inflation and other factors.\n", - "2. Outbreaks of contagious disease, such as the COVID-19 pandemic.\n", - "3. Catastrophic events, such as disease, a weather event, war, or terrorist attack.\n", - "4. Failure to meet regulatory requirements related to climate change.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "'Comparing the risk factors from the Uber 10Q September 2022 and Uber 10Q June 2022, some changes include:\\n\\n1. The September 2022 report highlights the risk of drivers being classified as employees, workers, or quasi-employees instead of independent contractors, which was not mentioned in the June 2022 report.\\n2. The September 2022 report emphasizes the highly competitive nature of the mobility, delivery, and logistics industries, while the June 2022 report does not.\\n3. The September 2022 report mentions the lowering of fares or service fees and offering of driver incentives and consumer discounts and promotions as a risk factor, which was not present in the June 2022 report.\\n4. The September 2022 report highlights the significant losses since inception and potential for future losses, which was not mentioned in the June 2022 report.\\n5. The September 2022 report includes the risk of a decrease in consumer spending and potential for merchants to go out of business, which was not present in the June 2022 report.\\n6. The September 2022 report mentions dependencies on third parties as a risk factor, which was not present in the June 2022 report.\\n7. The September 2022 report includes the impact of actions to mitigate contagious disease or pandemic as a risk factor, which was not mentioned in the June 2022 report.\\n\\nSome risk factors that remained consistent between both reports include:\\n1. Increases in fuel, food, labor, energy, and other costs due to inflation and other factors.\\n2. Outbreaks of contagious disease, such as the COVID-19 pandemic.\\n3. Catastrophic events, such as disease, a weather event, war, or terrorist attack.\\n4. Failure to meet regulatory requirements related to climate change.'" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "agent_chain_gpt4.run(input=\"Analyze changes in risk factors for Uber\")" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "618fc1cc-c2f0-451e-9e26-d33218696cad", - "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 compare Uber's quarterly financials\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Financials\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "The financial information provided in this Quarterly Report on Form 10-Q includes the Condensed Consolidated Balance Sheets as of December 31, 2021 and September 30, 2022, the Condensed Consolidated Statements of Operations for the Three and Nine Months Ended September 30, 2021 and 2022, the Condensed Consolidated Statements of Comprehensive Income (Loss) for the Three and Nine Months Ended September 30, 2021 and 2022, the Condensed Consolidated Statements of Redeemable Non-Controlling Interests and Equity for the Three and Nine Months Ended September 30, 2021 and 2022, and the Condensed Consolidated Statements of Cash Flows for the Nine Months Ended September 30, 2021 and 2022.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to compare the financials from the other quarters\n", - "Action: Uber 10Q June 2022\n", - "Action Input: Financials\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m\n", - "The financial information provided in the context information includes net cash provided by (used in) operating activities, net cash used in investing activities, net cash used in financing activities, principal payments on finance leases, proceeds from issuance of common stock for the ESPP, and sources of funding and available line of credit.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to compare the financials from the other quarters\n", - "Action: Uber 10Q March 2022\n", - "Action Input: Financials\u001b[0m\n", - "Observation: \u001b[38;5;200m\u001b[1;3m\n", - "The condensed consolidated financial statements and accompanying notes have been prepared in accordance with GAAP. These financial statements provide information about the company's business, financial condition, operating results, prospects, strategy, and financial needs. The statements include net cash provided by (used in) operating activities, net cash used in investing activities, net cash used in financing activities, and contractual obligations. Additionally, the company provides information about its liquidity and capital resources, including its sources of funding and available line of credit.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: Uber's revenue growth and risk factors can be analyzed by comparing the financials from the quarterly reports ending September 2022, June 2022, and March 2022. This comparison will provide information about the company's net cash provided by (used in) operating activities, net cash used in investing activities, net cash used in financing activities, principal payments on finance leases, proceeds from issuance of common stock for the ESPP, and sources of funding and available line of credit.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "\"Uber's revenue growth and risk factors can be analyzed by comparing the financials from the quarterly reports ending September 2022, June 2022, and March 2022. This comparison will provide information about the company's net cash provided by (used in) operating activities, net cash used in investing activities, net cash used in financing activities, principal payments on finance leases, proceeds from issuance of common stock for the ESPP, and sources of funding and available line of credit.\"" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Prompt variation 1:\n", - "agent_chain.run(input=\"Analyze Uber revenue growth and risk factors over time\")" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "10f1a5cd-8a43-4d17-a87c-7e4c007f9e5c", - "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 compare Uber's revenue growth and risk factors over different quarters\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Revenue growth and risk factors\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "Revenue growth may be affected by a number of factors, including our ability to attract and retain new platform users, increased competition in the markets in which we operate, our ability to expand our operations in new and existing markets, our ability to maintain an adequate growth rate and effectively manage that growth, our ability to keep pace with technological changes in the industries in which we operate, changes in governmental or other regulations affecting our business, harm to our brand or reputation, and other risks described elsewhere in this Quarterly Report on Form 10-Q. Seasonal trends may also contribute to fluctuations in our operating results. In addition, our revenue growth may be affected by a softening of Driver, consumer, merchant, Shipper, or Carrier demand, whether caused by changes in the preferences of such parties, failure to maintain our brand, changes in the U.S. or global economies, licensing fees in various jurisdictions, competition, or other factors. If our growth slows more significantly than we currently expect, we may not be able to achieve profitability, which would adversely affect our financial results and future prospects.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to compare Uber's revenue growth and risk factors over different quarters\n", - "Action: Uber 10Q June 2022\n", - "Action Input: Revenue growth and risk factors\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m\n", - "Revenue growth is dependent on a number of factors, including the duration and severity of the COVID-19 pandemic, the ability to grow supply and demand on the platform, the ability to increase existing platform users' activity, the ability to introduce the platform to new markets, the ability to provide high-quality support to drivers, consumers, merchants, shippers, and carriers, the ability to expand the business and increase market share and category position, the ability to compete with the products and offerings of competitors, the ability to develop new products, offerings, and technologies, the ability to penetrate suburban and rural areas, the ability to reduce the costs of the Mobility offering, the ability to maintain existing local regulations in key markets, the ability to enter or expand operations in certain countries, and the ability to increase positive perception of the brand.\n", - "\n", - "Risk factors include the inability to increase revenue at a faster rate than the increase in expenses, the inability to attract or maintain a critical mass of drivers, consumers, merchants, shippers, and carriers, the inability to maintain or increase network scale and liquidity in a given geographic market, the inability to reduce driver incentives without adversely affecting the liquidity network effect, the inability to attract shippers to the platform, the inability to attract\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: Uber's revenue growth and risk factors vary from quarter to quarter and are affected by a number of factors, including the duration and severity of the COVID-19 pandemic, the ability to grow supply and demand on the platform, the ability to increase existing platform users' activity, the ability to introduce the platform to new markets, the ability to provide high-quality support to drivers, consumers, merchants, shippers, and carriers, the ability to expand the business and increase market share and category position, the ability to compete with the products and offerings of competitors, the ability to develop new products, offerings, and technologies, the ability to penetrate suburban and rural areas, the ability to reduce the costs of the Mobility offering, the ability to maintain existing local regulations in key markets, the ability to enter or expand operations in certain countries, and the ability to increase positive perception of the brand. Risk factors include the inability to increase revenue at a faster rate than the increase in expenses, the inability to attract or maintain a critical mass of drivers, consumers, merchants, shippers, and carriers, the inability to maintain or increase network scale and liquidity in a given geographic market, the inability to reduce driver incentives without adversely affecting the liquidity network effect, the inability to attract shippers to the platform, the inability to attract and retain customers, and the inability to maintain or increase brand recognition.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "\"Uber's revenue growth and risk factors vary from quarter to quarter and are affected by a number of factors, including the duration and severity of the COVID-19 pandemic, the ability to grow supply and demand on the platform, the ability to increase existing platform users' activity, the ability to introduce the platform to new markets, the ability to provide high-quality support to drivers, consumers, merchants, shippers, and carriers, the ability to expand the business and increase market share and category position, the ability to compete with the products and offerings of competitors, the ability to develop new products, offerings, and technologies, the ability to penetrate suburban and rural areas, the ability to reduce the costs of the Mobility offering, the ability to maintain existing local regulations in key markets, the ability to enter or expand operations in certain countries, and the ability to increase positive perception of the brand. Risk factors include the inability to increase revenue at a faster rate than the increase in expenses, the inability to attract or maintain a critical mass of drivers, consumers, merchants, shippers, and carriers, the inability to maintain or increase network scale and liquidity in a given geographic market, the inability to reduce driver incentives without adversely affecting the liquidity network effect, the inability to attract shippers to the platform, the inability to attract and retain customers, and the inability to maintain or increase brand recognition.\"" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Prompt variation 2: looks at all three quarters\n", - "agent_chain.run(input=\"Analyze Uber revenue growth and risk factors over quarters\")" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "c67bb7fe-bbf5-4320-9518-b8f4440fd8eb", - "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;3mI need to gather revenue data and risk factors from each of the three available 10Q reports.\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Revenue and risk factors\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "Revenue for the company may be affected by a variety of factors, including competition, consumer spending, and economic conditions. The company may experience significant fluctuations in its operating results due to seasonal fluctuations, the current COVID-19 pandemic, and other factors beyond its control. Risk factors that could have an adverse effect on the company's business, financial condition, operating results, or prospects include Drivers being classified as employees, workers or quasi-employees instead of independent contractors, increased competition, the need to lower fares or service fees, and the need to offer significant Driver incentives and consumer discounts and promotions. Additionally, the company may be adversely affected by geopolitical shifts, increased tensions between the United States and countries in which it operates, and the effects of the global economy. The company may also be required to sell assets at a time when it would not be able to realize the long-term value of these assets, and may experience significant taxes upon the sale or transfer of these assets.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI now have the risk factors and need to gather revenue data from the other two 10Q reports.\n", - "Action: Uber 10Q June 2022\n", - "Action Input: Revenue\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3mrecognized from contracts with an original expected length of greater than one year is expected to be recognized as follows:\n", - "\n", - "Less than or equal to 12 months: $33 million\n", - "Greater than 12 months: $115 million\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI now have the revenue data from the June 2022 report and need to gather revenue data from the March 2022 report.\n", - "Action: Uber 10Q March 2022\n", - "Action Input: Revenue\u001b[0m\n", - "Observation: \u001b[38;5;200m\u001b[1;3m\n", - "Revenue is generated from fees paid by Drivers and Merchants for use of our platform, net of Driver and Merchant earnings and Driver incentives. In certain markets, revenue is also generated from fees paid by end-users for connection services obtained via the platform. Mobility revenue also includes immaterial revenue streams such as our financial partnerships products.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI now have the revenue data and risk factors from all three 10Q reports.\n", - "Final Answer: Uber's revenue growth is affected by various factors such as competition, consumer spending, and economic conditions. Risk factors include driver classification, increased competition, fare and fee reductions, and geopolitical shifts. The company's revenue in June 2022 was expected to be recognized as $33 million for contracts less than or equal to 12 months and $115 million for contracts greater than 12 months. In March 2022, revenue was generated from fees paid by drivers and merchants, as well as fees paid by end-users in certain markets.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "\"Uber's revenue growth is affected by various factors such as competition, consumer spending, and economic conditions. Risk factors include driver classification, increased competition, fare and fee reductions, and geopolitical shifts. The company's revenue in June 2022 was expected to be recognized as $33 million for contracts less than or equal to 12 months and $115 million for contracts greater than 12 months. In March 2022, revenue was generated from fees paid by drivers and merchants, as well as fees paid by end-users in certain markets.\"" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Prompt variation 1: only looks at september\n", - "agent_chain_gpt4.run(input=\"Analyze Uber revenue growth and risk factors over time\")" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "4bdb380c-5241-4d92-84dc-422fafc0e4e1", - "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 look at the changes in the macro environment over the past few quarters.\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Macro environment\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3mrisks that Uber faces include:\n", - "\n", - "• Outbreaks of contagious disease, such as the COVID-19 pandemic and the impact of actions to mitigate the such disease or pandemic\n", - "• Catastrophic events, such as disease, a weather event, war, or terrorist attack\n", - "• Laws and regulations more restrictive than those in the United States\n", - "• Competition with companies or other services that understand local markets better than Uber does\n", - "• Differing levels of social acceptance of Uber's brand, products, and offerings\n", - "• Differing levels of technological compatibility with Uber's platform\n", - "• Legal uncertainty regarding Uber's liability for the actions of platform users and third parties\n", - "• Fluctuations in currency exchange rates\n", - "• Regulations governing the control of local currencies\n", - "• Adverse tax consequences\n", - "• Political, social, and economic instability abroad\n", - "• Public health concerns or emergencies, such as the current COVID-19 pandemic\n", - "• Reduced or varied protection for intellectual property rights in some markets\n", - "• Increased financial accounting and reporting burdens\n", - "• Import and export restrictions and changes in trade regulation\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: The biggest changes in the macro environment in the past few quarters include risks such as outbreaks of contagious disease, catastrophic events, laws and regulations more restrictive than those in the United States, competition with companies or other services that understand local markets better than Uber does, differing levels of social acceptance of Uber's brand, products, and offerings, differing levels of technological compatibility with Uber's platform, legal uncertainty regarding Uber's liability for the actions of platform users and third parties, fluctuations in currency exchange rates, regulations governing the control of local currencies, adverse tax consequences, political, social, and economic instability abroad, public health concerns or emergencies, reduced or varied protection for intellectual property rights in some markets, increased financial accounting and reporting burdens, import and export restrictions, and changes in trade regulation.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "\"The biggest changes in the macro environment in the past few quarters include risks such as outbreaks of contagious disease, catastrophic events, laws and regulations more restrictive than those in the United States, competition with companies or other services that understand local markets better than Uber does, differing levels of social acceptance of Uber's brand, products, and offerings, differing levels of technological compatibility with Uber's platform, legal uncertainty regarding Uber's liability for the actions of platform users and third parties, fluctuations in currency exchange rates, regulations governing the control of local currencies, adverse tax consequences, political, social, and economic instability abroad, public health concerns or emergencies, reduced or varied protection for intellectual property rights in some markets, increased financial accounting and reporting burdens, import and export restrictions, and changes in trade regulation.\"" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# only picks september\n", - "agent_chain.run(\n", - " input=\"What have been the biggest changes in the macro environment in the past few quarters?\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "id": "f5a356f8-3f4c-456b-90f3-3787704f2421", - "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 look at the financials for September 2022\n", - "Action: Uber 10Q September 2022\n", - "Action Input: N/A\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "The question is not provided.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to look at the financials for June 2022 and March 2022 to get the information I need\n", - "Action: Uber 10Q June 2022\n", - "Action Input: N/A\u001b[0m\n", - "Observation: \u001b[33;1m\u001b[1;3m\n", - "The question is not provided.\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I need to look at the financials for March 2022\n", - "Action: Uber 10Q March 2022\n", - "Action Input: N/A\u001b[0m\n", - "Observation: \u001b[38;5;200m\u001b[1;3m\n", - "N/A\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: Uber had $7.2 billion in cash as of September 2022.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "'Uber had $7.2 billion in cash as of September 2022.'" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# get wrong answer?\n", - "agent_chain.run(input=\"How much cash did Uber have in sept 2022?\")" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "59ca14d6-8b02-4b8e-98f1-dccc0e368171", - "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;3mI need to check the Uber 10Q September 2022 to find the cash amount.\n", - "Action: Uber 10Q September 2022\n", - "Action Input: Cash amount in September 2022\u001b[0m\n", - "Observation: \u001b[36;1m\u001b[1;3m\n", - "$8.6 billion\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3mI now know the final answer.\n", - "Final Answer: Uber had $8.6 billion in cash in September 2022.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "'Uber had $8.6 billion in cash in September 2022.'" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# get better answer\n", - "agent_chain_gpt4.run(input=\"How much cash did Uber have in sept 2022?\")" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "42ede03b-9edb-47a8-8be6-0996b5b54905", - "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 find out how much cash Uber had in March 2022.\n", - "Action: Uber 10Q March 2022\n", - "Action Input: Cash\u001b[0m\n", - "Observation: \u001b[38;5;200m\u001b[1;3mpaid for income taxes, net of refunds, for the three months ended March 31, 2021 was:\n", - "\n", - "22\u001b[0m\n", - "Thought:\u001b[32;1m\u001b[1;3m I now know the final answer\n", - "Final Answer: Uber had $22 million in cash in March 2022.\u001b[0m\n", - "\n", - "\u001b[1m> Finished chain.\u001b[0m\n" - ] - }, - { - "data": { - "text/plain": [ - "'Uber had $22 million in cash in March 2022.'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "agent_chain.run(input=\"How much cash did Uber have in March 2022?\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "57b9bd62-f498-4683-a738-0dda8541495a", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# get wrong answer?\n", - "agent_chain_gpt4.run(input=\"How much cash did Uber have in March 2022?\")" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "3c4bba6c-3fe8-4330-b244-ac3c865dfcde", - "metadata": {}, - "source": [ - "#### Define Graph" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "id": "bb3c96a7-2c87-431b-8c87-7223afec8e1e", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index import ComposableGraph, SummaryIndex" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "id": "96959ae8-11ff-41df-8f95-a68e4b955a50", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "graph = ComposableGraph.from_indices(\n", - " SummaryIndex,\n", - " children_indices=[march_index, june_index, sept_index],\n", - " index_summaries=[\n", - " \"Provides information about Uber quarterly financials ending March 2022\",\n", - " \"Provides information about Uber quarterly financials ending June 2022\",\n", - " \"Provides information about Uber quarterly financials ending September 2022\",\n", - " ],\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "id": "97e7b372-69ff-41d0-8a69-33387c9dd82c", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.query_engine.transform_query_engine import TransformQueryEngine\n", - "from llama_index.indices.query.query_transform.base import DecomposeQueryTransform\n", - "\n", - "# define decompose_transform\n", - "decompose_transform = DecomposeQueryTransform(verbose=True)\n", - "\n", - "# define custom query engines\n", - "custom_query_engines = {}\n", - "for index in [march_index, june_index, sept_index]:\n", - " query_engine = index.as_query_engine(service_context=service_context)\n", - " query_engine = TransformQueryEngine(\n", - " query_engine,\n", - " query_transform=decompose_transform,\n", - " transform_extra_info={\"index_summary\": index.index_struct.summary},\n", - " )\n", - " custom_query_engines[index.index_id] = query_engine\n", - "\n", - "custom_query_engines[graph.root_id] = graph.root_index.as_query_engine(\n", - " service_context=service_context,\n", - " streaming=True,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "id": "2395ab1a-c9d2-4533-9692-770b925ba081", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# define graph\n", - "g_engine = graph.as_query_engine(custom_query_engines=custom_query_engines)" - ] - }, - { - "cell_type": "code", - "execution_count": 119, - "id": "ba213503-ca9d-4880-8cb0-f5290ca69713", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[33;1m\u001b[1;3m> Current query: Analyze Uber revenue growth over the last few quarters\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What was Uber's revenue growth from the last quarter ending March 2022 compared to the previous quarter?\n", - "\u001b[0mINFO:llama_index.token_counter.token_counter:> [retrieve] Total LLM token usage: 0 tokens\n", - "> [retrieve] Total LLM token usage: 0 tokens\n", - "> [retrieve] Total LLM token usage: 0 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [retrieve] Total embedding token usage: 19 tokens\n", - "> [retrieve] Total embedding token usage: 19 tokens\n", - "> [retrieve] Total embedding token usage: 19 tokens\n", - "\u001b[33;1m\u001b[1;3m> Current query: Analyze Uber revenue growth over the last few quarters\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What was Uber's revenue growth from the last quarter ending March 2022 compared to the previous quarter?\n", - "\u001b[0mINFO:llama_index.token_counter.token_counter:> [get_response] Total LLM token usage: 1653 tokens\n", - "> [get_response] Total LLM token usage: 1653 tokens\n", - "> [get_response] Total LLM token usage: 1653 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "\u001b[33;1m\u001b[1;3m> Current query: Analyze Uber revenue growth over the last few quarters\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What was Uber's revenue growth from the last quarter ending June 2022 compared to the previous quarter?\n", - "\u001b[0mINFO:llama_index.token_counter.token_counter:> [retrieve] Total LLM token usage: 0 tokens\n", - "> [retrieve] Total LLM token usage: 0 tokens\n", - "> [retrieve] Total LLM token usage: 0 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [retrieve] Total embedding token usage: 19 tokens\n", - "> [retrieve] Total embedding token usage: 19 tokens\n", - "> [retrieve] Total embedding token usage: 19 tokens\n", - "\u001b[33;1m\u001b[1;3m> Current query: Analyze Uber revenue growth over the last few quarters\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What was Uber's revenue growth from the last quarter ending June 2022 compared to the previous quarter?\n", - "\u001b[0mINFO:llama_index.token_counter.token_counter:> [get_response] Total LLM token usage: 1789 tokens\n", - "> [get_response] Total LLM token usage: 1789 tokens\n", - "> [get_response] Total LLM token usage: 1789 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "\u001b[33;1m\u001b[1;3m> Current query: Analyze Uber revenue growth over the last few quarters\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What was Uber's revenue growth from the last few quarters ending September 2022?\n", - "\u001b[0mINFO:llama_index.token_counter.token_counter:> [retrieve] Total LLM token usage: 0 tokens\n", - "> [retrieve] Total LLM token usage: 0 tokens\n", - "> [retrieve] Total LLM token usage: 0 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [retrieve] Total embedding token usage: 15 tokens\n", - "> [retrieve] Total embedding token usage: 15 tokens\n", - "> [retrieve] Total embedding token usage: 15 tokens\n", - "\u001b[33;1m\u001b[1;3m> Current query: Analyze Uber revenue growth over the last few quarters\n", - "\u001b[0m\u001b[38;5;200m\u001b[1;3m> New query: What was Uber's revenue growth from the last few quarters ending September 2022?\n", - "\u001b[0mINFO:llama_index.token_counter.token_counter:> [get_response] Total LLM token usage: 1365 tokens\n", - "> [get_response] Total LLM token usage: 1365 tokens\n", - "> [get_response] Total LLM token usage: 1365 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [get_response] Total LLM token usage: 0 tokens\n", - "> [get_response] Total LLM token usage: 0 tokens\n", - "> [get_response] Total LLM token usage: 0 tokens\n", - "INFO:llama_index.token_counter.token_counter:> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "> [get_response] Total embedding token usage: 0 tokens\n", - "Based on the context information provided, we can analyze Uber's revenue growth for specific periods, but not for every quarter. Here's a summary of the available data:\n", - "\n", - "1. For the first quarter of 2022, compared to the same period in 2021, the context does not provide specific revenue growth figures.\n", - "\n", - "2. For the three months ended June 30, 2022, compared to the same period in 2021, the context does not provide specific revenue growth figures. However, it does mention that there was growth for both the three and six months ended June 30, 2022, compared to the same periods in 2021.\n", - "\n", - "3. For the three months ended September 30, 2022, compared to the same period in 2021, Uber's revenue growth was 72%, increasing from $4,845 million to $8,343 million.\n", - "\n", - "4. For the nine months ended September 30, 2022, compared to the same period in 2021, Uber's revenue growth was 99%, increasing from $11,677 million to $23,270 million.\n", - "\n", - "In summary, the context information shows that Uber has experienced significant revenue growth in recent periods, particularly in the three months ended September 30, 2022, and the nine months ended September 30, 2022. However, specific revenue growth figures for the first quarter of 2022 and the three months ended June 30, 2022, are not provided in the context.\n" - ] - } - ], - "source": [ - "# test querying the graph\n", - "response = g_engine.query(\"Analyze Uber revenue growth over the last few quarters\")\n", - "print(str(response))" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "id": "8fff0065-7e5e-4b22-a7c7-d454fb433a4e", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "NodeWithScore(node=Node(text=\"\\nUber's revenue growth from the last few quarters ending September 2022 was 99%, with total revenue increasing from $11.7 billion to $23.3 billion.\", doc_id='b65df649-59a3-4ca3-b57f-d6d4f5404364', embedding=None, doc_hash='6b64e2c2316f4da7944aeb5fff13ca96f08590d2ebcfa09732e68905983b7889', extra_info=None, node_info=None, relationships={}), score=None)" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response.source_nodes[2]" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "2d6471ed-5645-4bb0-b8db-1b964ff7cd23", - "metadata": { - "tags": [] - }, - "source": [ - "## Compare and Contrast - OpenAI Function Agent\n", - "\n", - "Use OpenAIAgent, built on top of the OpenAI tool use interface" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "a89972cc-f7b8-4ebd-9c39-935e8a3671ba", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.tools.query_engine import QueryEngineTool\n", - "\n", - "\n", - "query_tool_sept = QueryEngineTool.from_defaults(\n", - " query_engine=sept_engine,\n", - " name=\"sept_2022\",\n", - " description=f\"Provides information about Uber quarterly financials ending September 2022\",\n", - ")\n", - "query_tool_june = QueryEngineTool.from_defaults(\n", - " query_engine=june_engine,\n", - " name=\"june_2022\",\n", - " description=f\"Provides information about Uber quarterly financials ending June 2022\",\n", - ")\n", - "query_tool_march = QueryEngineTool.from_defaults(\n", - " query_engine=march_engine,\n", - " name=\"march_2022\",\n", - " description=f\"Provides information about Uber quarterly financials ending March 2022\",\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "e073c876-e645-462b-947c-43e00c8d60f1", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n" - ] - } - ], - "source": [ - "%load_ext autoreload\n", - "%autoreload 2" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "6466d4bf-59bd-4916-bf28-c1eb71a0a650", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from llama_index.agent import OpenAIAgent\n", - "from llama_index.selectors.llm_selectors import LLMSingleSelector\n", - "\n", - "\n", - "query_engine = OpenAIAgent.from_tools(\n", - " [\n", - " query_tool_sept,\n", - " query_tool_june,\n", - " query_tool_march,\n", - " ],\n", - " max_function_calls=10,\n", - " verbose=True,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "feeb0afc-96c8-4be5-839c-ce8a64fb9e71", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "=== Calling Function ===\n", - "Calling function: sept_2022 with args: {\n", - " \"input\": \"revenue\"\n", - "}\n", - "Got output: \n", - "We generate revenue primarily from fees paid by Mobility Drivers for the use of our platform(s) and related services to facilitate and complete mobility services, and in certain markets, revenue from fees paid by end-users for connection services obtained via the platform. Additionally, in certain markets where we are responsible for delivery services, delivery fees charged to end-users are also included in revenue. We also generate revenue for Delivery from Merchants’ and Couriers’ use of the Delivery platform and related service to facilitate and complete Delivery transactions. Freight revenue consists of revenue from freight transportation services provided to Shippers. Prior to 2022, All Other revenue primarily includes collaboration revenue related to our Advanced Technologies Group (“ATG”) business and revenue from our New Mobility offerings and products.\n", - "========================\n", - "=== Calling Function ===\n", - "Calling function: june_2022 with args: {\n", - " \"input\": \"revenue\"\n", - "}\n", - "Got output: \n", - "Revenue is primarily derived from fees paid by Mobility Drivers for the use of our platform(s) and related services to facilitate and complete mobility services, and in certain markets, revenue from fees paid by end-users for connection services obtained via the platform. Delivery revenue consists of revenue from Merchants’ and Couriers’ use of the Delivery platform and related service to facilitate and complete Delivery transactions. Additionally, in certain markets where we are responsible for delivery services, delivery fees charged to end-users are also included in revenue. Freight revenue consists of revenue from freight transportation services provided to shippers. All Other revenue primarily includes collaboration revenue related to our Advanced Technologies Group (“ATG”) business and revenue from our New Mobility offerings and products.\n", - "========================\n", - "=== Calling Function ===\n", - "Calling function: march_2022 with args: {\n", - " \"input\": \"revenue\"\n", - "}\n", - "Got output: \n", - "Revenue is generated from fees paid by Drivers and Merchants for use of our platform. We also generate revenue from fees paid by end-users for connection services obtained via the platform, and in certain markets, revenue from fees paid by end-users for mobility services. Revenue is net of Driver and Merchant earnings and Driver incentives.\n", - "========================\n", - "Based on the information provided, Uber's revenue growth over the last few quarters can be attributed to the following factors:\n", - "\n", - "1. Fees paid by Mobility Drivers: Revenue is primarily generated from fees paid by Mobility Drivers for the use of Uber's platform and related services to facilitate and complete mobility services. This includes fees paid by Drivers for connecting with passengers and providing transportation services.\n", - "\n", - "2. Fees paid by end-users: In certain markets, Uber also generates revenue from fees paid by end-users for connection services obtained via the platform. This includes fees paid by passengers for booking rides and accessing transportation services.\n", - "\n", - "3. Delivery revenue: Uber's revenue also includes fees paid by Merchants and Couriers for the use of the Delivery platform and related services to facilitate and complete delivery transactions. In certain markets where Uber is responsible for delivery services, delivery fees charged to end-users are also included in revenue.\n", - "\n", - "4. Freight revenue: Uber generates revenue from freight transportation services provided to shippers. This includes fees paid by shippers for using Uber's platform to transport goods.\n", - "\n", - "5. All Other revenue: This category includes collaboration revenue related to Uber's Advanced Technologies Group (ATG) business and revenue from Uber's New Mobility offerings and products. It encompasses various other sources of revenue beyond the core mobility and delivery services.\n", - "\n", - "Overall, Uber's revenue growth is driven by the increasing adoption of its platform by Mobility Drivers, end-users, Merchants, and shippers. The expansion into delivery services and the development of new mobility offerings also contribute to revenue growth.\n" - ] - } - ], - "source": [ - "response = query_engine.query(\"Analyze Uber revenue growth over the last few quarters\")" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "53bfd23d-cbb8-40ce-8bb7-feb3001398dc", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Based on the information provided, Uber's revenue growth over the last few quarters can be attributed to the following factors:\n", - "\n", - "1. Fees paid by Mobility Drivers: Revenue is primarily generated from fees paid by Mobility Drivers for the use of Uber's platform and related services to facilitate and complete mobility services. This includes fees paid by Drivers for connecting with passengers and providing transportation services.\n", - "\n", - "2. Fees paid by end-users: In certain markets, Uber also generates revenue from fees paid by end-users for connection services obtained via the platform. This includes fees paid by passengers for booking rides and accessing transportation services.\n", - "\n", - "3. Delivery revenue: Uber's revenue also includes fees paid by Merchants and Couriers for the use of the Delivery platform and related services to facilitate and complete delivery transactions. In certain markets where Uber is responsible for delivery services, delivery fees charged to end-users are also included in revenue.\n", - "\n", - "4. Freight revenue: Uber generates revenue from freight transportation services provided to shippers. This includes fees paid by shippers for using Uber's platform to transport goods.\n", - "\n", - "5. All Other revenue: This category includes collaboration revenue related to Uber's Advanced Technologies Group (ATG) business and revenue from Uber's New Mobility offerings and products. It encompasses various other sources of revenue beyond the core mobility and delivery services.\n", - "\n", - "Overall, Uber's revenue growth is driven by the increasing adoption of its platform by Mobility Drivers, end-users, Merchants, and shippers. The expansion into delivery services and the development of new mobility offerings also contribute to revenue growth.\n" - ] - } - ], - "source": [ - "print(str(response))" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "5bae0b65-59f5-4b5b-b5a7-1d8c5c4aa308", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "response = query_engine.query(\"Analyze changes in risk factors for Uber\")" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "id": "01703941-f016-47d3-9cf9-fefac0fb54e7", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "To analyze changes in risk factors for Uber, we would need access to the company's financial reports and disclosures. These reports typically provide information about the company's risk factors and any changes that have occurred over time.\n", - "\n", - "Unfortunately, as an AI language model, I don't have real-time access to current financial reports. However, I can provide you with general information about common risk factors that may affect Uber or any other company in the transportation industry. These risk factors can include:\n", - "\n", - "1. Regulatory and Legal Risks: Uber operates in multiple countries and is subject to various regulations and legal challenges. Changes in regulations or legal actions can impact Uber's operations and financial performance.\n", - "\n", - "2. Competitive Landscape: Uber faces competition from other ride-sharing companies, taxi services, and transportation network companies. Changes in the competitive landscape, such as the entry of new competitors or changes in market share, can affect Uber's market position and profitability.\n", - "\n", - "3. Technological Disruption: The transportation industry is undergoing significant technological changes, including the development of autonomous vehicles and the rise of electric vehicles. Uber needs to adapt to these technological advancements to remain competitive.\n", - "\n", - "4. Driver and Rider Safety: Safety incidents involving drivers or riders can negatively impact Uber's reputation and lead to legal liabilities. Ensuring the safety of both drivers and riders is crucial for Uber's success.\n", - "\n", - "5. Economic Factors: Uber's business is influenced by macroeconomic factors such as economic growth, consumer spending, and unemployment rates. Economic downturns can affect demand for ride-sharing services and impact Uber's financial performance.\n", - "\n", - "6. Cybersecurity and Data Privacy: Uber collects and stores a significant amount of user data, including personal and financial information. Cybersecurity breaches or data privacy issues can harm Uber's reputation and result in legal and financial consequences.\n", - "\n", - "It's important to note that the specific risk factors for Uber may vary over time and can be found in the company's financial reports, including its annual reports (Form 10-K) and quarterly reports (Form 10-Q). These reports provide detailed information about the company's risk factors, including any changes or updates.\n", - "\n", - "If you have access to Uber's latest financial reports, I can help you analyze the specific risk factors mentioned in those reports.\n" - ] - } - ], - "source": [ - "print(str(response))" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "ebd52c07-0e46-4edd-8201-caa72b25ae1c", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "=== Calling Function ===\n", - "Calling function: sept_2022 with args: {\n", - " \"input\": \"revenue\"\n", - "}\n", - "Got output: What is the primary source of revenue for Uber?\n", - "\n", - "The primary source of revenue for Uber is fees paid by Mobility Drivers and Merchants for the use of their platform(s) and related services to facilitate and complete mobility and delivery services. In certain markets, revenue from fees paid by end-users for connection services obtained via the platform is also included in revenue. Additionally, revenue from advertising services and freight transportation services provided to shippers are also included in revenue.\n", - "========================\n", - "=== Calling Function ===\n", - "Calling function: june_2022 with args: {\n", - " \"input\": \"revenue\"\n", - "}\n", - "Got output: What is the primary source of revenue for Uber?\n", - "\n", - "The primary source of revenue for Uber is fees paid by Mobility Drivers and Merchants for the use of their platform(s) and related services to facilitate and complete mobility and delivery services. In certain markets, revenue from fees paid by end-users for connection services obtained via the platform is also included in revenue. Additionally, revenue from advertising services and freight transportation services provided to shippers are also included in revenue.\n", - "========================\n", - "=== Calling Function ===\n", - "Calling function: march_2022 with args: {\n", - " \"input\": \"revenue\"\n", - "}\n", - "Got output: What is the main source of revenue for Uber?\n", - "\n", - "The main source of revenue for Uber is fees paid by Drivers and Merchants for use of their platform, as they act as an agent in these transactions by connecting consumers to Drivers and Merchants to facilitate a Trip, meal or grocery delivery service. However, in certain markets where they are responsible for mobility services, they present revenue from end-users on a gross basis, as they control the service provided by Drivers to end-users, while payments to Drivers in exchange for mobility services are recognized in cost of revenue, exclusive of depreciation and amortization.\n", - "========================\n", - "=== Calling Function ===\n", - "Calling function: sept_2022 with args: {\n", - " \"input\": \"risk factors\"\n", - "}\n", - "Got output: What is the topic of the text?\n", - "\n", - "The topic of the text is risk factors related to Uber's business operations, including economic risks, dependencies on third parties, and conducting business internationally. The text also mentions the impact of the COVID-19 pandemic on Uber's business.\n", - "========================\n", - "=== Calling Function ===\n", - "Calling function: june_2022 with args: {\n", - " \"input\": \"risk factors\"\n", - "}\n", - "Got output: What are some of the risks mentioned in the document?\n", - "\n", - "Some of the risks mentioned in the document include the impact of the COVID-19 pandemic on the business and financial results, economic conditions and their impact on discretionary consumer spending, climate change risks, security or data privacy breaches, cyberattacks, the need for additional capital to support the growth of the business, legal and regulatory risks, and risks related to the collection, use, transfer, disclosure, and other processing of data.\n", - "========================\n", - "=== Calling Function ===\n", - "Calling function: march_2022 with args: {\n", - " \"input\": \"risk factors\"\n", - "}\n", - "Got output: What is the topic of the \"Risk Factors\" section in the document?\n", - "\n", - "The topic of the \"Risk Factors\" section in the document is the potential risks and challenges that could have an adverse effect on Uber's business, financial condition, and results of operations. The section outlines various risks related to economic, social, weather, and regulatory conditions, cybersecurity, data privacy breaches, climate change, legal and regulatory risks, intellectual property, and market volatility, among others.\n", - "========================\n" - ] - } - ], - "source": [ - "response = query_engine.query(\n", - " \"Analyze Uber revenue growth and risk factors over quarters\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "id": "c47e41be-d61c-4992-b1c7-e038e1860d33", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Based on the available information, the primary source of revenue for Uber is fees paid by Mobility Drivers and Merchants for the use of their platform and related services. This includes fees paid by end-users for connection services obtained via the platform, revenue from advertising services, and revenue from freight transportation services provided to shippers.\n", - "\n", - "As for the risk factors, some of the key risks mentioned include the impact of the COVID-19 pandemic on Uber's business and financial results, economic conditions affecting consumer spending, climate change risks, security and data privacy breaches, the need for additional capital, legal and regulatory risks, and risks related to data collection and processing.\n", - "\n", - "Please note that the specific details and analysis of revenue growth and risk factors may vary in the actual financial reports and disclosures provided by Uber.\n" - ] - } - ], - "source": [ - "print(str(response))" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "ba9d02e4-4c5c-47d2-8cf4-62bcc967e6f2", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "NodeWithScore(node=Node(text=\"The context information provided does not include data for September 2019, so it is not possible to determine Uber's revenue growth from September 2019 to September 2022.\", doc_id='482b9a72-cc11-46a2-833d-99d5a24f71bc', embedding=None, doc_hash='cd1c6c860a4bd10f1216afef4b4ccdc4e4966d7b131659bd072af03f15cf493e', extra_info=None, node_info=None, relationships={}), score=None)" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response.source_nodes[2]" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "id": "8c71117d-70e8-435f-855d-c75c66f36b7f", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "=== Calling Function ===\n", - "Calling function: sept_2022 with args: {\n", - " \"input\": \"cash\"\n", - "}\n", - "Got output: What is the amount of net cash provided by operating activities for the nine months ended September 30, 2022?\n", - "\n", - "The amount of net cash provided by operating activities for the nine months ended September 30, 2022 is $886 million.\n", - "========================\n" - ] - } - ], - "source": [ - "response = query_engine.query(\"How much cash did Uber have in sept 2022?\")" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "id": "7e0a02d6-13e2-4e6e-a100-c95acd131083", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Uber had $886 million in net cash provided by operating activities for the nine months ended September 30, 2022.\n" - ] - } - ], - "source": [ - "print(str(response))" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "521c4b41-89ae-40d5-8e06-e626d59d78a2", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "response.source_nodes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "598f6f3c-e5ac-401b-925a-7a6cce0620bd", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "llama_index_v2", - "language": "python", - "name": "llama_index_v2" - }, - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}