Skip to content
Snippets Groups Projects
Commit cd257018 authored by David Matthew Antonio's avatar David Matthew Antonio
Browse files

Stuff

parent 75cc9994
No related branches found
No related tags found
No related merge requests found
# from langchain_core.prompts import ChatPromptTemplate
# from langchain_openai import ChatOpenAI
# from langchain_core.messages import HumanMessage, SystemMessage, AIMessage
import config
import interface
import initializer
def main():
if (config.INITIALIZE_ON_RUN):
initializer.run()
gradio_app = interface.initialize()
gradio_app.launch(share = config.GRADIO_PUBLIC)
from controllers import stocks
import multiprocessing as mp
print("Acquiring exchanges")
try:
stocks.retrieve_exchanges()
except:
print("Cannot retrieve exchanges from the API")
exit()
else:
print("Exchange list updated!")
# Due to API Limits, only Philippine stocks are considered
print("Acquiring tickers")
try:
tickers = stocks.retrieve_tickers("PSE")
except:
print("Cannot retrieve tickers from the API")
exit()
else:
print("Ticker list updated!")
print("Acquiring stock data")
processes = [mp.Process(target = stocks.retrieve_eod_historical_data, args = ("PSE", i["Code"])) for i in tickers]
for p in processes:
p.start()
for p in processes:
p.join()
print("Initializing gradio app")
gradio_app = interface.initialize()
gradio_app.launch(share = config.GRADIO_PUBLIC)
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -4,7 +4,6 @@ BASE_DATA_PATH = 'data/'
# Directories must end with a '/'
TICKERS_DIRECTORY = 'tickers/'
STOCKS_DIRECTORY = 'stocks/'
FUSED_DATA_DIRECTORY = 'fused/'
# Files may include its following path and must end with the respective extension
EXCHANGES_FILEPATH = 'exchanges.json'
......@@ -19,8 +18,7 @@ def get_tickers_directory() -> str:
def get_stocks_directory() -> str:
return BASE_DATA_PATH + STOCKS_DIRECTORY
def get_fused_data_directory() -> str:
return BASE_DATA_PATH + FUSED_DATA_DIRECTORY
def get_exchanges_filepath() -> str:
return BASE_DATA_PATH + EXCHANGES_FILEPATH
......
......@@ -3,7 +3,6 @@ from chromadb.config import DEFAULT_TENANT, DEFAULT_DATABASE, Settings
from langchain_core.documents import Document
from langchain_openai import OpenAIEmbeddings
from utility import stock_data_helper
from langchain_text_splitters import RecursiveJsonSplitter
import os
try:
import secret
......@@ -13,6 +12,7 @@ except:
def get_vectordb():
embeddings = OpenAIEmbeddings(model="text-embedding-3-large", api_key = OPENAIKEY)
print("Loading local data")
tickers = stock_data_helper.get_stock_codes("PSE")
stocks = [stock_data_helper.get_stock_data("PSE", i['Code']) for i in tickers]
......@@ -48,7 +48,7 @@ def get_vectordb():
Name: "General/All stocks/tickers/companies in the philippines",
Country: "Philippines"
!HISTORICAL DATA:
{str(stock_data_helper.get_stock_codes)}
{str(stock_data_helper.get_stock_codes("PSE"))}
""",
metadata ={
"Name": "General/All stocks/tickers/companies in the philippines",
......
from controllers import stocks
from utility import stock_data_helper
import multiprocessing as mp
def run():
try:
stocks.retrieve_exchanges()
except:
print("Cannot retrieve exchanges from the API")
exit()
else:
print("Exchange list updated!")
# Due to API Limits, only Philippine stocks are considered
try:
tickers = stocks.retrieve_tickers("PSE")
except:
print("Cannot retrieve tickers from the API")
exit()
else:
print("Ticker list updated!")
tickers = stock_data_helper.get_stock_codes("PSE")
processes = [mp.Process(target = stocks.retrieve_eod_historical_data, args = ("PSE", i["Code"])) for i in tickers]
for p in processes:
p.start()
for p in processes:
p.join()
# try:
# stock_data_helper.create_fused_data("PSE")
# except Exception as exception:
# print(exception)
if __name__ == "__main__":
run()
\ No newline at end of file
import gradio as gr
from controllers import rag, prompt
vector_db = rag.get_vectordb()
vector_db = None
def get_prompt_response(query:str):
if vector_db == None:
vector_db = rag.get_vectordb()
context = vector_db.similarity_search(query,k=10)
ai_message = prompt.send_prompt(query, str(context))
return ai_message.content
......
......@@ -5,10 +5,9 @@ import os
EXCHANGES_FILEPATH = config.get_exchanges_filepath()
TICKERS_DIRECTORY = config.get_tickers_directory()
STOCKS_DIRECTORY = config.get_stocks_directory()
FUSED_DATA_DIRECTORY = config.get_fused_data_directory()
def get_stock_codes(exchange_code:str) -> list[str]:
print("Attempting to load local tickers")
try:
with open(TICKERS_DIRECTORY + f"{exchange_code}.json", 'r') as file:
data = json.load(file)
......@@ -20,7 +19,7 @@ def get_stock_codes(exchange_code:str) -> list[str]:
return data
def get_stock_data(exchange_code:str, stock_code:str):
print("Attempting to load local stock data")
try:
with open(STOCKS_DIRECTORY + f"{exchange_code}/{stock_code}.json", 'r') as file:
data = json.load(file)
......@@ -30,27 +29,3 @@ def get_stock_data(exchange_code:str, stock_code:str):
return data
def get_fused_data(exchange_code:str, stock_code:str):
try:
with open(FUSED_DATA_DIRECTORY + f"{exchange_code}/{stock_code}.json", 'r') as file:
data = json.load(file)
except:
print("File not found")
exit()
return data
def create_fused_data(exchange_code:str):
stock_codes = get_stock_codes(exchange_code)
if not os.path.exists(f"{FUSED_DATA_DIRECTORY}{exchange_code}/"):
os.makedirs(f"{FUSED_DATA_DIRECTORY}{exchange_code}/")
for stock in stock_codes:
stock['data'] = get_stock_data(exchange_code, stock['Code'])
with open(f"{FUSED_DATA_DIRECTORY}{exchange_code}/" + f'{stock['Code']}.json', 'w') as filename:
json.dump(stock_codes, filename)
return stock_codes
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment