Skip to content

Commit

Permalink
added perplexity
Browse files Browse the repository at this point in the history
  • Loading branch information
pratham-darooka committed Jun 17, 2024
1 parent 92c8370 commit e4a1491
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
16 changes: 12 additions & 4 deletions app/pages/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from app.utils.trading_period import display_market_status
from app.utils.whats_happening import fetch_and_parse_perplexity_output
from app.db.common import DB
import streamlit as st

Expand Down Expand Up @@ -57,7 +58,14 @@
st.switch_page('pages/stock_info.py')
else:
with stock_info.container():
st.title(f"_Nothing found for..._ **{st.session_state.stock_info_code.upper()}**")
back = st.button("Go Back!", type="primary", use_container_width=True)
if back:
st.switch_page(f'pages/{st.session_state.referrer}.py')
# st.title(f"_Nothing found for..._ **{st.session_state.stock_info_code.upper()}**")
# back = st.button("Go Back!", type="primary", use_container_width=True)
# if back:
# st.switch_page(f'pages/{st.session_state.referrer}.py')
title = st.empty()

with title:
st.title(f"_Asking AI for..._ **{st.session_state.stock_info_code.title()}**")
st.markdown(fetch_and_parse_perplexity_output(st.session_state.stock_info_code)['llm'])
with title:
st.title(f"_AI Response for..._ **{st.session_state.stock_info_code.title()}**")
2 changes: 1 addition & 1 deletion app/pages/stock_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@

with stock_news:
with st.container(border=True):
st.markdown(ic(format_ddg_news_as_markdown(ic(fetch_recent_stock_news(name, symbol)))))
st.markdown(format_ddg_news_as_markdown(fetch_recent_stock_news(name, symbol)))
36 changes: 35 additions & 1 deletion app/utils/whats_happening.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
import json
import requests
from markdownify import markdownify as md
from icecream import ic
import urllib.parse

def check_whats_happening(stock):
print("triggered ai!")


def fetch_and_parse_perplexity_output(query):
url = f'https://unfortunate-sally-maharat-8663b4b4.koyeb.app/search_normal?query={urllib.parse.quote(query)}&pro_mode=true&date_context=Today%20is%20Monday,%2017/06/2024%20and%20the%20time%20is%2001:45%20PM'
response = requests.get(url, stream=True)

response_content = response.content.decode('utf-8')

sources = []
llm_output = ""
relevant = []

for item in response_content.split('\n'):
if item:
output_dict = json.loads(item[5:])
if output_dict['type'] == 'sources':
sources.extend(output_dict['data']['organic'])
elif output_dict['type'] == 'llm':
llm_output += output_dict['text']
ic(llm_output)
elif output_dict['type'] == 'relevant':
relevant.extend(output_dict['data']['followUp'])
elif output_dict['type'] == 'finished':
break
else:
continue
return {'sources': sources, 'llm': md(llm_output), 'relevant': relevant}

if __name__ == "__main__":
check_whats_happening("RELIANCE")
# check_whats_happening("RELIANCE")
print(fetch_and_parse_perplexity_output("what is meow")['llm'])
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ supabase
nsepythonserver
python-dotenv
bs4
streamlit_aggrid
streamlit_aggrid
markdownify

0 comments on commit e4a1491

Please sign in to comment.