Viewing File: /home/ubuntu/codegamaai-test/broker_bot/src/historical_info.py

from src.utils import *
from help_apis.intent_class import *
from help_apis.entity_extraction import *
from stock_apis.get_stock_info import *
from similarity_search.similarity_check import *

def historical_info_scenerio(user_query, user_intent, user_config, key):
        # Provide information on the stock
        previous_intent = user_config["previous_intent"]
        previous_status = user_config["status"]
        relevent_entities = extract_entities(user_query)
        stock_list = relevent_entities["stock"]
        if stock_list != []:
            stock_name = stock_list[0]
        else:
            stock_name = None
        
        if previous_status == "no_entity_given":
            # We are expecting the stock name
            if stock_name != None:
                # response = f"This the the stock information for the stock {stock_name} you are interested in."

                get_ticker = get_stock_ticker(stock_name)
                if get_ticker == "No Symbol Found":
                    response = f"The stock name {stock_name} is not valid. The current process has been cancelled. Please retry with a valid stock name."
                    user_config = {"previous_intent": None, "current_intent": None,"status":0, "previous_question": None,"previous_response": None, "current_stocks": None, "current_quantity": None, "current_stock_value": None, "user_portofolio_info": None}
                    create_config_json(key,user_config)
                    return response
                else:
                    stock_name = get_ticker['name']
                    stock_symbol = get_ticker['symbol']
                    current_stock_information = historical_stock_data(stock_symbol, interval = "1mo")
                    response = current_stock_information
                    # Update config file
                    # user_config["status"] = "stock_name_given"
                    # user_config["previous_intent"] = user_intent
                    # user_config["previous_question"] = user_query
                    # user_config["current_stocks"] = stock_name
                    user_config = {"previous_intent": None,"current_intent": None, "status":0, "previous_question": None,"previous_response": None, "current_stocks": None, "current_quantity": None, "current_stock_value": None, "user_portofolio_info": None}
                    create_config_json(key,user_config)
                    return response
            
            else:
                response = "The stock name is not valid. The process has been cancelled."
                user_config = {"previous_intent": None,"current_intent": None, "status":0, "previous_question": None,"previous_response": None, "current_stocks": None, "current_quantity": None, "current_stock_value": None, "user_portofolio_info": None}
                create_config_json(key,user_config)
            
            return response
Back to Directory File Manager