Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -434,15 +434,18 @@ def generate_function_call(prompt):
|
|
434 |
return output
|
435 |
|
436 |
|
437 |
-
|
438 |
-
|
|
|
|
|
|
|
439 |
global display_ticker
|
440 |
-
logging.info("Current Value of GLOBAL TICKER: %s",
|
441 |
generate_kwargs = dict(temperature=0.001,max_new_tokens=1024,top_p=0.95,repetition_penalty=1.0,do_sample=True,seed=42)
|
442 |
today = datetime.date.today()
|
443 |
todays_date = today.strftime('%d%B%Y')
|
444 |
question = format_prompt(prompt, history)
|
445 |
-
logging.info("\n\nQuestion: %s",
|
446 |
|
447 |
chat_completion_params = generate_function_call(question)
|
448 |
logging.info(chat_completion_params)
|
@@ -453,25 +456,21 @@ async def generate_final_response(prompt, history, context_files=[], ticker_stat
|
|
453 |
logging.info("Final Ticker: %s", ticker)
|
454 |
|
455 |
try:
|
456 |
-
if (chat_completion_params['todays_news_flag'] or chat_completion_params['generic_query']) and len(ticker)
|
457 |
logging.info("Getting Latest News Headlines")
|
458 |
news_link.append(todays_news())
|
459 |
time.sleep(2)
|
460 |
-
elif chat_completion_params['todays_news_flag'] and len(ticker)
|
461 |
for tick in chat_completion_params["stock_name"]:
|
462 |
news_googles.append(f"Latest News for {tick}\n\n {get_google_news(tick)}")
|
463 |
-
elif (chat_completion_params['follow_up_query'] and ticker_stats) or (display_ticker == ticker and ticker_stats):
|
464 |
logging.info("\n\nAssigned into a followup query\n\n")
|
465 |
chat_completion_params['follow_up_query'] = True
|
466 |
else:
|
467 |
-
logging.info("prompt & ticker: %s, %s", question, ticker)
|
468 |
logging.info("Getting into raw_news()")
|
469 |
for stock in ticker:
|
470 |
-
context_file, ticker_stat, ticker_financial, report, news_google = raw_news(
|
471 |
-
raw_query=question,
|
472 |
-
todays_news_func_call=chat_completion_params["todays_news_flag"],
|
473 |
-
ticker=stock
|
474 |
-
)
|
475 |
# Append each detail to its corresponding list
|
476 |
context_files.append(context_file)
|
477 |
ticker_stats.append(ticker_stat)
|
@@ -479,35 +478,27 @@ async def generate_final_response(prompt, history, context_files=[], ticker_stat
|
|
479 |
reports.append(report)
|
480 |
news_googles.append(news_google)
|
481 |
|
|
|
482 |
logging.info(f"Generating response for **{question}**")
|
483 |
display_ticker = ticker if ticker else [0]
|
484 |
env = Environment(loader=FileSystemLoader("templates/"), autoescape=True)
|
|
|
485 |
template = env.get_template("system_prompt.txt")
|
486 |
-
content = template.render(
|
487 |
-
|
488 |
-
|
489 |
-
response_type="Response-1",
|
490 |
-
chat_completion_params=chat_completion_params,
|
491 |
-
context_file=context_files,
|
492 |
-
question=question,
|
493 |
-
ticker=ticker,
|
494 |
-
ticker_stats=ticker_stats,
|
495 |
-
reports=reports,
|
496 |
-
news_link=news_link,
|
497 |
-
earnings=earning_link,
|
498 |
-
news_googles=news_googles
|
499 |
-
)
|
500 |
try:
|
|
|
501 |
stream = client.text_generation(content, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
502 |
output = ""
|
503 |
for response in stream:
|
504 |
output += response.token.text
|
505 |
yield output
|
506 |
-
|
507 |
except StopAsyncIteration:
|
508 |
yield "Sorry, could you provide more details to clarify your query"
|
509 |
except Exception as e:
|
510 |
yield f"Sorry, your query couldn't be processed. Retry with correct name of stock - An error occurred: {e}"
|
|
|
511 |
|
512 |
theme ="JohnSmith9982/small_and_pretty"
|
513 |
|
|
|
434 |
return output
|
435 |
|
436 |
|
437 |
+
def generate_final_response(prompt, history, context_files=[], ticker_stats=[], reports=[], ticker_financials=[], news_link=[], earning_link=[], news_googles=[]):
|
438 |
+
# temperature = float(temperature)
|
439 |
+
# if temperature < 1e-2:
|
440 |
+
# temperature = 1e-2
|
441 |
+
# top_p = float(top_p)
|
442 |
global display_ticker
|
443 |
+
logging.info("Current Value of GLOBAL TICKER: %s",display_ticker)
|
444 |
generate_kwargs = dict(temperature=0.001,max_new_tokens=1024,top_p=0.95,repetition_penalty=1.0,do_sample=True,seed=42)
|
445 |
today = datetime.date.today()
|
446 |
todays_date = today.strftime('%d%B%Y')
|
447 |
question = format_prompt(prompt, history)
|
448 |
+
logging.info("\n\nQuestion: %s",question)
|
449 |
|
450 |
chat_completion_params = generate_function_call(question)
|
451 |
logging.info(chat_completion_params)
|
|
|
456 |
logging.info("Final Ticker: %s", ticker)
|
457 |
|
458 |
try:
|
459 |
+
if (chat_completion_params['todays_news_flag'] or chat_completion_params['generic_query']) and len(ticker)<1:
|
460 |
logging.info("Getting Latest News Headlines")
|
461 |
news_link.append(todays_news())
|
462 |
time.sleep(2)
|
463 |
+
elif chat_completion_params['todays_news_flag'] and len(ticker)>0:
|
464 |
for tick in chat_completion_params["stock_name"]:
|
465 |
news_googles.append(f"Latest News for {tick}\n\n {get_google_news(tick)}")
|
466 |
+
elif (chat_completion_params['follow_up_query'] and ticker_stats != []) or (display_ticker == ticker and ticker_stats != []):
|
467 |
logging.info("\n\nAssigned into a followup query\n\n")
|
468 |
chat_completion_params['follow_up_query'] = True
|
469 |
else:
|
470 |
+
logging.info("prompt & ticker: %s, %s", question, ticker )
|
471 |
logging.info("Getting into raw_news()")
|
472 |
for stock in ticker:
|
473 |
+
context_file, ticker_stat, ticker_financial, report, news_google = raw_news(raw_query=question, todays_news_func_call=chat_completion_params["todays_news_flag"], ticker=stock)
|
|
|
|
|
|
|
|
|
474 |
# Append each detail to its corresponding list
|
475 |
context_files.append(context_file)
|
476 |
ticker_stats.append(ticker_stat)
|
|
|
478 |
reports.append(report)
|
479 |
news_googles.append(news_google)
|
480 |
|
481 |
+
|
482 |
logging.info(f"Generating response for **{question}**")
|
483 |
display_ticker = ticker if ticker else [0]
|
484 |
env = Environment(loader=FileSystemLoader("templates/"), autoescape=True)
|
485 |
+
# env.globals['include'] = lambda filename: env.loader.get_source(env, filename)[0]
|
486 |
template = env.get_template("system_prompt.txt")
|
487 |
+
content = template.render(todays_date=todays_date,ticker_financials=ticker_financials ,response_type="Response-1",chat_completion_params=chat_completion_params,context_file=context_files, question=question,ticker=ticker, ticker_stats = ticker_stats, reports=reports, news_link=news_link, earnings = earning_link, news_googles=news_googles)
|
488 |
+
# logging.info(content)
|
489 |
+
output=""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
try:
|
491 |
+
# Now start the streaming
|
492 |
stream = client.text_generation(content, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
493 |
output = ""
|
494 |
for response in stream:
|
495 |
output += response.token.text
|
496 |
yield output
|
|
|
497 |
except StopAsyncIteration:
|
498 |
yield "Sorry, could you provide more details to clarify your query"
|
499 |
except Exception as e:
|
500 |
yield f"Sorry, your query couldn't be processed. Retry with correct name of stock - An error occurred: {e}"
|
501 |
+
|
502 |
|
503 |
theme ="JohnSmith9982/small_and_pretty"
|
504 |
|