from openai import OpenAI from langchain_core.messages import BaseMessage, HumanMessage from langchain_openai import ChatOpenAI from typing import Annotated import operator from typing import Sequence, TypedDict import numpy as np import pandas as pd from dotenv import load_dotenv import os from typing import Annotated import operator from typing import Sequence, TypedDict import matplotlib.pyplot as plt from langchain.schema.output_parser import StrOutputParser from tools import data_analyst #forecasting_expert_arima, forecasting_expert_rf, evaluator, investment_advisor from tools import crypto_sentiment_analysis_util import app_crypto_rf_model as rf import app_crypto_scrape as sa import app_crypto_arima_model as arima import streamlit as st st.set_page_config(page_title="LangChain Agent", layout="wide") load_dotenv() OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] llm = ChatOpenAI(model="gpt-3.5-turbo") #======================== AGENTS ================================== # The agent state is the input to each node in the graph class AgentState(TypedDict): # The annotation tells the graph that new messages will always # be added to the current states messages: Annotated[Sequence[BaseMessage], operator.add] # The 'next' field indicates where to route to next next: str tool=data_analyst.data_analyst_tools() from langchain_core.runnables import RunnableConfig st.title("💬 Krypto") #@st.cache_data #@st.cache_resource #def initialize_session_state(): if "chat_history" not in st.session_state: st.session_state["messages"] = [{"role":"system", "content":""" You are a cryptocurrency investing expert. Answer all questions related to cryptocurrency investment reccommendations. Say I don't know if you don't know. """}] #initialize_session_state() # Streamlit UI elements st.image('crypto_image.png') #st.text("Start by entering the currency.") sideb = st.sidebar with st.sidebar: #st.subheader("This is the LangGraph workflow visualization of this application rendered in real-time.") #st.image(create_graph_image()) title = st.text_input("Start by entering the currency name:") check1 = sideb.button(f"analyze {title}") results=[] if check1: st.write(f"I am now producing analysis for {title}") model = ChatOpenAI(temperature=0.7, api_key=OPENAI_API_KEY) chain= model | StrOutputParser() result=chain.invoke(f"You are a cryptocurrency data analyst.\ Provide correct cryptocurrency ticker from Coingecko website for cryptocurrency: {title}.\ Expected output: ticker.\ Provide it in the following format: >>cryptocurrencyticker>> \ for example: >>BTC>>") print(result) print('ticker',str(result).split(">>")[0]) if len(str(result).split(">>")[1])<10: cryptocurrencyticker=(str(result).split(">>")[1]) else: cryptocurrencyticker=(str(result).split(">>")[0]) cryptocurrency=title print(cryptocurrency,cryptocurrencyticker) print('here') #================== Scrape Current/Historical Price ==================== df=sa.scrape_crypto(cryptocurrency,cryptocurrencyticker) if len(df)>0: print(df.tail) print("Running forecasting models on historical prices") df_with_forecast_rf, accuracy_rf, result_rf=rf.model_run(df) df_with_forecast_arima, accuracy_arima, result_arima=arima.model_run(df) print("done") print(np.round(df['prices'][-1],2)) #--- for llm if accuracy_rf