├── requirements.txt ├── app.py ├── README.md ├── tools └── fetch_stock_info.py └── stock_analyzer_bot.ipynb /requirements.txt: -------------------------------------------------------------------------------- 1 | langchain==0.0.227 2 | streamlit 3 | openai 4 | bs4 5 | yfinance -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import tools 3 | from tools.fetch_stock_info import Anazlyze_stock 4 | 5 | st.title("Stock Analysis bot") 6 | st.write("This bot scraps and gathers real time stock realted information and analyzes it using LLM") 7 | 8 | query = st.text_input('Input your investment related query:') 9 | 10 | Enter=st.button("Enter") 11 | clear=st.button("Clear") 12 | 13 | if clear: 14 | print(clear) 15 | st.markdown(' ') 16 | 17 | if Enter: 18 | import time 19 | with st.spinner('Gathering all required information and analyzing. Be patient!!!!!'): 20 | out=Anazlyze_stock(query) 21 | st.success('Done!') 22 | st.write(out) 23 | 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Stock Analyzer 📈 2 | An AI Bot that can help you with stock investment by analyzing all the real-time as well as historic stock-related information with the help of LLM 3 | 4 | # Blog- 5 | https://medium.com/p/7f8a62cbcaaa 6 | # Motivation 7 | 8 | As a retail investor, if you don't have a finance background or the capability to understand all the complicated financial terms, makes the stock analysis process really time-consuming. Every time I end up watching some fin-YouTuber's video or some random blog on the internet to avoid manually dealing with all this stuff. This is where i thought of making a Langchian and LLM-based bot that can take real-time as well as historic data to make investment analysis 9 | 14 | # Experimentation 15 | Have defined a couple of tools/functions for the agent which scraps and gather real time information related to the input stock. It includes following- 16 | 1. Historic Stock price data. (You can take 1month, 1 year data depending on you models context length) 17 | 2. Company's financial statement 18 | 3. Latest company related news 19 | All these factors seems sufficient for the analysis, it captures historical performance as well as real time market sentiment. If you want further more tools can be added. 20 | 21 | #### Approach 1- Using langchain ReAct agent 22 | - The response and action agent did not turn out to be that good. Sometimes the results were below average 23 | - Zero shot React agent dynamically thinks about the query in runtime and tries to perform action based on the thought 24 | - The agent used to get stuck in infinite loop of thoughts and actions as it was not able to think with that kind of expected level for complicated task like stock analysis 25 | - This approach may work or may not, Further improvements can be made by modifying the prompt 26 | 27 | #### Approach 2- Predefine prompt with function calls 28 | - Open ai has introduced function call a month ago, which is really helpful with which we can get structured output as we want in json format from LLM 29 | - In this method stock ticker is extracted with the help of function calls. As most of the future code was dependet on this single argument 30 | - And in the later stages stock data, news, financial statements are simply fetched by inputting ticker symbol. Further analyzed by openai llm 31 | - It is recommended to use this approach for robust and stable analysis 32 | 33 | # Example - 34 | Input- \ 35 | ```Anazlyze_stock("Is it a good time to invest in Adani power?") ``` 36 | 37 | Output- 38 | 39 | ``` 40 | {'Query': 'Shall I invest in Adani power right now?', 'Company_name': 'Adani Power', 'Ticker': 'ADANIPOWER'} 41 | 42 | 43 | Analyzing..... 44 | 45 | Investment Thesis for Adani Power: 46 | 47 | 1. Strong Financials: Adani Power has shown consistent growth in its financials over the past three years. The company has a positive tangible book value, indicating a strong asset base. Additionally, the company has a high invested capital, which suggests a strong financial position. 48 | 2. Increasing Stock Price: The stock price of Adani Power has been increasing steadily over the past few days. This indicates positive investor sentiment and potential for further growth in the future. 49 | 3. Declining Revenues: Adani Power has reported declining revenues in its recent quarterly results. This could be a concern for investors as it may indicate a slowdown in the company's business operations. However, further analysis is required to determine the reasons behind the decline and its potential impact on future performance. 50 | 4. Positive News Coverage: Adani Power has been in the news recently, with multiple articles highlighting the company's performance and prospects. Positive news coverage can attract more investors and potentially drive up the stock price. 51 | 5. Power Sector Outlook: The power sector in India is expected to grow in the coming years due to increasing demand for electricity. Adani Power, being a major player in the sector, is well-positioned to benefit from this growth. However, it is important to consider the competitive landscape and regulatory environment of the sector before making an investment decision. 52 | 53 | Conclusion: 54 | Based on the available data, investing in Adani Power right now could be a favorable option. The company has strong financials and a positive stock price trend. However, it is important to conduct further research and analysis to fully understand the reasons behind the declining revenues and assess the potential risks associated with the power sector. 55 | ``` 56 | 57 | 58 | # Further improvements and addition to be done 59 | a) Streamlit Demo \ 60 | b) More tools can be added. Fo eg. math tool to perform complex technical analysis \ 61 | b) More robust prompting for stable output \ 62 | c) Support of other opensource LLMS \ 63 | d) Note- I am not a finance expert, Its just a fun hobby project, Feel free to add any suggestions/ moodification 64 | 65 | -------------------------------------------------------------------------------- /tools/fetch_stock_info.py: -------------------------------------------------------------------------------- 1 | import json 2 | import time 3 | from bs4 import BeautifulSoup 4 | import re 5 | import requests 6 | 7 | from langchain.llms import OpenAI 8 | from langchain.agents import load_tools, AgentType, Tool, initialize_agent 9 | import yfinance as yf 10 | 11 | import openai 12 | import warnings 13 | import os 14 | warnings.filterwarnings("ignore") 15 | 16 | os.environ["OPENAI_API_KEY"] = "Enter your API key here" 17 | 18 | 19 | llm=OpenAI(temperature=0, 20 | model_name="gpt-3.5-turbo-16k-0613") 21 | 22 | 23 | # Fetch stock data from Yahoo Finance 24 | def get_stock_price(ticker,history=5): 25 | # time.sleep(4) #To avoid rate limit error 26 | if "." in ticker: 27 | ticker=ticker.split(".")[0] 28 | ticker=ticker+".NS" 29 | stock = yf.Ticker(ticker) 30 | df = stock.history(period="1y") 31 | df=df[["Close","Volume"]] 32 | df.index=[str(x).split()[0] for x in list(df.index)] 33 | df.index.rename("Date",inplace=True) 34 | df=df[-history:] 35 | # print(df.columns) 36 | 37 | return df.to_string() 38 | 39 | # Script to scrap top5 googgle news for given company name 40 | def google_query(search_term): 41 | if "news" not in search_term: 42 | search_term=search_term+" stock news" 43 | url=f"https://www.google.com/search?q={search_term}&cr=countryIN" 44 | url=re.sub(r"\s","+",url) 45 | return url 46 | 47 | def get_recent_stock_news(company_name): 48 | # time.sleep(4) #To avoid rate limit error 49 | headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'} 50 | 51 | g_query=google_query(company_name) 52 | res=requests.get(g_query,headers=headers).text 53 | soup=BeautifulSoup(res,"html.parser") 54 | news=[] 55 | for n in soup.find_all("div","n0jPhd ynAwRc tNxQIb nDgy9d"): 56 | news.append(n.text) 57 | for n in soup.find_all("div","IJl0Z"): 58 | news.append(n.text) 59 | 60 | if len(news)>6: 61 | news=news[:4] 62 | else: 63 | news=news 64 | news_string="" 65 | for i,n in enumerate(news): 66 | news_string+=f"{i}. {n}\n" 67 | top5_news="Recent News:\n\n"+news_string 68 | 69 | return top5_news 70 | 71 | 72 | # Fetch financial statements from Yahoo Finance 73 | def get_financial_statements(ticker): 74 | # time.sleep(4) #To avoid rate limit error 75 | if "." in ticker: 76 | ticker=ticker.split(".")[0] 77 | else: 78 | ticker=ticker 79 | ticker=ticker+".NS" 80 | company = yf.Ticker(ticker) 81 | balance_sheet = company.balance_sheet 82 | if balance_sheet.shape[1]>=3: 83 | balance_sheet=balance_sheet.iloc[:,:3] # Remove 4th years data 84 | balance_sheet=balance_sheet.dropna(how="any") 85 | balance_sheet = balance_sheet.to_string() 86 | return balance_sheet 87 | 88 | 89 | #Openai function calling 90 | function=[ 91 | { 92 | "name": "get_company_Stock_ticker", 93 | "description": "This will get the indian NSE/BSE stock ticker of the company", 94 | "parameters": { 95 | "type": "object", 96 | "properties": { 97 | "ticker_symbol": { 98 | "type": "string", 99 | "description": "This is the stock symbol of the company.", 100 | }, 101 | 102 | "company_name": { 103 | "type": "string", 104 | "description": "This is the name of the company given in query", 105 | } 106 | }, 107 | "required": ["company_name","ticker_symbol"], 108 | }, 109 | } 110 | ] 111 | 112 | 113 | def get_stock_ticker(query): 114 | response = openai.ChatCompletion.create( 115 | model="gpt-3.5-turbo", 116 | temperature=0, 117 | messages=[{ 118 | "role":"user", 119 | "content":f"Given the user request, what is the comapany name and the company stock ticker ?: {query}?" 120 | }], 121 | functions=function, 122 | function_call={"name": "get_company_Stock_ticker"}, 123 | ) 124 | message = response["choices"][0]["message"] 125 | arguments = json.loads(message["function_call"]["arguments"]) 126 | company_name = arguments["company_name"] 127 | company_ticker = arguments["ticker_symbol"] 128 | return company_name,company_ticker 129 | 130 | def Anazlyze_stock(query): 131 | #agent.run(query) Outputs Company name, Ticker 132 | Company_name,ticker=get_stock_ticker(query) 133 | print({"Query":query,"Company_name":Company_name,"Ticker":ticker}) 134 | stock_data=get_stock_price(ticker,history=10) 135 | stock_financials=get_financial_statements(ticker) 136 | stock_news=get_recent_stock_news(Company_name) 137 | 138 | available_information=f"Stock Price: {stock_data}\n\nStock Financials: {stock_financials}\n\nStock News: {stock_news}" 139 | #available_information=f"Stock Financials: {stock_financials}\n\nStock News: {stock_news}" 140 | 141 | # print("\n\nAnalyzing.....\n") 142 | analysis=llm(f"Give detail stock analysis, Use the available data and provide investment recommendation. \ 143 | The user is fully aware about the investment risk, dont include any kind of warning like 'It is recommended to conduct further research and analysis or consult with a financial advisor before making an investment decision' in the answer \ 144 | User question: {query} \ 145 | You have the following information available about {Company_name}. Write (5-8) pointwise investment analysis to answer user query, At the end conclude with proper explaination.Try to Give positives and negatives : \ 146 | {available_information} " 147 | ) 148 | # print(analysis) 149 | 150 | return analysis 151 | -------------------------------------------------------------------------------- /stock_analyzer_bot.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import os\n", 10 | "import time\n", 11 | "from bs4 import BeautifulSoup\n", 12 | "import re\n", 13 | "import requests\n", 14 | "import warnings\n", 15 | "\n", 16 | "import langchain\n", 17 | "from langchain.llms import OpenAI\n", 18 | "from langchain.agents import load_tools, AgentType, Tool, initialize_agent\n", 19 | "os.environ[\"OPENAI_API_KEY\"] = \"ENter your API key here\"\n", 20 | "\n", 21 | "warnings.filterwarnings(\"ignore\")" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 3, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "\n", 31 | "llm=OpenAI(temperature=0,\n", 32 | " model_name=\"gpt-3.5-turbo-16k-0613\")" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "### Defining the custom Tools" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 4, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | " Close Volume\n", 52 | "Date \n", 53 | "2023-07-31 3004.050049 656048\n", 54 | "2023-08-01 3001.899902 602288\n", 55 | "2023-08-02 2977.149902 1152335\n", 56 | "2023-08-03 2902.100098 3319847\n", 57 | "2023-08-04 2904.399902 709334\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "import yfinance as yf\n", 63 | "\n", 64 | "# Fetch stock data from Yahoo Finance\n", 65 | "\n", 66 | "def get_stock_price(ticker,history=5):\n", 67 | " # time.sleep(4) #To avoid rate limit error\n", 68 | " if \".\" in ticker:\n", 69 | " ticker=ticker.split(\".\")[0]\n", 70 | " ticker=ticker+\".NS\"\n", 71 | " stock = yf.Ticker(ticker)\n", 72 | " df = stock.history(period=\"1y\")\n", 73 | " df=df[[\"Close\",\"Volume\"]]\n", 74 | " df.index=[str(x).split()[0] for x in list(df.index)]\n", 75 | " df.index.rename(\"Date\",inplace=True)\n", 76 | " df=df[-history:]\n", 77 | " # print(df.columns)\n", 78 | " \n", 79 | " return df.to_string()\n", 80 | "\n", 81 | "print(get_stock_price(\"TITAN\"))" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 5, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "Recent News:\n", 94 | "\n", 95 | "0. Asian Paint share price Today Live Updates : Asian Paint closed today at \n", 96 | "₹3339.9, up 0.13% from yesterday's ₹3335.55 | Mint\n", 97 | "1. Asian Paint share price Today Live Updates : Asian Paint closed today at \n", 98 | "₹3335.55, down -0.82% from yesterday's ₹3363.25 | Mint\n", 99 | "\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "# Script to scrap top5 googgle news for given company name\n", 105 | "\n", 106 | "def google_query(search_term):\n", 107 | " if \"news\" not in search_term:\n", 108 | " search_term=search_term+\" stock news\"\n", 109 | " url=f\"https://www.google.com/search?q={search_term}&cr=countryIN\"\n", 110 | " url=re.sub(r\"\\s\",\"+\",url)\n", 111 | " return url\n", 112 | "\n", 113 | "def get_recent_stock_news(company_name):\n", 114 | " # time.sleep(4) #To avoid rate limit error\n", 115 | " headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}\n", 116 | "\n", 117 | " g_query=google_query(company_name)\n", 118 | " res=requests.get(g_query,headers=headers).text\n", 119 | " soup=BeautifulSoup(res,\"html.parser\")\n", 120 | " news=[]\n", 121 | " for n in soup.find_all(\"div\",\"n0jPhd ynAwRc tNxQIb nDgy9d\"):\n", 122 | " news.append(n.text)\n", 123 | " for n in soup.find_all(\"div\",\"IJl0Z\"):\n", 124 | " news.append(n.text)\n", 125 | "\n", 126 | "\n", 127 | " if len(news)>6:\n", 128 | " news=news[:4]\n", 129 | " else:\n", 130 | " news=news\n", 131 | " news_string=\"\"\n", 132 | " for i,n in enumerate(news):\n", 133 | " news_string+=f\"{i}. {n}\\n\"\n", 134 | " top5_news=\"Recent News:\\n\\n\"+news_string\n", 135 | " \n", 136 | " return top5_news\n", 137 | "\n", 138 | "\n", 139 | "print(get_recent_stock_news(\"Asian paints\"))" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 8, 145 | "metadata": {}, 146 | "outputs": [ 147 | { 148 | "name": "stdout", 149 | "output_type": "stream", 150 | "text": [ 151 | " 2023-03-31 2022-03-31 2021-03-31\n", 152 | "Ordinary Shares Number 3195339547.0 3196991847.0 3195339547.0\n", 153 | "Share Issued 3195339547.0 3196991847.0 3195339547.0\n", 154 | "Net Debt 447846700000.0 445128500000.0 393856600000.0\n", 155 | "Total Debt 529230000000.0 511952100000.0 467054800000.0\n", 156 | "Tangible Book Value 255477800000.0 192170700000.0 191818400000.0\n", 157 | "Invested Capital 777618600000.0 700316500000.0 654904300000.0\n", 158 | "Working Capital -130012100000.0 -141013900000.0 -114893300000.0\n", 159 | "Net Tangible Assets 255477800000.0 192170700000.0 191818400000.0\n", 160 | "Capital Lease Obligations 39485700000.0 36051200000.0 35373100000.0\n", 161 | "Common Stock Equity 287874300000.0 224415600000.0 223222600000.0\n", 162 | "Total Capitalization 594959200000.0 551712600000.0 523672900000.0\n", 163 | "Total Equity Gross Minority Interest 342041200000.0 260284600000.0 252495600000.0\n", 164 | "Minority Interest 54166900000.0 35869000000.0 29273000000.0\n", 165 | "Stockholders Equity 287874300000.0 224415600000.0 223222600000.0\n", 166 | "Other Equity Interest 284678700000.0 221220000000.0 15000700000.0\n", 167 | "Capital Stock 3195600000.0 3195600000.0 3195600000.0\n", 168 | "Common Stock 3195600000.0 3195600000.0 3195600000.0\n", 169 | "Total Liabilities Net Minority Interest 941449200000.0 868561400000.0 736016500000.0\n", 170 | "Total Non Current Liabilities Net Minority Interest 500521400000.0 481224900000.0 426937800000.0\n", 171 | "Other Non Current Liabilities 110831600000.0 6907400000.0 1763200000.0\n", 172 | "Tradeand Other Payables Non Current 5619200000.0 3443800000.0 6705200000.0\n", 173 | "Non Current Deferred Revenue 106555100000.0 88984000000.0 68437000000.0\n", 174 | "Non Current Deferred Taxes Liabilities 19193700000.0 10333000000.0 9761500000.0\n", 175 | "Long Term Debt And Capital Lease Obligation 342191900000.0 359374900000.0 331875100000.0\n", 176 | "Long Term Capital Lease Obligation 35107000000.0 32077900000.0 31424800000.0\n", 177 | "Long Term Debt 307084900000.0 327297000000.0 300450300000.0\n", 178 | "Long Term Provisions 14200200000.0 12181800000.0 8395800000.0\n", 179 | "Current Liabilities 440927800000.0 387336500000.0 309078700000.0\n", 180 | "Other Current Liabilities 41884100000.0 34063600000.0 24453500000.0\n", 181 | "Current Debt And Capital Lease Obligation 187038100000.0 152577200000.0 135179700000.0\n", 182 | "Current Capital Lease Obligation 4378700000.0 3973300000.0 3948300000.0\n", 183 | "Current Debt 182659400000.0 148603900000.0 131231400000.0\n", 184 | "Current Provisions 3110700000.0 3448200000.0 2701100000.0\n", 185 | "Payables 76251600000.0 144512800000.0 104453000000.0\n", 186 | "Other Payable 55739500000.0 38212300000.0 31036100000.0\n", 187 | "Dividends Payable 237000000.0 234500000.0 232300000.0\n", 188 | "Total Tax Payable 2179600000.0 1470000000.0 1983800000.0\n", 189 | "Accounts Payable 74072000000.0 104596000000.0 71200800000.0\n", 190 | "Total Assets 1283490400000.0 1128846000000.0 988512100000.0\n", 191 | "Total Non Current Assets 972574700000.0 882523400000.0 794326700000.0\n", 192 | "Other Non Current Assets 109658900000.0 68105700000.0 64781700000.0\n", 193 | "Non Current Prepaid Assets 7390700000.0 21127000000.0 15158100000.0\n", 194 | "Non Current Deferred Taxes Assets 2529000000.0 3346000000.0 1840200000.0\n", 195 | "Investmentin Financial Assets 30278700000.0 11698100000.0 10948700000.0\n", 196 | "Available For Sale Securities 30278700000.0 11696500000.0 10932700000.0\n", 197 | "Long Term Equity Investment 142188800000.0 125800000000.0 119206300000.0\n", 198 | "Goodwill And Other Intangible Assets 32396500000.0 32244900000.0 31404200000.0\n", 199 | "Other Intangible Assets 13813400000.0 13661800000.0 13458500000.0\n", 200 | "Goodwill 18583100000.0 18583100000.0 17945700000.0\n", 201 | "Net PPE 638833700000.0 588000600000.0 523486600000.0\n", 202 | "Accumulated Depreciation -8091000000.0 -241656400000.0 -213488100000.0\n", 203 | "Gross PPE 638833700000.0 829657000000.0 736974700000.0\n", 204 | "Construction In Progress 53763600000.0 46351000000.0 35998000000.0\n", 205 | "Other Properties 585070100000.0 180296700000.0 142804800000.0\n", 206 | "Machinery Furniture Equipment 7504300000.0 539737700000.0 497834500000.0\n", 207 | "Land And Improvements 13102300000.0 28868100000.0 27757300000.0\n", 208 | "Properties 0.0 0.0 0.0\n", 209 | "Current Assets 310915700000.0 246322600000.0 194185400000.0\n", 210 | "Other Current Assets 13287200000.0 14796700000.0 9166900000.0\n", 211 | "Assets Held For Sale Current 32999400000.0 30468300000.0 30474600000.0\n", 212 | "Current Deferred Assets 11100000.0 11100000.0 11100000.0\n", 213 | "Restricted Cash 70167700000.0 35634600000.0 23301700000.0\n", 214 | "Prepaid Assets 6900000.0 15937100000.0 10151600000.0\n", 215 | "Inventory 39428800000.0 42315200000.0 18848000000.0\n", 216 | "Other Inventories 15700000.0 16600000.0 16000000.0\n", 217 | "Finished Goods 5918700000.0 5324400000.0 941500000.0\n", 218 | "Work In Process 69900000.0 119900000.0 1944000000.0\n", 219 | "Raw Materials 33424500000.0 36854300000.0 15946500000.0\n", 220 | "Other Receivables 24682600000.0 26758800000.0 18057300000.0\n", 221 | "Taxes Receivable 2700000.0 2800000.0 81600000.0\n", 222 | "Accounts Receivable 69521500000.0 59797400000.0 50009700000.0\n", 223 | "Allowance For Doubtful Accounts Receivable -10158500000.0 -5735600000.0 -4376500000.0\n", 224 | "Gross Accounts Receivable 79680000000.0 65533000000.0 54386200000.0\n", 225 | "Cash Cash Equivalents And Short Term Investments 130444300000.0 34877600000.0 42820500000.0\n", 226 | "Other Short Term Investments 88546700000.0 4105200000.0 4995400000.0\n", 227 | "Cash And Cash Equivalents 41897600000.0 30772400000.0 37825100000.0\n", 228 | "Cash Equivalents 19861500000.0 17020900000.0 25438400000.0\n", 229 | "Cash Financial 22036100000.0 13751500000.0 12386700000.0\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "# Fetch financial statements from Yahoo Finance\n", 235 | "\n", 236 | "def get_financial_statements(ticker):\n", 237 | " # time.sleep(4) #To avoid rate limit error\n", 238 | " if \".\" in ticker:\n", 239 | " ticker=ticker.split(\".\")[0]\n", 240 | " else:\n", 241 | " ticker=ticker\n", 242 | " ticker=ticker+\".NS\" \n", 243 | " company = yf.Ticker(ticker)\n", 244 | " balance_sheet = company.balance_sheet\n", 245 | " if balance_sheet.shape[1]>=3:\n", 246 | " balance_sheet=balance_sheet.iloc[:,:3] # Remove 4th years data\n", 247 | " balance_sheet=balance_sheet.dropna(how=\"any\")\n", 248 | " balance_sheet = balance_sheet.to_string()\n", 249 | " \n", 250 | " # cash_flow = company.cash_flow.to_string()\n", 251 | " # print(balance_sheet)\n", 252 | " # print(cash_flow)\n", 253 | " return balance_sheet\n", 254 | "print(get_financial_statements(\"TATAPOWER.NS\"))" 255 | ] 256 | }, 257 | { 258 | "cell_type": "markdown", 259 | "metadata": {}, 260 | "source": [ 261 | "### Custom tools" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": 7, 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "data": { 271 | "text/plain": [ 272 | "'Share Market Today - Stock Market and Share Market Live Updates: Get all the latest share market and India stock market news and updates on Moneycontrol.com CAMS Q1 Results: Profit grows 18% to Rs 76 crore. \"The Indian mutual fund industry grew by 6.4 per cent quarter-on-quarter (Q-o-Q) to reach Rs 43.8 lakh crore in AUM and is well-positioned for future growth. Our assets under management grew by 6.8 per cent Q-o-Q, ahead of the industry, to cross the Rs 30 lakh crore mark,\\'\\' Anuj Kumar, Managing ... Morgan Stanley upgrades India stocks, reveals names to buy \\'Stark contrast\\' to China: Morgan Stanley upgrades India stocks and shares 4 top picks Published Thu, Aug 3 20237:47 PM EDT Weizhen... NSE - National Stock Exchange of India Ltd: Live Share/Stock Market News & Updates, Quotes- Nseindia.com NSE Indices Equities Derivatives Reference Rates Market Turnover Complaints & Reporting Filter Indices View All Indices NIFTY 50 19,517.00 135.35 (0.70%) NIFTY NEXT 50 44,765.00 350.45 (0.79%) NIFTY MIDCAP SELECT 8,571.70 70.70 (0.83%) By Ankita Garg: India on Thursday announced an immediate import restriction for laptops and personal computers, noting that any entity or company planning to bring laptops and computers for sale in India will have to apply for and obtain a \"Valid Licence for Restricted Imports\".. The sudden move means that companies like Apple, which sells MacBooks as well as Mac mini and other computers, will ...'" 273 | ] 274 | }, 275 | "execution_count": 7, 276 | "metadata": {}, 277 | "output_type": "execute_result" 278 | } 279 | ], 280 | "source": [ 281 | "from langchain.tools import DuckDuckGoSearchRun\n", 282 | "search=DuckDuckGoSearchRun()\n", 283 | "\n", 284 | "search(\"Stock news India\")" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 42, 290 | "metadata": {}, 291 | "outputs": [], 292 | "source": [ 293 | "# Making tool list\n", 294 | "\n", 295 | "tools=[\n", 296 | " Tool(\n", 297 | " name=\"get stock data\",\n", 298 | " func=get_stock_price,\n", 299 | " description=\"Use when you are asked to evaluate or analyze a stock. This will output historic share price data. You should input the the stock ticker to it \"\n", 300 | " ),\n", 301 | " Tool(\n", 302 | " name=\"DuckDuckGo Search\",\n", 303 | " func=search.run,\n", 304 | " description=\"Use only when you need to get NSE/BSE stock ticker from internet, you can also get recent stock related news. Dont use it for any other analysis or task\"\n", 305 | " ),\n", 306 | " Tool(\n", 307 | " name=\"get recent news\",\n", 308 | " func=get_recent_stock_news,\n", 309 | " description=\"Use this to fetch recent news about stocks\"\n", 310 | " ),\n", 311 | "\n", 312 | " Tool(\n", 313 | " name=\"get financial statements\",\n", 314 | " func=get_financial_statements,\n", 315 | " description=\"Use this to get financial statement of the company. With the help of this data companys historic performance can be evaluaated. You should input stock ticker to it\"\n", 316 | " ) \n", 317 | "\n", 318 | "\n", 319 | "]" 320 | ] 321 | }, 322 | { 323 | "cell_type": "markdown", 324 | "metadata": {}, 325 | "source": [ 326 | "#### Approach1- React Agent" 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": 74, 332 | "metadata": {}, 333 | "outputs": [], 334 | "source": [ 335 | "from langchain.agents import initialize_agent \n", 336 | "\n", 337 | "zero_shot_agent=initialize_agent(\n", 338 | " llm=llm,\n", 339 | " agent=\"zero-shot-react-description\",\n", 340 | " tools=tools,\n", 341 | " verbose=True,\n", 342 | " max_iteration=4,\n", 343 | " return_intermediate_steps=True,\n", 344 | " handle_parsing_errors=True\n", 345 | ")\n", 346 | "\n" 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": 75, 352 | "metadata": {}, 353 | "outputs": [ 354 | { 355 | "name": "stdout", 356 | "output_type": "stream", 357 | "text": [ 358 | "Answer the following questions as best you can. You have access to the following tools:\n", 359 | "\n", 360 | "get stock data: Use when you are asked to evaluate or analyze a stock. This will output historic share price data. You should input the the stock ticker to it \n", 361 | "DuckDuckGo Search: Use only when you need to get NSE/BSE stock ticker from internet, you can also get recent stock related news. Dont use it for any other analysis or task\n", 362 | "get recent news: Use this to fetch recent news about stocks\n", 363 | "get financial statements: Use this to get financial statement of the company. With the help of this data companys historic performance can be evaluaated. You should input stock ticker to it\n", 364 | "\n", 365 | "Use the following format:\n", 366 | "\n", 367 | "Question: the input question you must answer\n", 368 | "Thought: you should always think about what to do\n", 369 | "Action: the action to take, should be one of [get stock data, DuckDuckGo Search, get recent news, get financial statements]\n", 370 | "Action Input: the input to the action\n", 371 | "Observation: the result of the action\n", 372 | "... (this Thought/Action/Action Input/Observation can repeat N times)\n", 373 | "Thought: I now know the final answer\n", 374 | "Final Answer: the final answer to the original input question\n", 375 | "\n", 376 | "Begin!\n", 377 | "\n", 378 | "Question: {input}\n", 379 | "Thought:{agent_scratchpad}\n" 380 | ] 381 | } 382 | ], 383 | "source": [ 384 | "print(zero_shot_agent.agent.llm_chain.prompt.template) \n" 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": 82, 390 | "metadata": {}, 391 | "outputs": [], 392 | "source": [ 393 | "#Adding predefine evaluation steps in the agent Prompt\n", 394 | "\n", 395 | "new_prompt=\"\"\"You are a financial advisor. Give stock recommendations for given query.\n", 396 | "Everytime first you should identify the company name and get the stock ticker symbole for indian stock.\n", 397 | "Answer the following questions as best you can. You have access to the following tools:\n", 398 | "\n", 399 | "get stock data: Use when you are asked to evaluate or analyze a stock. This will output historic share price data. You should input the the stock ticker to it \n", 400 | "DuckDuckGo Search: Use only when you need to get NSE/BSE stock ticker from internet, you can also get recent stock related news. Dont use it for any other analysis or task\n", 401 | "get recent news: Use this to fetch recent news about stocks\n", 402 | "get financial statements: Use this to get financial statement of the company. With the help of this data companys historic performance can be evaluaated. You should input stock ticker to it\n", 403 | "\n", 404 | "steps- \n", 405 | "Note- if you fail in satisfying any of the step below, Just move to next one\n", 406 | "1) Get the company name and search for the \"company name + NSE/BSE stock ticker\" on internet. Dont hallucinate extract stock ticker as it is from the text. Output- stock ticker\n", 407 | "2) Use \"get stock data\" tool to gather stock info. Output- Stock data\n", 408 | "3) Get company's historic financial data using \"get financial statements\". Output- Financial statement\n", 409 | "4) Use this \"get recent news\" tool to search for latest stock realted news. Output- Stock news\n", 410 | "5) Analyze the stock based on gathered data and give detail analysis for investment choice. provide numbers and reasons to justify your answer. Output- Detailed stock Analysis\n", 411 | "\n", 412 | "Use the following format:\n", 413 | "\n", 414 | "Question: the input question you must answer\n", 415 | "Thought: you should always think about what to do, Also try to follow steps mentioned above\n", 416 | "Action: the action to take, should be one of [get stock data, DuckDuckGo Search, get recent news, get financial statements]\n", 417 | "Action Input: the input to the action\n", 418 | "Observation: the result of the action\n", 419 | "... (this Thought/Action/Action Input/Observation can repeat N times)\n", 420 | "Thought: I now know the final answer\n", 421 | "Final Answer: the final answer to the original input question\n", 422 | "Begin!\n", 423 | "\n", 424 | "Question: {input}\n", 425 | "Thought:{agent_scratchpad}\"\"\"\n", 426 | "\n" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": 83, 432 | "metadata": {}, 433 | "outputs": [], 434 | "source": [ 435 | "#Setting up new prompt\n", 436 | "zero_shot_agent.agent.llm_chain.prompt.template=new_prompt\n" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 78, 442 | "metadata": {}, 443 | "outputs": [ 444 | { 445 | "name": "stdout", 446 | "output_type": "stream", 447 | "text": [ 448 | "\n", 449 | "\n", 450 | "\u001b[1m> Entering new chain...\u001b[0m\n" 451 | ] 452 | }, 453 | { 454 | "name": "stdout", 455 | "output_type": "stream", 456 | "text": [ 457 | "\u001b[32;1m\u001b[1;3mI need to find the stock ticker symbol for Bajaj Finance and gather stock data, financial statements, and recent news to analyze its investment potential.\n", 458 | "Action: DuckDuckGo Search\n", 459 | "Action Input: Bajaj Finance NSE/BSE stock ticker\u001b[0m\n", 460 | "Observation: \u001b[33;1m\u001b[1;3mBajaj Finance Limited Share Price Today, Live NSE Stock Price: Get the latest Bajaj Finance Limited news, company updates, quotes, offers, annual financial reports, graph, volumes, 52 week high low, buy sell tips, balance sheet, historical charts, market performance, capitalisation, dividends, volume, profit and loss account, research, results and more details at NSE India. Housing Development Finance Corporation ₹2,724.30 0.00 (0.00%) Bajaj Holdings & Investment ₹7,400.90 -142.60 (-1.89%) Bajaj Finserv ₹1,587.60 -10.70 (0.67%) HDFC Asset Management Company... In this regard, the Company has sent a detailed communication to all the Shareholders holding shares as on Friday, 9 June 2023 whose email addresses are registered with the Company/Depositories... Bajaj Finance Ltd. Share Price Today NSE BSE | StockEdge. Home. Stocks. Bajaj Finance Ltd. Share Price. View in App. NSE. BSE. 7296.45 -3.85 -0.1% 01 August 2023, 10:30:59 AM. Volume: 144,325. 7,320 7,310 7,300 7,290 09:30 10 AM 10:30. 1D Low : 7282.00. 1D High : 7330.00. 1W. 1M. 3M. 6M. 1Y. 2Y. 5Y. Company Profile. View details >> F&O. Aug 02, 2023 03:59 PM. Bajaj Finance Ltd. SECTOR : Finance | BSE :500034 | NSE : BAJFINANCE. 10:00 14:00 7148.00 7172.00 7196.00 7220.00 7244.00 7268.00 7292.00 1W 1M 3M 1Y 5Y Max . 7,203.45. -66.25 (-0.91 %) BUY SELL SEP. Company details. Day Low. Day High. 7,145.00. 7,290.00. 52W Low. 52W High. 5,485.70. 7,999.90. 6M Return 23.83%\u001b[0m\n", 461 | "Thought:\u001b[32;1m\u001b[1;3mI have found the stock ticker symbol for Bajaj Finance, which is BAJFINANCE. Now I need to gather stock data, financial statements, and recent news to analyze its investment potential.\n", 462 | "Action: get stock data\n", 463 | "Action Input: BAJFINANCE\u001b[0m\n", 464 | "Observation: \u001b[36;1m\u001b[1;3m Close Volume\n", 465 | "Date \n", 466 | "2023-07-31 7300.299805 749315\n", 467 | "2023-08-01 7269.700195 752765\n", 468 | "2023-08-02 7203.450195 898536\n", 469 | "2023-08-03 7108.350098 1081898\n", 470 | "2023-08-04 7148.700195 731349\u001b[0m\n", 471 | "Thought:\u001b[32;1m\u001b[1;3mI have gathered the stock data for Bajaj Finance. Now I need to gather financial statements and recent news to further analyze its investment potential.\n", 472 | "Action: get financial statements\n", 473 | "Action Input: BAJFINANCE\u001b[0m\n", 474 | "Observation: \u001b[36;1m\u001b[1;3m 2023-03-31 2022-03-31 2021-03-31 2020-03-31\n", 475 | "Ordinary Shares Number 605918538.0 605429233.0 602587339.0 601689069.0\n", 476 | "Share Issued 605918538.0 605429233.0 602587339.0 601689069.0\n", 477 | "Net Debt 1677204100000.0 1286471600000.0 1035838600000.0 1069521000000.0\n", 478 | "Total Debt 1720249300000.0 1328883000000.0 1061857600000.0 1087303000000.0\n", 479 | "Tangible Book Value 536756900000.0 432581000000.0 366004100000.0 321039000000.0\n", 480 | "Invested Capital 2263969100000.0 1761459300000.0 1427603600000.0 1407069100000.0\n", 481 | "Net Tangible Assets 536756900000.0 432581000000.0 366004100000.0 321039000000.0\n", 482 | "Common Stock Equity 543719800000.0 437126900000.0 369184100000.0 323276300000.0\n", 483 | "Total Capitalization 2263969100000.0 1761459300000.0 1427603600000.0 1407069100000.0\n", 484 | "Total Equity Gross Minority Interest 543719800000.0 437126900000.0 369184100000.0 323276300000.0\n", 485 | "Stockholders Equity 543719800000.0 437126900000.0 369184100000.0 323276300000.0\n", 486 | "Other Equity Interest 542510900000.0 3971300000.0 3032500000.0 2131700000.0\n", 487 | "Retained Earnings 272200600000.0 192519900000.0 142428400000.0 107529100000.0\n", 488 | "Additional Paid In Capital 174409800000.0 172177700000.0 169784500000.0 168414300000.0\n", 489 | "Capital Stock 1208900000.0 1210900000.0 1203200000.0 1199900000.0\n", 490 | "Common Stock 1208900000.0 1210900000.0 1203200000.0 1199900000.0\n", 491 | "Total Liabilities Net Minority Interest 2208566900000.0 1687926700000.0 1346084600000.0 1320637400000.0\n", 492 | "Derivative Product Liabilities 40100000.0 1400200000.0 1378700000.0 NaN\n", 493 | "Long Term Debt And Capital Lease Obligation 1720249300000.0 1328883000000.0 1061857600000.0 1087303000000.0\n", 494 | "Payables 22306500000.0 16554900000.0 12909300000.0 10238000000.0\n", 495 | "Other Payable 6393200000.0 3843200000.0 2138200000.0 1978400000.0\n", 496 | "Dividends Payable 22500000.0 17900000.0 20800000.0 48200000.0\n", 497 | "Total Tax Payable 1392100000.0 1000600000.0 1801700000.0 591700000.0\n", 498 | "Accounts Payable 14521200000.0 11693200000.0 8948600000.0 7619700000.0\n", 499 | "Total Assets 2752286700000.0 2125053600000.0 1715268700000.0 1643913700000.0\n", 500 | "Investments And Advances 237203600000.0 50265600000.0 187786400000.0 179342600000.0\n", 501 | "Investmentin Financial Assets 237203600000.0 50265600000.0 187786400000.0 179342600000.0\n", 502 | "Available For Sale Securities 235714800000.0 34413100000.0 54869400000.0 33237500000.0\n", 503 | "Financial Assets Designatedas Fair Value Through Profitor Loss Total 65236300000.0 14633500000.0 132917000000.0 144387500000.0\n", 504 | "Long Term Equity Investment 944000000.0 NaN NaN NaN\n", 505 | "Investmentsin Associatesat Cost 944000000.0 NaN NaN NaN\n", 506 | "Goodwill And Other Intangible Assets 6962900000.0 4545900000.0 3180000000.0 2237300000.0\n", 507 | "Other Intangible Assets 6930200000.0 4513200000.0 3147300000.0 2204600000.0\n", 508 | "Goodwill 32700000.0 32700000.0 32700000.0 32700000.0\n", 509 | "Net PPE 16911700000.0 12958500000.0 10487600000.0 10972600000.0\n", 510 | "Accumulated Depreciation -11294900000.0 -9037100000.0 -7180000000.0 -5428900000.0\n", 511 | "Gross PPE 16911700000.0 21995600000.0 17667600000.0 16401500000.0\n", 512 | "Construction In Progress 146000000.0 132700000.0 70700000.0 NaN\n", 513 | "Other Properties 16765700000.0 1432000000.0 1002500000.0 851500000.0\n", 514 | "Machinery Furniture Equipment 9247100000.0 7662100000.0 7040700000.0 6825100000.0\n", 515 | "Buildings And Improvements 13323100000.0 10802900000.0 8499000000.0 7716200000.0\n", 516 | "Land And Improvements 2719100000.0 1965900000.0 1054700000.0 1008700000.0\n", 517 | "Prepaid Assets 3414700000.0 2503700000.0 1888100000.0 2546100000.0\n", 518 | "Receivables 12997200000.0 14987400000.0 11072400000.0 9524900000.0\n", 519 | "Taxes Receivable 1814300000.0 1683000000.0 1940200000.0 2449700000.0\n", 520 | "Cash And Cash Equivalents 43045200000.0 37860800000.0 22580900000.0 14271800000.0\n", 521 | "Cash Financial 590700000.0 537200000.0 568400000.0 271200000.0\u001b[0m\n", 522 | "Thought:" 523 | ] 524 | }, 525 | { 526 | "name": "stderr", 527 | "output_type": "stream", 528 | "text": [ 529 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 530 | ] 531 | }, 532 | { 533 | "name": "stdout", 534 | "output_type": "stream", 535 | "text": [ 536 | "\u001b[32;1m\u001b[1;3mI have gathered the necessary data for Bajaj Finance. Now I can analyze its investment potential.\n", 537 | "Action: get recent news\n", 538 | "Action Input: Bajaj Finance\u001b[0m\n", 539 | "Observation: \u001b[38;5;200m\u001b[1;3mRecent News:\n", 540 | "\n", 541 | "0. Bajaj Finance share price Today Live Updates : Bajaj Finance closed today \n", 542 | "at ₹7145.05, up 0.52% from yesterday's ₹7107.95 | Mint\n", 543 | "1. Recos Updates: Motilal Oswal Financial Services Recommends Bajaj Finance \n", 544 | "with 23.46% Upside Potential\n", 545 | "\u001b[0m\n", 546 | "Thought:" 547 | ] 548 | }, 549 | { 550 | "name": "stderr", 551 | "output_type": "stream", 552 | "text": [ 553 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 554 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 555 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 556 | ] 557 | }, 558 | { 559 | "name": "stdout", 560 | "output_type": "stream", 561 | "text": [ 562 | "\u001b[32;1m\u001b[1;3mBased on the gathered data, I can now provide a detailed analysis of Bajaj Finance as an investment choice.\n", 563 | "\n", 564 | "Bajaj Finance (NSE: BAJFINANCE) is a finance company listed on the National Stock Exchange of India. The stock has shown a recent upward trend, with a closing price of ₹7,145.05, up 0.52% from the previous day's closing price of ₹7,107.95. The stock has a 52-week low of ₹5,485.70 and a 52-week high of ₹7,999.90.\n", 565 | "\n", 566 | "In terms of financial performance, Bajaj Finance has shown consistent growth in its net tangible assets, common stock equity, and total equity over the past four years. The company's net debt has also increased over the same period, indicating a higher level of leverage. However, Bajaj Finance has a strong capitalization and invested capital, which suggests a solid financial position.\n", 567 | "\n", 568 | "Recent news about Bajaj Finance includes a recommendation from Motilal Oswal Financial Services, which suggests a 23.46% upside potential for the stock.\n", 569 | "\n", 570 | "Based on the analysis of the stock data, financial statements, and recent news, Bajaj Finance appears to be a good investment choice. The stock has shown positive price performance and the company has demonstrated consistent growth in key financial metrics. However, investors should consider the potential risks associated with the company's leverage and the overall market conditions before making an investment decision.\n", 571 | "\n", 572 | "Final Answer: Bajaj Finance is a good investment choice right now based on the analysis of stock data, financial statements, and recent news.\u001b[0m\n", 573 | "\n", 574 | "\u001b[1m> Finished chain.\u001b[0m\n" 575 | ] 576 | }, 577 | { 578 | "data": { 579 | "text/plain": [ 580 | "{'input': 'Is Bajaj Finance a good investment choice right now?',\n", 581 | " 'output': 'Bajaj Finance is a good investment choice right now based on the analysis of stock data, financial statements, and recent news.',\n", 582 | " 'intermediate_steps': [(AgentAction(tool='DuckDuckGo Search', tool_input='Bajaj Finance NSE/BSE stock ticker', log='I need to find the stock ticker symbol for Bajaj Finance and gather stock data, financial statements, and recent news to analyze its investment potential.\\nAction: DuckDuckGo Search\\nAction Input: Bajaj Finance NSE/BSE stock ticker'),\n", 583 | " 'Bajaj Finance Limited Share Price Today, Live NSE Stock Price: Get the latest Bajaj Finance Limited news, company updates, quotes, offers, annual financial reports, graph, volumes, 52 week high low, buy sell tips, balance sheet, historical charts, market performance, capitalisation, dividends, volume, profit and loss account, research, results and more details at NSE India. Housing Development Finance Corporation ₹2,724.30 0.00 (0.00%) Bajaj Holdings & Investment ₹7,400.90 -142.60 (-1.89%) Bajaj Finserv ₹1,587.60 -10.70 (0.67%) HDFC Asset Management Company... In this regard, the Company has sent a detailed communication to all the Shareholders holding shares as on Friday, 9 June 2023 whose email addresses are registered with the Company/Depositories... Bajaj Finance Ltd. Share Price Today NSE BSE | StockEdge. Home. Stocks. Bajaj Finance Ltd. Share Price. View in App. NSE. BSE. 7296.45 -3.85 -0.1% 01 August 2023, 10:30:59 AM. Volume: 144,325. 7,320 7,310 7,300 7,290 09:30 10 AM 10:30. 1D Low : 7282.00. 1D High : 7330.00. 1W. 1M. 3M. 6M. 1Y. 2Y. 5Y. Company Profile. View details >> F&O. Aug 02, 2023 03:59 PM. Bajaj Finance Ltd. SECTOR : Finance | BSE :500034 | NSE : BAJFINANCE. 10:00 14:00 7148.00 7172.00 7196.00 7220.00 7244.00 7268.00 7292.00 1W 1M 3M 1Y 5Y Max . 7,203.45. -66.25 (-0.91 %) BUY SELL SEP. Company details. Day Low. Day High. 7,145.00. 7,290.00. 52W Low. 52W High. 5,485.70. 7,999.90. 6M Return 23.83%'),\n", 584 | " (AgentAction(tool='get stock data', tool_input='BAJFINANCE', log='I have found the stock ticker symbol for Bajaj Finance, which is BAJFINANCE. Now I need to gather stock data, financial statements, and recent news to analyze its investment potential.\\nAction: get stock data\\nAction Input: BAJFINANCE'),\n", 585 | " ' Close Volume\\nDate \\n2023-07-31 7300.299805 749315\\n2023-08-01 7269.700195 752765\\n2023-08-02 7203.450195 898536\\n2023-08-03 7108.350098 1081898\\n2023-08-04 7148.700195 731349'),\n", 586 | " (AgentAction(tool='get financial statements', tool_input='BAJFINANCE', log='I have gathered the stock data for Bajaj Finance. Now I need to gather financial statements and recent news to further analyze its investment potential.\\nAction: get financial statements\\nAction Input: BAJFINANCE'),\n", 587 | " ' 2023-03-31 2022-03-31 2021-03-31 2020-03-31\\nOrdinary Shares Number 605918538.0 605429233.0 602587339.0 601689069.0\\nShare Issued 605918538.0 605429233.0 602587339.0 601689069.0\\nNet Debt 1677204100000.0 1286471600000.0 1035838600000.0 1069521000000.0\\nTotal Debt 1720249300000.0 1328883000000.0 1061857600000.0 1087303000000.0\\nTangible Book Value 536756900000.0 432581000000.0 366004100000.0 321039000000.0\\nInvested Capital 2263969100000.0 1761459300000.0 1427603600000.0 1407069100000.0\\nNet Tangible Assets 536756900000.0 432581000000.0 366004100000.0 321039000000.0\\nCommon Stock Equity 543719800000.0 437126900000.0 369184100000.0 323276300000.0\\nTotal Capitalization 2263969100000.0 1761459300000.0 1427603600000.0 1407069100000.0\\nTotal Equity Gross Minority Interest 543719800000.0 437126900000.0 369184100000.0 323276300000.0\\nStockholders Equity 543719800000.0 437126900000.0 369184100000.0 323276300000.0\\nOther Equity Interest 542510900000.0 3971300000.0 3032500000.0 2131700000.0\\nRetained Earnings 272200600000.0 192519900000.0 142428400000.0 107529100000.0\\nAdditional Paid In Capital 174409800000.0 172177700000.0 169784500000.0 168414300000.0\\nCapital Stock 1208900000.0 1210900000.0 1203200000.0 1199900000.0\\nCommon Stock 1208900000.0 1210900000.0 1203200000.0 1199900000.0\\nTotal Liabilities Net Minority Interest 2208566900000.0 1687926700000.0 1346084600000.0 1320637400000.0\\nDerivative Product Liabilities 40100000.0 1400200000.0 1378700000.0 NaN\\nLong Term Debt And Capital Lease Obligation 1720249300000.0 1328883000000.0 1061857600000.0 1087303000000.0\\nPayables 22306500000.0 16554900000.0 12909300000.0 10238000000.0\\nOther Payable 6393200000.0 3843200000.0 2138200000.0 1978400000.0\\nDividends Payable 22500000.0 17900000.0 20800000.0 48200000.0\\nTotal Tax Payable 1392100000.0 1000600000.0 1801700000.0 591700000.0\\nAccounts Payable 14521200000.0 11693200000.0 8948600000.0 7619700000.0\\nTotal Assets 2752286700000.0 2125053600000.0 1715268700000.0 1643913700000.0\\nInvestments And Advances 237203600000.0 50265600000.0 187786400000.0 179342600000.0\\nInvestmentin Financial Assets 237203600000.0 50265600000.0 187786400000.0 179342600000.0\\nAvailable For Sale Securities 235714800000.0 34413100000.0 54869400000.0 33237500000.0\\nFinancial Assets Designatedas Fair Value Through Profitor Loss Total 65236300000.0 14633500000.0 132917000000.0 144387500000.0\\nLong Term Equity Investment 944000000.0 NaN NaN NaN\\nInvestmentsin Associatesat Cost 944000000.0 NaN NaN NaN\\nGoodwill And Other Intangible Assets 6962900000.0 4545900000.0 3180000000.0 2237300000.0\\nOther Intangible Assets 6930200000.0 4513200000.0 3147300000.0 2204600000.0\\nGoodwill 32700000.0 32700000.0 32700000.0 32700000.0\\nNet PPE 16911700000.0 12958500000.0 10487600000.0 10972600000.0\\nAccumulated Depreciation -11294900000.0 -9037100000.0 -7180000000.0 -5428900000.0\\nGross PPE 16911700000.0 21995600000.0 17667600000.0 16401500000.0\\nConstruction In Progress 146000000.0 132700000.0 70700000.0 NaN\\nOther Properties 16765700000.0 1432000000.0 1002500000.0 851500000.0\\nMachinery Furniture Equipment 9247100000.0 7662100000.0 7040700000.0 6825100000.0\\nBuildings And Improvements 13323100000.0 10802900000.0 8499000000.0 7716200000.0\\nLand And Improvements 2719100000.0 1965900000.0 1054700000.0 1008700000.0\\nPrepaid Assets 3414700000.0 2503700000.0 1888100000.0 2546100000.0\\nReceivables 12997200000.0 14987400000.0 11072400000.0 9524900000.0\\nTaxes Receivable 1814300000.0 1683000000.0 1940200000.0 2449700000.0\\nCash And Cash Equivalents 43045200000.0 37860800000.0 22580900000.0 14271800000.0\\nCash Financial 590700000.0 537200000.0 568400000.0 271200000.0'),\n", 588 | " (AgentAction(tool='get recent news', tool_input='Bajaj Finance', log='I have gathered the necessary data for Bajaj Finance. Now I can analyze its investment potential.\\nAction: get recent news\\nAction Input: Bajaj Finance'),\n", 589 | " \"Recent News:\\n\\n0. Bajaj Finance share price Today Live Updates : Bajaj Finance closed today \\nat ₹7145.05, up 0.52% from yesterday's ₹7107.95 | Mint\\n1. Recos Updates: Motilal Oswal Financial Services Recommends Bajaj Finance \\nwith 23.46% Upside Potential\\n\")]}" 590 | ] 591 | }, 592 | "execution_count": 78, 593 | "metadata": {}, 594 | "output_type": "execute_result" 595 | } 596 | ], 597 | "source": [ 598 | "zero_shot_agent(\"Is Bajaj Finance a good investment choice right now?\")" 599 | ] 600 | }, 601 | { 602 | "cell_type": "code", 603 | "execution_count": 84, 604 | "metadata": {}, 605 | "outputs": [ 606 | { 607 | "name": "stdout", 608 | "output_type": "stream", 609 | "text": [ 610 | "\n", 611 | "\n", 612 | "\u001b[1m> Entering new chain...\u001b[0m\n", 613 | "\u001b[32;1m\u001b[1;3mI need to find the stock ticker symbol for Asian Paints and gather stock data, financial statements, and recent news to analyze the stock.\n", 614 | "Action: DuckDuckGo Search\n", 615 | "Action Input: \"Asian Paints NSE/BSE stock ticker\"\u001b[0m\n", 616 | "Observation: \u001b[33;1m\u001b[1;3mAsian Paints Limited Share Price Today, Live NSE Stock Price: Get the latest Asian Paints Limited news, company updates, quotes, offers, annual financial reports, graph, volumes, 52 week high low, buy sell tips, balance sheet, historical charts, market performance, capitalisation, dividends, volume, profit and loss account, research, results and more details at NSE India. Asian Paints Share Price Today (02 Aug, 2023) - Asian Paints Share Price Live NSE/BSE Business News › Markets › Stocks › Stock Price Quotes › Asian Paints Share Price Sector: Building Materi... Industry: Paints/Varnishes Asian Paints Share Price 3,348.10 5.15 (0.15 %) Volume: 5,89,686 Live Last Updated On: 02 Aug, 2023, 02:22 PM IST Asian Paints Ltd Share Price Today, ASIANPAINT Share Price NSE, BSE Sign In News Markets Stocks Asian Paints Ltd Asian Paints Ltd (ASIANPAINT) Share Price Sector: Paints/Varnish... Asian Paints Share Price: Find the latest news on Asian Paints Stock Price. Get all the information on Asian Paints with historic price charts for NSE / BSE. Experts & Broker view also get the ... See the latest Asian Paints Ltd stock price (XNSE:ASIANPAINT), related news, valuation, dividends and more to help you make your investing decisions.\u001b[0m\n", 617 | "Thought:\u001b[32;1m\u001b[1;3mI have found the stock ticker symbol for Asian Paints, which is ASIANPAINT.\n", 618 | "Action: get stock data\n", 619 | "Action Input: ASIANPAINT\u001b[0m\n", 620 | "Observation: \u001b[36;1m\u001b[1;3m Close Volume\n", 621 | "Date \n", 622 | "2023-07-31 3377.350098 933890\n", 623 | "2023-08-01 3342.949951 698667\n", 624 | "2023-08-02 3362.899902 857218\n", 625 | "2023-08-03 3336.350098 711067\n", 626 | "2023-08-04 3339.649902 519248\u001b[0m\n", 627 | "Thought:\u001b[32;1m\u001b[1;3mI have gathered the stock data for Asian Paints.\n", 628 | "Action: get financial statements\n", 629 | "Action Input: ASIANPAINT\u001b[0m\n", 630 | "Observation: \u001b[36;1m\u001b[1;3m 2023-03-31 2022-03-31 2021-03-31 2020-03-31\n", 631 | "Treasury Shares Number 357659.0 223240.0 NaN NaN\n", 632 | "Ordinary Shares Number 958840131.0 958974550.0 959197790.0 959197790.0\n", 633 | "Share Issued 958840131.0 959197790.0 959197790.0 959197790.0\n", 634 | "Net Debt 4491100000.0 1539000000.0 21500000.0 NaN\n", 635 | "Total Debt 19326200000.0 15868400000.0 10930800000.0 11182400000.0\n", 636 | "Tangible Book Value 155763400000.0 133827100000.0 122696700000.0 95427000000.0\n", 637 | "Invested Capital 169644400000.0 145871800000.0 131548300000.0 104845900000.0\n", 638 | "Working Capital 86392300000.0 75813400000.0 61007400000.0 31997300000.0\n", 639 | "Net Tangible Assets 155763400000.0 133827100000.0 122696700000.0 95427000000.0\n", 640 | "Capital Lease Obligations 9604100000.0 8112200000.0 7445400000.0 7638100000.0\n", 641 | "Common Stock Equity 159922300000.0 138115600000.0 128062900000.0 101301600000.0\n", 642 | "Total Capitalization 160683800000.0 138561000000.0 128207800000.0 101486600000.0\n", 643 | "Total Equity Gross Minority Interest 164458900000.0 141990900000.0 132291500000.0 105336900000.0\n", 644 | "Minority Interest 4536600000.0 3875300000.0 4228600000.0 4035300000.0\n", 645 | "Stockholders Equity 159922300000.0 138115600000.0 128062900000.0 101301600000.0\n", 646 | "Other Equity Interest 158963100000.0 134000000.0 NaN NaN\n", 647 | "Treasury Stock 1108900000.0 750000000.0 NaN NaN\n", 648 | "Retained Earnings 113668400000.0 91859500000.0 78740200000.0 52046400000.0\n", 649 | "Additional Paid In Capital 53700000.0 53700000.0 53700000.0 53700000.0\n", 650 | "Capital Stock 959200000.0 959200000.0 959200000.0 959200000.0\n", 651 | "Common Stock 959200000.0 959200000.0 959200000.0 959200000.0\n", 652 | "Total Liabilities Net Minority Interest 93521100000.0 87853600000.0 71404700000.0 56210800000.0\n", 653 | "Total Non Current Liabilities Net Minority Interest 14561800000.0 12143700000.0 12146100000.0 12407000000.0\n", 654 | "Other Non Current Liabilities 391700000.0 21100000.0 7100000.0 NaN\n", 655 | "Derivative Product Liabilities 61200000.0 0.0 NaN NaN\n", 656 | "Non Current Pension And Other Postretirement Benefit Plans 2293100000.0 NaN 2152100000.0 1807500000.0\n", 657 | "Tradeand Other Payables Non Current 179200000.0 12900000.0 26200000.0 16100000.0\n", 658 | "Non Current Deferred Revenue 400500000.0 30000000.0 46300000.0 61000000.0\n", 659 | "Non Current Deferred Taxes Liabilities 3348400000.0 3488500000.0 4155900000.0 4438000000.0\n", 660 | "Long Term Debt And Capital Lease Obligation 8050900000.0 6429100000.0 5758500000.0 6084400000.0\n", 661 | "Long Term Capital Lease Obligation 7289400000.0 5983700000.0 5613600000.0 5899400000.0\n", 662 | "Long Term Debt 761500000.0 445400000.0 144900000.0 185000000.0\n", 663 | "Long Term Provisions 2307000000.0 2183200000.0 2152100000.0 NaN\n", 664 | "Current Liabilities 78959300000.0 75709900000.0 59258600000.0 43803800000.0\n", 665 | "Other Current Liabilities 4590400000.0 28700000.0 5800000.0 1300000.0\n", 666 | "Current Deferred Taxes Liabilities 1636900000.0 1301200000.0 1212300000.0 1800500000.0\n", 667 | "Current Debt And Capital Lease Obligation 11275300000.0 9439300000.0 5172300000.0 5098000000.0\n", 668 | "Current Capital Lease Obligation 2314700000.0 2128500000.0 1831800000.0 1738700000.0\n", 669 | "Current Debt 8960600000.0 7310800000.0 3340500000.0 3359300000.0\n", 670 | "Pensionand Other Post Retirement Benefit Plans Current 729800000.0 NaN NaN NaN\n", 671 | "Current Provisions 742100000.0 697000000.0 844300000.0 624600000.0\n", 672 | "Payables 37991300000.0 63453900000.0 51594200000.0 35784300000.0\n", 673 | "Other Payable 26653600000.0 21339900000.0 17349100000.0 13829500000.0\n", 674 | "Dividends Payable 239900000.0 246600000.0 266700000.0 224700000.0\n", 675 | "Total Tax Payable 1636900000.0 1301200000.0 1212300000.0 NaN\n", 676 | "Accounts Payable 36354400000.0 41867400000.0 33978400000.0 21730100000.0\n", 677 | "Total Assets 257980000000.0 229844500000.0 203696200000.0 161547700000.0\n", 678 | "Total Non Current Assets 92628400000.0 78321200000.0 83430200000.0 85746600000.0\n", 679 | "Other Non Current Assets 3345400000.0 1328700000.0 683800000.0 NaN\n", 680 | "Non Current Prepaid Assets 5731500000.0 3656700000.0 2817200000.0 3862300000.0\n", 681 | "Non Current Deferred Taxes Assets 186700000.0 260200000.0 142800000.0 168000000.0\n", 682 | "Financial Assets 0.0 0.0 NaN NaN\n", 683 | "Investmentin Financial Assets 11461600000.0 5513600000.0 9857800000.0 10497400000.0\n", 684 | "Held To Maturity Securities 8300000.0 6700000.0 8300000.0 11500000.0\n", 685 | "Available For Sale Securities 11461600000.0 5496200000.0 6597700000.0 6279300000.0\n", 686 | "Financial Assets Designatedas Fair Value Through Profitor Loss Total 19200000.0 10700000.0 3251800000.0 4206600000.0\n", 687 | "Long Term Equity Investment 7817300000.0 5154700000.0 4839000000.0 4566300000.0\n", 688 | "Investmentsin Associatesat Cost 7817300000.0 5154700000.0 4839000000.0 4566300000.0\n", 689 | "Goodwill And Other Intangible Assets 4158900000.0 4288500000.0 5366200000.0 5874600000.0\n", 690 | "Other Intangible Assets 1874100000.0 1859900000.0 2339900000.0 2674700000.0\n", 691 | "Goodwill 2284800000.0 2428600000.0 3026300000.0 3199900000.0\n", 692 | "Net PPE 63741600000.0 55166400000.0 55048800000.0 58250900000.0\n", 693 | "Accumulated Depreciation -33361300000.0 -28124000000.0 -22960000000.0 -18029300000.0\n", 694 | "Gross PPE 63741600000.0 83290400000.0 78008800000.0 76280200000.0\n", 695 | "Construction In Progress 10195900000.0 4264300000.0 1829800000.0 1402400000.0\n", 696 | "Other Properties 53545700000.0 769900000.0 769200000.0 744300000.0\n", 697 | "Machinery Furniture Equipment 51244500000.0 47846700000.0 45770600000.0 44444400000.0\n", 698 | "Buildings And Improvements 26881000000.0 23964600000.0 23197600000.0 23284600000.0\n", 699 | "Land And Improvements 7987100000.0 6444900000.0 6441600000.0 6404500000.0\n", 700 | "Properties 0.0 0.0 0.0 0.0\n", 701 | "Current Assets 165351600000.0 151523300000.0 120266000000.0 75801100000.0\n", 702 | "Other Current Assets 5539800000.0 5412500000.0 4500000.0 NaN\n", 703 | "Hedging Assets Current 23400000.0 0.0 8800000.0 NaN\n", 704 | "Assets Held For Sale Current 0.0 81300000.0 134900000.0 138600000.0\n", 705 | "Restricted Cash 567900000.0 558000000.0 428900000.0 2221500000.0\n", 706 | "Prepaid Assets 2418000000.0 3294200000.0 3963000000.0 1427400000.0\n", 707 | "Inventory 62106400000.0 61529800000.0 37986000000.0 33898100000.0\n", 708 | "Finished Goods 36113300000.0 32933100000.0 20299000000.0 19774900000.0\n", 709 | "Work In Process 1871100000.0 1950200000.0 1334600000.0 934200000.0\n", 710 | "Raw Materials 24122000000.0 26646500000.0 16352400000.0 13189000000.0\n", 711 | "Other Receivables 7545600000.0 7094400000.0 4090100000.0 4749100000.0\n", 712 | "Taxes Receivable NaN NaN 11800000.0 17000000.0\n", 713 | "Accounts Receivable 46369400000.0 38714500000.0 26038000000.0 17952200000.0\n", 714 | "Allowance For Doubtful Accounts Receivable -3051300000.0 -2389500000.0 -1853100000.0 -1551200000.0\n", 715 | "Gross Accounts Receivable 49428700000.0 41104000000.0 27891100000.0 19503400000.0\n", 716 | "Cash Cash Equivalents And Short Term Investments 51336000000.0 40251100000.0 47609100000.0 15411600000.0\n", 717 | "Other Short Term Investments 46105000000.0 34033900000.0 44145200000.0 9773300000.0\n", 718 | "Cash And Cash Equivalents 5231000000.0 6217200000.0 3463900000.0 5638300000.0\n", 719 | "Cash Equivalents 583800000.0 627100000.0 260600000.0 243200000.0\n", 720 | "Cash Financial 4647200000.0 5590100000.0 3203300000.0 5395100000.0\u001b[0m\n", 721 | "Thought:" 722 | ] 723 | }, 724 | { 725 | "name": "stderr", 726 | "output_type": "stream", 727 | "text": [ 728 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 729 | ] 730 | }, 731 | { 732 | "name": "stdout", 733 | "output_type": "stream", 734 | "text": [ 735 | "\u001b[32;1m\u001b[1;3mI have gathered the necessary data for Asian Paints. Now I can analyze the stock and provide a detailed analysis for investment choice.\n", 736 | "Action: Analyze the stock based on gathered data\u001b[0m\n", 737 | "Observation: Invalid Format: Missing 'Action Input:' after 'Action:'\n", 738 | "Thought:" 739 | ] 740 | }, 741 | { 742 | "name": "stderr", 743 | "output_type": "stream", 744 | "text": [ 745 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 746 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 747 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 748 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 749 | ] 750 | }, 751 | { 752 | "name": "stdout", 753 | "output_type": "stream", 754 | "text": [ 755 | "\u001b[32;1m\u001b[1;3mI need to provide the action input for analyzing the stock based on the gathered data.\n", 756 | "Action: Analyze the stock based on gathered data\n", 757 | "Action Input: ASIANPAINT\u001b[0m\n", 758 | "Observation: Analyze the stock based on gathered data is not a valid tool, try another one.\n", 759 | "Thought:" 760 | ] 761 | }, 762 | { 763 | "name": "stderr", 764 | "output_type": "stream", 765 | "text": [ 766 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 767 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 768 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 769 | ] 770 | }, 771 | { 772 | "name": "stdout", 773 | "output_type": "stream", 774 | "text": [ 775 | "\u001b[32;1m\u001b[1;3mI need to use a different tool to analyze the stock based on the gathered data.\n", 776 | "Action: get recent news\n", 777 | "Action Input: ASIANPAINT\u001b[0m\n", 778 | "Observation: \u001b[38;5;200m\u001b[1;3mRecent News:\n", 779 | "\n", 780 | "0. Asian Paint share price Today Live Updates : Asian Paint closed today at \n", 781 | "₹3339.9, up 0.13% from yesterday's ₹3335.55 | Mint\n", 782 | "1. Asian Paint share price Today Live Updates : Asian Paint closed today at \n", 783 | "₹3335.55, down -0.82% from yesterday's ₹3363.25 | Mint\n", 784 | "\u001b[0m\n", 785 | "Thought:" 786 | ] 787 | }, 788 | { 789 | "name": "stderr", 790 | "output_type": "stream", 791 | "text": [ 792 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 793 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 794 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 795 | ] 796 | }, 797 | { 798 | "name": "stdout", 799 | "output_type": "stream", 800 | "text": [ 801 | "\u001b[32;1m\u001b[1;3mI have gathered recent news about Asian Paints. Now I can analyze the stock and provide a detailed analysis for investment choice.\n", 802 | "Action: Analyze the stock based on gathered data\n", 803 | "Action Input: ASIANPAINT\u001b[0m\n", 804 | "Observation: Analyze the stock based on gathered data is not a valid tool, try another one.\n", 805 | "Thought:" 806 | ] 807 | }, 808 | { 809 | "name": "stderr", 810 | "output_type": "stream", 811 | "text": [ 812 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 813 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 814 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 815 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 8.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 816 | ] 817 | }, 818 | { 819 | "name": "stdout", 820 | "output_type": "stream", 821 | "text": [ 822 | "\u001b[32;1m\u001b[1;3mI need to use a different tool to analyze the stock based on the gathered data.\n", 823 | "Action: get financial statements\n", 824 | "Action Input: ASIANPAINT\u001b[0m\n", 825 | "Observation: \u001b[36;1m\u001b[1;3m 2023-03-31 2022-03-31 2021-03-31 2020-03-31\n", 826 | "Treasury Shares Number 357659.0 223240.0 NaN NaN\n", 827 | "Ordinary Shares Number 958840131.0 958974550.0 959197790.0 959197790.0\n", 828 | "Share Issued 958840131.0 959197790.0 959197790.0 959197790.0\n", 829 | "Net Debt 4491100000.0 1539000000.0 21500000.0 NaN\n", 830 | "Total Debt 19326200000.0 15868400000.0 10930800000.0 11182400000.0\n", 831 | "Tangible Book Value 155763400000.0 133827100000.0 122696700000.0 95427000000.0\n", 832 | "Invested Capital 169644400000.0 145871800000.0 131548300000.0 104845900000.0\n", 833 | "Working Capital 86392300000.0 75813400000.0 61007400000.0 31997300000.0\n", 834 | "Net Tangible Assets 155763400000.0 133827100000.0 122696700000.0 95427000000.0\n", 835 | "Capital Lease Obligations 9604100000.0 8112200000.0 7445400000.0 7638100000.0\n", 836 | "Common Stock Equity 159922300000.0 138115600000.0 128062900000.0 101301600000.0\n", 837 | "Total Capitalization 160683800000.0 138561000000.0 128207800000.0 101486600000.0\n", 838 | "Total Equity Gross Minority Interest 164458900000.0 141990900000.0 132291500000.0 105336900000.0\n", 839 | "Minority Interest 4536600000.0 3875300000.0 4228600000.0 4035300000.0\n", 840 | "Stockholders Equity 159922300000.0 138115600000.0 128062900000.0 101301600000.0\n", 841 | "Other Equity Interest 158963100000.0 134000000.0 NaN NaN\n", 842 | "Treasury Stock 1108900000.0 750000000.0 NaN NaN\n", 843 | "Retained Earnings 113668400000.0 91859500000.0 78740200000.0 52046400000.0\n", 844 | "Additional Paid In Capital 53700000.0 53700000.0 53700000.0 53700000.0\n", 845 | "Capital Stock 959200000.0 959200000.0 959200000.0 959200000.0\n", 846 | "Common Stock 959200000.0 959200000.0 959200000.0 959200000.0\n", 847 | "Total Liabilities Net Minority Interest 93521100000.0 87853600000.0 71404700000.0 56210800000.0\n", 848 | "Total Non Current Liabilities Net Minority Interest 14561800000.0 12143700000.0 12146100000.0 12407000000.0\n", 849 | "Other Non Current Liabilities 391700000.0 21100000.0 7100000.0 NaN\n", 850 | "Derivative Product Liabilities 61200000.0 0.0 NaN NaN\n", 851 | "Non Current Pension And Other Postretirement Benefit Plans 2293100000.0 NaN 2152100000.0 1807500000.0\n", 852 | "Tradeand Other Payables Non Current 179200000.0 12900000.0 26200000.0 16100000.0\n", 853 | "Non Current Deferred Revenue 400500000.0 30000000.0 46300000.0 61000000.0\n", 854 | "Non Current Deferred Taxes Liabilities 3348400000.0 3488500000.0 4155900000.0 4438000000.0\n", 855 | "Long Term Debt And Capital Lease Obligation 8050900000.0 6429100000.0 5758500000.0 6084400000.0\n", 856 | "Long Term Capital Lease Obligation 7289400000.0 5983700000.0 5613600000.0 5899400000.0\n", 857 | "Long Term Debt 761500000.0 445400000.0 144900000.0 185000000.0\n", 858 | "Long Term Provisions 2307000000.0 2183200000.0 2152100000.0 NaN\n", 859 | "Current Liabilities 78959300000.0 75709900000.0 59258600000.0 43803800000.0\n", 860 | "Other Current Liabilities 4590400000.0 28700000.0 5800000.0 1300000.0\n", 861 | "Current Deferred Taxes Liabilities 1636900000.0 1301200000.0 1212300000.0 1800500000.0\n", 862 | "Current Debt And Capital Lease Obligation 11275300000.0 9439300000.0 5172300000.0 5098000000.0\n", 863 | "Current Capital Lease Obligation 2314700000.0 2128500000.0 1831800000.0 1738700000.0\n", 864 | "Current Debt 8960600000.0 7310800000.0 3340500000.0 3359300000.0\n", 865 | "Pensionand Other Post Retirement Benefit Plans Current 729800000.0 NaN NaN NaN\n", 866 | "Current Provisions 742100000.0 697000000.0 844300000.0 624600000.0\n", 867 | "Payables 37991300000.0 63453900000.0 51594200000.0 35784300000.0\n", 868 | "Other Payable 26653600000.0 21339900000.0 17349100000.0 13829500000.0\n", 869 | "Dividends Payable 239900000.0 246600000.0 266700000.0 224700000.0\n", 870 | "Total Tax Payable 1636900000.0 1301200000.0 1212300000.0 NaN\n", 871 | "Accounts Payable 36354400000.0 41867400000.0 33978400000.0 21730100000.0\n", 872 | "Total Assets 257980000000.0 229844500000.0 203696200000.0 161547700000.0\n", 873 | "Total Non Current Assets 92628400000.0 78321200000.0 83430200000.0 85746600000.0\n", 874 | "Other Non Current Assets 3345400000.0 1328700000.0 683800000.0 NaN\n", 875 | "Non Current Prepaid Assets 5731500000.0 3656700000.0 2817200000.0 3862300000.0\n", 876 | "Non Current Deferred Taxes Assets 186700000.0 260200000.0 142800000.0 168000000.0\n", 877 | "Financial Assets 0.0 0.0 NaN NaN\n", 878 | "Investmentin Financial Assets 11461600000.0 5513600000.0 9857800000.0 10497400000.0\n", 879 | "Held To Maturity Securities 8300000.0 6700000.0 8300000.0 11500000.0\n", 880 | "Available For Sale Securities 11461600000.0 5496200000.0 6597700000.0 6279300000.0\n", 881 | "Financial Assets Designatedas Fair Value Through Profitor Loss Total 19200000.0 10700000.0 3251800000.0 4206600000.0\n", 882 | "Long Term Equity Investment 7817300000.0 5154700000.0 4839000000.0 4566300000.0\n", 883 | "Investmentsin Associatesat Cost 7817300000.0 5154700000.0 4839000000.0 4566300000.0\n", 884 | "Goodwill And Other Intangible Assets 4158900000.0 4288500000.0 5366200000.0 5874600000.0\n", 885 | "Other Intangible Assets 1874100000.0 1859900000.0 2339900000.0 2674700000.0\n", 886 | "Goodwill 2284800000.0 2428600000.0 3026300000.0 3199900000.0\n", 887 | "Net PPE 63741600000.0 55166400000.0 55048800000.0 58250900000.0\n", 888 | "Accumulated Depreciation -33361300000.0 -28124000000.0 -22960000000.0 -18029300000.0\n", 889 | "Gross PPE 63741600000.0 83290400000.0 78008800000.0 76280200000.0\n", 890 | "Construction In Progress 10195900000.0 4264300000.0 1829800000.0 1402400000.0\n", 891 | "Other Properties 53545700000.0 769900000.0 769200000.0 744300000.0\n", 892 | "Machinery Furniture Equipment 51244500000.0 47846700000.0 45770600000.0 44444400000.0\n", 893 | "Buildings And Improvements 26881000000.0 23964600000.0 23197600000.0 23284600000.0\n", 894 | "Land And Improvements 7987100000.0 6444900000.0 6441600000.0 6404500000.0\n", 895 | "Properties 0.0 0.0 0.0 0.0\n", 896 | "Current Assets 165351600000.0 151523300000.0 120266000000.0 75801100000.0\n", 897 | "Other Current Assets 5539800000.0 5412500000.0 4500000.0 NaN\n", 898 | "Hedging Assets Current 23400000.0 0.0 8800000.0 NaN\n", 899 | "Assets Held For Sale Current 0.0 81300000.0 134900000.0 138600000.0\n", 900 | "Restricted Cash 567900000.0 558000000.0 428900000.0 2221500000.0\n", 901 | "Prepaid Assets 2418000000.0 3294200000.0 3963000000.0 1427400000.0\n", 902 | "Inventory 62106400000.0 61529800000.0 37986000000.0 33898100000.0\n", 903 | "Finished Goods 36113300000.0 32933100000.0 20299000000.0 19774900000.0\n", 904 | "Work In Process 1871100000.0 1950200000.0 1334600000.0 934200000.0\n", 905 | "Raw Materials 24122000000.0 26646500000.0 16352400000.0 13189000000.0\n", 906 | "Other Receivables 7545600000.0 7094400000.0 4090100000.0 4749100000.0\n", 907 | "Taxes Receivable NaN NaN 11800000.0 17000000.0\n", 908 | "Accounts Receivable 46369400000.0 38714500000.0 26038000000.0 17952200000.0\n", 909 | "Allowance For Doubtful Accounts Receivable -3051300000.0 -2389500000.0 -1853100000.0 -1551200000.0\n", 910 | "Gross Accounts Receivable 49428700000.0 41104000000.0 27891100000.0 19503400000.0\n", 911 | "Cash Cash Equivalents And Short Term Investments 51336000000.0 40251100000.0 47609100000.0 15411600000.0\n", 912 | "Other Short Term Investments 46105000000.0 34033900000.0 44145200000.0 9773300000.0\n", 913 | "Cash And Cash Equivalents 5231000000.0 6217200000.0 3463900000.0 5638300000.0\n", 914 | "Cash Equivalents 583800000.0 627100000.0 260600000.0 243200000.0\n", 915 | "Cash Financial 4647200000.0 5590100000.0 3203300000.0 5395100000.0\u001b[0m\n", 916 | "Thought:" 917 | ] 918 | }, 919 | { 920 | "name": "stderr", 921 | "output_type": "stream", 922 | "text": [ 923 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 924 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 925 | ] 926 | }, 927 | { 928 | "name": "stdout", 929 | "output_type": "stream", 930 | "text": [ 931 | "\u001b[32;1m\u001b[1;3mI have gathered the necessary data for Asian Paints. Now I can analyze the stock and provide a detailed analysis for investment choice.\n", 932 | "Action: Analyze the stock based on gathered data\n", 933 | "Action Input: Stock data, financial statements, recent news\u001b[0m\n", 934 | "Observation: Analyze the stock based on gathered data is not a valid tool, try another one.\n", 935 | "Thought:" 936 | ] 937 | }, 938 | { 939 | "name": "stderr", 940 | "output_type": "stream", 941 | "text": [ 942 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 943 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n", 944 | "Retrying langchain.llms.openai.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for default-gpt-3.5-turbo-16k in organization org-ee1LP900po9H9JaxPmhhwDap on requests per min. Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method..\n" 945 | ] 946 | }, 947 | { 948 | "ename": "KeyboardInterrupt", 949 | "evalue": "", 950 | "output_type": "error", 951 | "traceback": [ 952 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 953 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 954 | "Cell \u001b[0;32mIn[84], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m response \u001b[39m=\u001b[39m zero_shot_agent({\u001b[39m\"\u001b[39;49m\u001b[39minput\u001b[39;49m\u001b[39m\"\u001b[39;49m:\u001b[39m\"\u001b[39;49m\u001b[39mShall I invest in Asian paints?\u001b[39;49m\u001b[39m\"\u001b[39;49m})\n", 955 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/chains/base.py:243\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)\u001b[0m\n\u001b[1;32m 241\u001b[0m \u001b[39mexcept\u001b[39;00m (\u001b[39mKeyboardInterrupt\u001b[39;00m, \u001b[39mException\u001b[39;00m) \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 242\u001b[0m run_manager\u001b[39m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 243\u001b[0m \u001b[39mraise\u001b[39;00m e\n\u001b[1;32m 244\u001b[0m run_manager\u001b[39m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m 245\u001b[0m final_outputs: Dict[\u001b[39mstr\u001b[39m, Any] \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprep_outputs(\n\u001b[1;32m 246\u001b[0m inputs, outputs, return_only_outputs\n\u001b[1;32m 247\u001b[0m )\n", 956 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/chains/base.py:237\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)\u001b[0m\n\u001b[1;32m 231\u001b[0m run_manager \u001b[39m=\u001b[39m callback_manager\u001b[39m.\u001b[39mon_chain_start(\n\u001b[1;32m 232\u001b[0m dumpd(\u001b[39mself\u001b[39m),\n\u001b[1;32m 233\u001b[0m inputs,\n\u001b[1;32m 234\u001b[0m )\n\u001b[1;32m 235\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 236\u001b[0m outputs \u001b[39m=\u001b[39m (\n\u001b[0;32m--> 237\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_call(inputs, run_manager\u001b[39m=\u001b[39;49mrun_manager)\n\u001b[1;32m 238\u001b[0m \u001b[39mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 239\u001b[0m \u001b[39melse\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_call(inputs)\n\u001b[1;32m 240\u001b[0m )\n\u001b[1;32m 241\u001b[0m \u001b[39mexcept\u001b[39;00m (\u001b[39mKeyboardInterrupt\u001b[39;00m, \u001b[39mException\u001b[39;00m) \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 242\u001b[0m run_manager\u001b[39m.\u001b[39mon_chain_error(e)\n", 957 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/agents/agent.py:987\u001b[0m, in \u001b[0;36mAgentExecutor._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m 985\u001b[0m \u001b[39m# We now enter the agent loop (until it returns something).\u001b[39;00m\n\u001b[1;32m 986\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_should_continue(iterations, time_elapsed):\n\u001b[0;32m--> 987\u001b[0m next_step_output \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_take_next_step(\n\u001b[1;32m 988\u001b[0m name_to_tool_map,\n\u001b[1;32m 989\u001b[0m color_mapping,\n\u001b[1;32m 990\u001b[0m inputs,\n\u001b[1;32m 991\u001b[0m intermediate_steps,\n\u001b[1;32m 992\u001b[0m run_manager\u001b[39m=\u001b[39;49mrun_manager,\n\u001b[1;32m 993\u001b[0m )\n\u001b[1;32m 994\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(next_step_output, AgentFinish):\n\u001b[1;32m 995\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_return(\n\u001b[1;32m 996\u001b[0m next_step_output, intermediate_steps, run_manager\u001b[39m=\u001b[39mrun_manager\n\u001b[1;32m 997\u001b[0m )\n", 958 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/agents/agent.py:792\u001b[0m, in \u001b[0;36mAgentExecutor._take_next_step\u001b[0;34m(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)\u001b[0m\n\u001b[1;32m 786\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Take a single step in the thought-action-observation loop.\u001b[39;00m\n\u001b[1;32m 787\u001b[0m \n\u001b[1;32m 788\u001b[0m \u001b[39mOverride this to take control of how the agent makes and acts on choices.\u001b[39;00m\n\u001b[1;32m 789\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 790\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 791\u001b[0m \u001b[39m# Call the LLM to see what to do.\u001b[39;00m\n\u001b[0;32m--> 792\u001b[0m output \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49magent\u001b[39m.\u001b[39;49mplan(\n\u001b[1;32m 793\u001b[0m intermediate_steps,\n\u001b[1;32m 794\u001b[0m callbacks\u001b[39m=\u001b[39;49mrun_manager\u001b[39m.\u001b[39;49mget_child() \u001b[39mif\u001b[39;49;00m run_manager \u001b[39melse\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m,\n\u001b[1;32m 795\u001b[0m \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49minputs,\n\u001b[1;32m 796\u001b[0m )\n\u001b[1;32m 797\u001b[0m \u001b[39mexcept\u001b[39;00m OutputParserException \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 798\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhandle_parsing_errors, \u001b[39mbool\u001b[39m):\n", 959 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/agents/agent.py:443\u001b[0m, in \u001b[0;36mAgent.plan\u001b[0;34m(self, intermediate_steps, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 431\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Given input, decided what to do.\u001b[39;00m\n\u001b[1;32m 432\u001b[0m \n\u001b[1;32m 433\u001b[0m \u001b[39mArgs:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 440\u001b[0m \u001b[39m Action specifying what tool to use.\u001b[39;00m\n\u001b[1;32m 441\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 442\u001b[0m full_inputs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mget_full_inputs(intermediate_steps, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m--> 443\u001b[0m full_output \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mllm_chain\u001b[39m.\u001b[39;49mpredict(callbacks\u001b[39m=\u001b[39;49mcallbacks, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mfull_inputs)\n\u001b[1;32m 444\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39moutput_parser\u001b[39m.\u001b[39mparse(full_output)\n", 960 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/chains/llm.py:252\u001b[0m, in \u001b[0;36mLLMChain.predict\u001b[0;34m(self, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 237\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mpredict\u001b[39m(\u001b[39mself\u001b[39m, callbacks: Callbacks \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mstr\u001b[39m:\n\u001b[1;32m 238\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Format prompt with kwargs and pass to LLM.\u001b[39;00m\n\u001b[1;32m 239\u001b[0m \n\u001b[1;32m 240\u001b[0m \u001b[39m Args:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 250\u001b[0m \u001b[39m completion = llm.predict(adjective=\"funny\")\u001b[39;00m\n\u001b[1;32m 251\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 252\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m(kwargs, callbacks\u001b[39m=\u001b[39;49mcallbacks)[\u001b[39mself\u001b[39m\u001b[39m.\u001b[39moutput_key]\n", 961 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/chains/base.py:243\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)\u001b[0m\n\u001b[1;32m 241\u001b[0m \u001b[39mexcept\u001b[39;00m (\u001b[39mKeyboardInterrupt\u001b[39;00m, \u001b[39mException\u001b[39;00m) \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 242\u001b[0m run_manager\u001b[39m.\u001b[39mon_chain_error(e)\n\u001b[0;32m--> 243\u001b[0m \u001b[39mraise\u001b[39;00m e\n\u001b[1;32m 244\u001b[0m run_manager\u001b[39m.\u001b[39mon_chain_end(outputs)\n\u001b[1;32m 245\u001b[0m final_outputs: Dict[\u001b[39mstr\u001b[39m, Any] \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprep_outputs(\n\u001b[1;32m 246\u001b[0m inputs, outputs, return_only_outputs\n\u001b[1;32m 247\u001b[0m )\n", 962 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/chains/base.py:237\u001b[0m, in \u001b[0;36mChain.__call__\u001b[0;34m(self, inputs, return_only_outputs, callbacks, tags, metadata, include_run_info)\u001b[0m\n\u001b[1;32m 231\u001b[0m run_manager \u001b[39m=\u001b[39m callback_manager\u001b[39m.\u001b[39mon_chain_start(\n\u001b[1;32m 232\u001b[0m dumpd(\u001b[39mself\u001b[39m),\n\u001b[1;32m 233\u001b[0m inputs,\n\u001b[1;32m 234\u001b[0m )\n\u001b[1;32m 235\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 236\u001b[0m outputs \u001b[39m=\u001b[39m (\n\u001b[0;32m--> 237\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_call(inputs, run_manager\u001b[39m=\u001b[39;49mrun_manager)\n\u001b[1;32m 238\u001b[0m \u001b[39mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 239\u001b[0m \u001b[39melse\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_call(inputs)\n\u001b[1;32m 240\u001b[0m )\n\u001b[1;32m 241\u001b[0m \u001b[39mexcept\u001b[39;00m (\u001b[39mKeyboardInterrupt\u001b[39;00m, \u001b[39mException\u001b[39;00m) \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 242\u001b[0m run_manager\u001b[39m.\u001b[39mon_chain_error(e)\n", 963 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/chains/llm.py:92\u001b[0m, in \u001b[0;36mLLMChain._call\u001b[0;34m(self, inputs, run_manager)\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_call\u001b[39m(\n\u001b[1;32m 88\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 89\u001b[0m inputs: Dict[\u001b[39mstr\u001b[39m, Any],\n\u001b[1;32m 90\u001b[0m run_manager: Optional[CallbackManagerForChainRun] \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m,\n\u001b[1;32m 91\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Dict[\u001b[39mstr\u001b[39m, \u001b[39mstr\u001b[39m]:\n\u001b[0;32m---> 92\u001b[0m response \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgenerate([inputs], run_manager\u001b[39m=\u001b[39;49mrun_manager)\n\u001b[1;32m 93\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcreate_outputs(response)[\u001b[39m0\u001b[39m]\n", 964 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/chains/llm.py:102\u001b[0m, in \u001b[0;36mLLMChain.generate\u001b[0;34m(self, input_list, run_manager)\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Generate LLM result from inputs.\"\"\"\u001b[39;00m\n\u001b[1;32m 101\u001b[0m prompts, stop \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mprep_prompts(input_list, run_manager\u001b[39m=\u001b[39mrun_manager)\n\u001b[0;32m--> 102\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mllm\u001b[39m.\u001b[39;49mgenerate_prompt(\n\u001b[1;32m 103\u001b[0m prompts,\n\u001b[1;32m 104\u001b[0m stop,\n\u001b[1;32m 105\u001b[0m callbacks\u001b[39m=\u001b[39;49mrun_manager\u001b[39m.\u001b[39;49mget_child() \u001b[39mif\u001b[39;49;00m run_manager \u001b[39melse\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m,\n\u001b[1;32m 106\u001b[0m \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mllm_kwargs,\n\u001b[1;32m 107\u001b[0m )\n", 965 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/llms/base.py:186\u001b[0m, in \u001b[0;36mBaseLLM.generate_prompt\u001b[0;34m(self, prompts, stop, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 178\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mgenerate_prompt\u001b[39m(\n\u001b[1;32m 179\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 180\u001b[0m prompts: List[PromptValue],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 183\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any,\n\u001b[1;32m 184\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m LLMResult:\n\u001b[1;32m 185\u001b[0m prompt_strings \u001b[39m=\u001b[39m [p\u001b[39m.\u001b[39mto_string() \u001b[39mfor\u001b[39;00m p \u001b[39min\u001b[39;00m prompts]\n\u001b[0;32m--> 186\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mgenerate(prompt_strings, stop\u001b[39m=\u001b[39;49mstop, callbacks\u001b[39m=\u001b[39;49mcallbacks, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n", 966 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/llms/base.py:279\u001b[0m, in \u001b[0;36mBaseLLM.generate\u001b[0;34m(self, prompts, stop, callbacks, tags, metadata, **kwargs)\u001b[0m\n\u001b[1;32m 273\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 274\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mAsked to cache, but no cache found at `langchain.cache`.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 275\u001b[0m )\n\u001b[1;32m 276\u001b[0m run_managers \u001b[39m=\u001b[39m callback_manager\u001b[39m.\u001b[39mon_llm_start(\n\u001b[1;32m 277\u001b[0m dumpd(\u001b[39mself\u001b[39m), prompts, invocation_params\u001b[39m=\u001b[39mparams, options\u001b[39m=\u001b[39moptions\n\u001b[1;32m 278\u001b[0m )\n\u001b[0;32m--> 279\u001b[0m output \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_generate_helper(\n\u001b[1;32m 280\u001b[0m prompts, stop, run_managers, \u001b[39mbool\u001b[39;49m(new_arg_supported), \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs\n\u001b[1;32m 281\u001b[0m )\n\u001b[1;32m 282\u001b[0m \u001b[39mreturn\u001b[39;00m output\n\u001b[1;32m 283\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39m(missing_prompts) \u001b[39m>\u001b[39m \u001b[39m0\u001b[39m:\n", 967 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/llms/base.py:223\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m 221\u001b[0m \u001b[39mfor\u001b[39;00m run_manager \u001b[39min\u001b[39;00m run_managers:\n\u001b[1;32m 222\u001b[0m run_manager\u001b[39m.\u001b[39mon_llm_error(e)\n\u001b[0;32m--> 223\u001b[0m \u001b[39mraise\u001b[39;00m e\n\u001b[1;32m 224\u001b[0m flattened_outputs \u001b[39m=\u001b[39m output\u001b[39m.\u001b[39mflatten()\n\u001b[1;32m 225\u001b[0m \u001b[39mfor\u001b[39;00m manager, flattened_output \u001b[39min\u001b[39;00m \u001b[39mzip\u001b[39m(run_managers, flattened_outputs):\n", 968 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/llms/base.py:210\u001b[0m, in \u001b[0;36mBaseLLM._generate_helper\u001b[0;34m(self, prompts, stop, run_managers, new_arg_supported, **kwargs)\u001b[0m\n\u001b[1;32m 200\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_generate_helper\u001b[39m(\n\u001b[1;32m 201\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 202\u001b[0m prompts: List[\u001b[39mstr\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 206\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any,\n\u001b[1;32m 207\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m LLMResult:\n\u001b[1;32m 208\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m 209\u001b[0m output \u001b[39m=\u001b[39m (\n\u001b[0;32m--> 210\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_generate(\n\u001b[1;32m 211\u001b[0m prompts,\n\u001b[1;32m 212\u001b[0m stop\u001b[39m=\u001b[39;49mstop,\n\u001b[1;32m 213\u001b[0m \u001b[39m# TODO: support multiple run managers\u001b[39;49;00m\n\u001b[1;32m 214\u001b[0m run_manager\u001b[39m=\u001b[39;49mrun_managers[\u001b[39m0\u001b[39;49m] \u001b[39mif\u001b[39;49;00m run_managers \u001b[39melse\u001b[39;49;00m \u001b[39mNone\u001b[39;49;00m,\n\u001b[1;32m 215\u001b[0m \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs,\n\u001b[1;32m 216\u001b[0m )\n\u001b[1;32m 217\u001b[0m \u001b[39mif\u001b[39;00m new_arg_supported\n\u001b[1;32m 218\u001b[0m \u001b[39melse\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_generate(prompts, stop\u001b[39m=\u001b[39mstop)\n\u001b[1;32m 219\u001b[0m )\n\u001b[1;32m 220\u001b[0m \u001b[39mexcept\u001b[39;00m (\u001b[39mKeyboardInterrupt\u001b[39;00m, \u001b[39mException\u001b[39;00m) \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m 221\u001b[0m \u001b[39mfor\u001b[39;00m run_manager \u001b[39min\u001b[39;00m run_managers:\n", 969 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/llms/openai.py:806\u001b[0m, in \u001b[0;36mOpenAIChat._generate\u001b[0;34m(self, prompts, stop, run_manager, **kwargs)\u001b[0m\n\u001b[1;32m 802\u001b[0m \u001b[39mreturn\u001b[39;00m LLMResult(\n\u001b[1;32m 803\u001b[0m generations\u001b[39m=\u001b[39m[[Generation(text\u001b[39m=\u001b[39mresponse)]],\n\u001b[1;32m 804\u001b[0m )\n\u001b[1;32m 805\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 806\u001b[0m full_response \u001b[39m=\u001b[39m completion_with_retry(\u001b[39mself\u001b[39;49m, messages\u001b[39m=\u001b[39;49mmessages, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mparams)\n\u001b[1;32m 807\u001b[0m llm_output \u001b[39m=\u001b[39m {\n\u001b[1;32m 808\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mtoken_usage\u001b[39m\u001b[39m\"\u001b[39m: full_response[\u001b[39m\"\u001b[39m\u001b[39musage\u001b[39m\u001b[39m\"\u001b[39m],\n\u001b[1;32m 809\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmodel_name\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmodel_name,\n\u001b[1;32m 810\u001b[0m }\n\u001b[1;32m 811\u001b[0m \u001b[39mreturn\u001b[39;00m LLMResult(\n\u001b[1;32m 812\u001b[0m generations\u001b[39m=\u001b[39m[\n\u001b[1;32m 813\u001b[0m [Generation(text\u001b[39m=\u001b[39mfull_response[\u001b[39m\"\u001b[39m\u001b[39mchoices\u001b[39m\u001b[39m\"\u001b[39m][\u001b[39m0\u001b[39m][\u001b[39m\"\u001b[39m\u001b[39mmessage\u001b[39m\u001b[39m\"\u001b[39m][\u001b[39m\"\u001b[39m\u001b[39mcontent\u001b[39m\u001b[39m\"\u001b[39m])]\n\u001b[1;32m 814\u001b[0m ],\n\u001b[1;32m 815\u001b[0m llm_output\u001b[39m=\u001b[39mllm_output,\n\u001b[1;32m 816\u001b[0m )\n", 970 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/langchain/llms/openai.py:90\u001b[0m, in \u001b[0;36mcompletion_with_retry\u001b[0;34m(llm, **kwargs)\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[39m@retry_decorator\u001b[39m\n\u001b[1;32m 87\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_completion_with_retry\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs: Any) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Any:\n\u001b[1;32m 88\u001b[0m \u001b[39mreturn\u001b[39;00m llm\u001b[39m.\u001b[39mclient\u001b[39m.\u001b[39mcreate(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m---> 90\u001b[0m \u001b[39mreturn\u001b[39;00m _completion_with_retry(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n", 971 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/tenacity/__init__.py:289\u001b[0m, in \u001b[0;36mBaseRetrying.wraps..wrapped_f\u001b[0;34m(*args, **kw)\u001b[0m\n\u001b[1;32m 287\u001b[0m \u001b[39m@functools\u001b[39m\u001b[39m.\u001b[39mwraps(f)\n\u001b[1;32m 288\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mwrapped_f\u001b[39m(\u001b[39m*\u001b[39margs: t\u001b[39m.\u001b[39mAny, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkw: t\u001b[39m.\u001b[39mAny) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m t\u001b[39m.\u001b[39mAny:\n\u001b[0;32m--> 289\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m(f, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkw)\n", 972 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/tenacity/__init__.py:389\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m 387\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(do, DoSleep):\n\u001b[1;32m 388\u001b[0m retry_state\u001b[39m.\u001b[39mprepare_for_next_attempt()\n\u001b[0;32m--> 389\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msleep(do)\n\u001b[1;32m 390\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 391\u001b[0m \u001b[39mreturn\u001b[39;00m do\n", 973 | "File \u001b[0;32m/mnt/e/Random Projects/wsl_env/lib/python3.10/site-packages/tenacity/nap.py:31\u001b[0m, in \u001b[0;36msleep\u001b[0;34m(seconds)\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39msleep\u001b[39m(seconds: \u001b[39mfloat\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 26\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \u001b[39m Sleep strategy that delays execution for a given number of seconds.\u001b[39;00m\n\u001b[1;32m 28\u001b[0m \n\u001b[1;32m 29\u001b[0m \u001b[39m This is the default strategy, and may be mocked out for unit testing.\u001b[39;00m\n\u001b[1;32m 30\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 31\u001b[0m time\u001b[39m.\u001b[39;49msleep(seconds)\n", 974 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: " 975 | ] 976 | } 977 | ], 978 | "source": [ 979 | "response = zero_shot_agent({\"input\":\"Shall I invest in Asian paints?\"})" 980 | ] 981 | }, 982 | { 983 | "cell_type": "code", 984 | "execution_count": null, 985 | "metadata": {}, 986 | "outputs": [], 987 | "source": [ 988 | "# The why this approach did not work is added in the github readme\n", 989 | "# It is recommended to use the approach2 for robust results" 990 | ] 991 | }, 992 | { 993 | "cell_type": "markdown", 994 | "metadata": {}, 995 | "source": [ 996 | "##### Approach 2" 997 | ] 998 | }, 999 | { 1000 | "cell_type": "code", 1001 | "execution_count": 9, 1002 | "metadata": {}, 1003 | "outputs": [], 1004 | "source": [ 1005 | "import openai\n", 1006 | "\n", 1007 | "import os\n", 1008 | "os.environ[\"OPENAI_API_KEY\"] = \"Enter your API key here\"\n", 1009 | "openai.api_key=\"Enter your API key here\"\n" 1010 | ] 1011 | }, 1012 | { 1013 | "cell_type": "code", 1014 | "execution_count": 10, 1015 | "metadata": {}, 1016 | "outputs": [], 1017 | "source": [ 1018 | "from langchain.llms import OpenAI\n", 1019 | "\n", 1020 | "llm=OpenAI(temperature=0,\n", 1021 | " model_name=\"gpt-3.5-turbo-16k-0613\")" 1022 | ] 1023 | }, 1024 | { 1025 | "cell_type": "code", 1026 | "execution_count": 11, 1027 | "metadata": {}, 1028 | "outputs": [ 1029 | { 1030 | "data": { 1031 | "text/plain": [ 1032 | "('Paytm', 'PAYTM')" 1033 | ] 1034 | }, 1035 | "execution_count": 11, 1036 | "metadata": {}, 1037 | "output_type": "execute_result" 1038 | } 1039 | ], 1040 | "source": [ 1041 | "#Openai function calling\n", 1042 | "\n", 1043 | "import json\n", 1044 | "function=[\n", 1045 | " {\n", 1046 | " \"name\": \"get_company_Stock_ticker\",\n", 1047 | " \"description\": \"This will get the indian NSE/BSE stock ticker of the company\",\n", 1048 | " \"parameters\": {\n", 1049 | " \"type\": \"object\",\n", 1050 | " \"properties\": {\n", 1051 | " \"ticker_symbol\": {\n", 1052 | " \"type\": \"string\",\n", 1053 | " \"description\": \"This is the stock symbol of the company.\",\n", 1054 | " },\n", 1055 | "\n", 1056 | " \"company_name\": {\n", 1057 | " \"type\": \"string\",\n", 1058 | " \"description\": \"This is the name of the company given in query\",\n", 1059 | " }\n", 1060 | " },\n", 1061 | " \"required\": [\"company_name\",\"ticker_symbol\"],\n", 1062 | " },\n", 1063 | " }\n", 1064 | "]\n", 1065 | "\n", 1066 | "\n", 1067 | "\n", 1068 | "def get_stock_ticker(query):\n", 1069 | " response = openai.ChatCompletion.create(\n", 1070 | " model=\"gpt-3.5-turbo\",\n", 1071 | " temperature=0,\n", 1072 | " messages=[{\n", 1073 | " \"role\":\"user\",\n", 1074 | " \"content\":f\"Given the user request, what is the comapany name and the company stock ticker ?: {query}?\"\n", 1075 | " }],\n", 1076 | " functions=function,\n", 1077 | " function_call={\"name\": \"get_company_Stock_ticker\"},\n", 1078 | " )\n", 1079 | " message = response[\"choices\"][0][\"message\"]\n", 1080 | " arguments = json.loads(message[\"function_call\"][\"arguments\"])\n", 1081 | " company_name = arguments[\"company_name\"]\n", 1082 | " company_ticker = arguments[\"ticker_symbol\"]\n", 1083 | " return company_name,company_ticker\n", 1084 | "\n", 1085 | "get_stock_ticker(\"How is ths stock of Paytm doing?\")" 1086 | ] 1087 | }, 1088 | { 1089 | "cell_type": "code", 1090 | "execution_count": 12, 1091 | "metadata": {}, 1092 | "outputs": [], 1093 | "source": [ 1094 | "def Anazlyze_stock(query):\n", 1095 | " #agent.run(query) Outputs Company name, Ticker\n", 1096 | " Company_name,ticker=get_stock_ticker(query)\n", 1097 | " print({\"Query\":query,\"Company_name\":Company_name,\"Ticker\":ticker})\n", 1098 | " stock_data=get_stock_price(ticker,history=10)\n", 1099 | " stock_financials=get_financial_statements(ticker)\n", 1100 | " stock_news=get_recent_stock_news(Company_name)\n", 1101 | "\n", 1102 | " # available_information=f\"Stock Price: {stock_data}\\n\\nStock Financials: {stock_financials}\\n\\nStock News: {stock_news}\"\n", 1103 | " available_information=f\"Stock Financials: {stock_financials}\\n\\nStock News: {stock_news}\"\n", 1104 | "\n", 1105 | " print(\"\\n\\nAnalyzing.....\\n\")\n", 1106 | " analysis=llm(f\"Give detail stock analysis, Use the available data and provide investment recommendation. \\\n", 1107 | " The user is fully aware about the investment risk, dont include any kind of warning like 'It is recommended to conduct further research and analysis or consult with a financial advisor before making an investment decision' in the answer \\\n", 1108 | " User question: {query} \\\n", 1109 | " You have the following information available about {Company_name}. Write (5-8) pointwise investment analysis to answer user query, At the end conclude with proper explaination.Try to Give positives and negatives : \\\n", 1110 | " {available_information} \"\n", 1111 | " )\n", 1112 | " print(analysis)\n", 1113 | "\n", 1114 | " return analysis" 1115 | ] 1116 | }, 1117 | { 1118 | "cell_type": "code", 1119 | "execution_count": 57, 1120 | "metadata": {}, 1121 | "outputs": [ 1122 | { 1123 | "name": "stdout", 1124 | "output_type": "stream", 1125 | "text": [ 1126 | "{'Query': 'Shall I invest in Adani power right now?', 'Company_name': 'Adani Power', 'Ticker': 'ADANIPOWER'}\n", 1127 | "\n", 1128 | "\n", 1129 | "Analyzing.....\n", 1130 | "\n", 1131 | "Investment Thesis for Adani Power:\n", 1132 | "\n", 1133 | "1. Strong Financials: Adani Power has shown consistent growth in its financials over the past three years. The company has a positive tangible book value, indicating a strong asset base. Additionally, the company has a high invested capital, which suggests a strong financial position.\n", 1134 | "\n", 1135 | "2. Increasing Stock Price: The stock price of Adani Power has been increasing steadily over the past few days. This indicates positive investor sentiment and potential for further growth in the future.\n", 1136 | "\n", 1137 | "3. Declining Revenues: Adani Power has reported declining revenues in its recent quarterly results. This could be a concern for investors as it may indicate a slowdown in the company's business operations. However, further analysis is required to determine the reasons behind the decline and its potential impact on future performance.\n", 1138 | "\n", 1139 | "4. Positive News Coverage: Adani Power has been in the news recently, with multiple articles highlighting the company's performance and prospects. Positive news coverage can attract more investors and potentially drive up the stock price.\n", 1140 | "\n", 1141 | "5. Power Sector Outlook: The power sector in India is expected to grow in the coming years due to increasing demand for electricity. Adani Power, being a major player in the sector, is well-positioned to benefit from this growth. However, it is important to consider the competitive landscape and regulatory environment of the sector before making an investment decision.\n", 1142 | "\n", 1143 | "Conclusion:\n", 1144 | "\n", 1145 | "Based on the available data, investing in Adani Power right now could be a favorable option. The company has strong financials and a positive stock price trend. However, it is important to conduct further research and analysis to fully understand the reasons behind the declining revenues and assess the potential risks associated with the power sector.\n" 1146 | ] 1147 | } 1148 | ], 1149 | "source": [ 1150 | "\n", 1151 | "out=Anazlyze_stock(\"Shall I invest in Adani power right now?\") \n" 1152 | ] 1153 | }, 1154 | { 1155 | "cell_type": "code", 1156 | "execution_count": 65, 1157 | "metadata": {}, 1158 | "outputs": [ 1159 | { 1160 | "name": "stdout", 1161 | "output_type": "stream", 1162 | "text": [ 1163 | "{'Query': 'Is it a good time to invest in Yes Bank?', 'Company_name': 'Yes Bank', 'Ticker': 'YESBANK'}\n", 1164 | "\n", 1165 | "\n", 1166 | "Analyzing.....\n", 1167 | "\n", 1168 | "Investment Thesis for Yes Bank:\n", 1169 | "\n", 1170 | "1. Financial Performance: Yes Bank has shown improvement in its financials over the past three years. The net debt has increased, indicating higher borrowing, but the tangible book value and common stock equity have also increased, suggesting a stronger financial position.\n", 1171 | "\n", 1172 | "2. Total Capitalization: The total capitalization of Yes Bank has been consistently increasing, indicating a growing investor base and potential for future growth. This can be seen as a positive sign for investors considering investing in the bank.\n", 1173 | "\n", 1174 | "3. Total Assets: Yes Bank's total assets have also been increasing steadily, indicating the bank's ability to attract and manage a larger pool of assets. This growth in assets can contribute to the bank's profitability and potential for future expansion.\n", 1175 | "\n", 1176 | "4. Stock News: Recent news about Yes Bank suggests that the stock has seen a marginal increase in price and has been holding steady. This stability in the stock price can be seen as a positive sign for investors, indicating a potential for future growth.\n", 1177 | "\n", 1178 | "5. Weak Underlying Business: However, it is important to note that there are concerns about the bank's weak underlying business, as indicated by the soft quarter expected in Q1. This may lead to a decline in profitability, which could impact the stock price in the short term.\n", 1179 | "\n", 1180 | "6. Overall Market Conditions: It is also important to consider the overall market conditions and the banking sector as a whole before making an investment decision. Factors such as economic conditions, regulatory changes, and competition can significantly impact the performance of Yes Bank and its stock price.\n", 1181 | "\n", 1182 | "Based on the available data and information, it can be concluded that investing in Yes Bank at this time carries both positive and negative factors. The positive factors include the bank's improving financials, increasing total capitalization, and steady stock price. However, the concerns about the weak underlying business and potential decline in profitability should also be taken into consideration. Therefore, investors should carefully evaluate their risk tolerance and conduct further research and analysis before making an investment decision in Yes Bank.\n" 1183 | ] 1184 | }, 1185 | { 1186 | "data": { 1187 | "text/plain": [ 1188 | "\"Investment Thesis for Yes Bank:\\n\\n1. Financial Performance: Yes Bank has shown improvement in its financials over the past three years. The net debt has increased, indicating higher borrowing, but the tangible book value and common stock equity have also increased, suggesting a stronger financial position.\\n\\n2. Total Capitalization: The total capitalization of Yes Bank has been consistently increasing, indicating a growing investor base and potential for future growth. This can be seen as a positive sign for investors considering investing in the bank.\\n\\n3. Total Assets: Yes Bank's total assets have also been increasing steadily, indicating the bank's ability to attract and manage a larger pool of assets. This growth in assets can contribute to the bank's profitability and potential for future expansion.\\n\\n4. Stock News: Recent news about Yes Bank suggests that the stock has seen a marginal increase in price and has been holding steady. This stability in the stock price can be seen as a positive sign for investors, indicating a potential for future growth.\\n\\n5. Weak Underlying Business: However, it is important to note that there are concerns about the bank's weak underlying business, as indicated by the soft quarter expected in Q1. This may lead to a decline in profitability, which could impact the stock price in the short term.\\n\\n6. Overall Market Conditions: It is also important to consider the overall market conditions and the banking sector as a whole before making an investment decision. Factors such as economic conditions, regulatory changes, and competition can significantly impact the performance of Yes Bank and its stock price.\\n\\nBased on the available data and information, it can be concluded that investing in Yes Bank at this time carries both positive and negative factors. The positive factors include the bank's improving financials, increasing total capitalization, and steady stock price. However, the concerns about the weak underlying business and potential decline in profitability should also be taken into consideration. Therefore, investors should carefully evaluate their risk tolerance and conduct further research and analysis before making an investment decision in Yes Bank.\"" 1189 | ] 1190 | }, 1191 | "execution_count": 65, 1192 | "metadata": {}, 1193 | "output_type": "execute_result" 1194 | } 1195 | ], 1196 | "source": [ 1197 | "Anazlyze_stock(\"Is it a good time to invest in Yes Bank?\") " 1198 | ] 1199 | }, 1200 | { 1201 | "cell_type": "code", 1202 | "execution_count": 13, 1203 | "metadata": {}, 1204 | "outputs": [ 1205 | { 1206 | "name": "stdout", 1207 | "output_type": "stream", 1208 | "text": [ 1209 | "{'Query': 'How vednata share is doing?', 'Company_name': 'Vedanta', 'Ticker': 'VEDL'}\n", 1210 | "\n", 1211 | "\n", 1212 | "Analyzing.....\n", 1213 | "\n", 1214 | "1. The number of ordinary shares for Vedanta has remained relatively stable over the past three years, indicating no significant dilution or increase in share capital.\n", 1215 | "2. Net debt has increased significantly from 250.48 billion in 2021 to 592.56 billion in 2023, indicating a higher level of debt for the company. This could potentially impact the company's financial stability and ability to generate profits.\n", 1216 | "3. Tangible book value has decreased from 588.03 billion in 2021 to 351.91 billion in 2023. This indicates a decrease in the company's tangible assets and could be a cause for concern.\n", 1217 | "4. Working capital has shown a significant improvement from -29.32 billion in 2021 to 28.62 billion in 2022. This indicates that the company has improved its ability to meet short-term obligations and manage its current assets and liabilities.\n", 1218 | "5. Total equity has remained relatively stable over the past three years, indicating a consistent level of shareholder's equity in the company.\n", 1219 | "6. Total liabilities have increased from 1.08281 trillion in 2021 to 1.46929 trillion in 2023, indicating a higher level of debt and obligations for the company.\n", 1220 | "7. Total assets have increased from 1.85697 trillion in 2021 to 1.96356 trillion in 2023, indicating growth in the company's asset base.\n", 1221 | "\n", 1222 | "Based on the available data, here is the investment recommendation for Vedanta:\n", 1223 | "\n", 1224 | "Positive Points:\n", 1225 | "1. The improvement in working capital indicates that the company has better control over its short-term obligations and current assets.\n", 1226 | "2. The increase in total assets indicates growth in the company's asset base, which could potentially lead to higher revenues and profits in the future.\n", 1227 | "\n", 1228 | "Negative Points:\n", 1229 | "1. The significant increase in net debt and total liabilities indicates a higher level of debt for the company, which could impact its financial stability and ability to generate profits.\n", 1230 | "2. The decrease in tangible book value raises concerns about the company's tangible assets and their value.\n", 1231 | "\n", 1232 | "In conclusion, Vedanta's financials show a mixed picture. While there are positive signs such as the improvement in working capital and increase in total assets, the significant increase in net debt and decrease in tangible book value are causes for concern. Investors should carefully evaluate the company's financial health and future prospects before making an investment decision.\n" 1233 | ] 1234 | }, 1235 | { 1236 | "data": { 1237 | "text/plain": [ 1238 | "\"1. The number of ordinary shares for Vedanta has remained relatively stable over the past three years, indicating no significant dilution or increase in share capital.\\n2. Net debt has increased significantly from 250.48 billion in 2021 to 592.56 billion in 2023, indicating a higher level of debt for the company. This could potentially impact the company's financial stability and ability to generate profits.\\n3. Tangible book value has decreased from 588.03 billion in 2021 to 351.91 billion in 2023. This indicates a decrease in the company's tangible assets and could be a cause for concern.\\n4. Working capital has shown a significant improvement from -29.32 billion in 2021 to 28.62 billion in 2022. This indicates that the company has improved its ability to meet short-term obligations and manage its current assets and liabilities.\\n5. Total equity has remained relatively stable over the past three years, indicating a consistent level of shareholder's equity in the company.\\n6. Total liabilities have increased from 1.08281 trillion in 2021 to 1.46929 trillion in 2023, indicating a higher level of debt and obligations for the company.\\n7. Total assets have increased from 1.85697 trillion in 2021 to 1.96356 trillion in 2023, indicating growth in the company's asset base.\\n\\nBased on the available data, here is the investment recommendation for Vedanta:\\n\\nPositive Points:\\n1. The improvement in working capital indicates that the company has better control over its short-term obligations and current assets.\\n2. The increase in total assets indicates growth in the company's asset base, which could potentially lead to higher revenues and profits in the future.\\n\\nNegative Points:\\n1. The significant increase in net debt and total liabilities indicates a higher level of debt for the company, which could impact its financial stability and ability to generate profits.\\n2. The decrease in tangible book value raises concerns about the company's tangible assets and their value.\\n\\nIn conclusion, Vedanta's financials show a mixed picture. While there are positive signs such as the improvement in working capital and increase in total assets, the significant increase in net debt and decrease in tangible book value are causes for concern. Investors should carefully evaluate the company's financial health and future prospects before making an investment decision.\"" 1239 | ] 1240 | }, 1241 | "execution_count": 13, 1242 | "metadata": {}, 1243 | "output_type": "execute_result" 1244 | } 1245 | ], 1246 | "source": [ 1247 | "Anazlyze_stock(\"How vednata share is doing?\") " 1248 | ] 1249 | } 1250 | ], 1251 | "metadata": { 1252 | "kernelspec": { 1253 | "display_name": "wsl_env", 1254 | "language": "python", 1255 | "name": "python3" 1256 | }, 1257 | "language_info": { 1258 | "codemirror_mode": { 1259 | "name": "ipython", 1260 | "version": 3 1261 | }, 1262 | "file_extension": ".py", 1263 | "mimetype": "text/x-python", 1264 | "name": "python", 1265 | "nbconvert_exporter": "python", 1266 | "pygments_lexer": "ipython3", 1267 | "version": "3.10.6" 1268 | }, 1269 | "orig_nbformat": 4 1270 | }, 1271 | "nbformat": 4, 1272 | "nbformat_minor": 2 1273 | } 1274 | --------------------------------------------------------------------------------