WilliamGazeley commited on
Commit
a818c02
1 Parent(s): ad4ac8c

Reopen preprompt UI

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -3,10 +3,13 @@ import huggingface_hub
3
  import streamlit as st
4
  from vllm import LLM, SamplingParams
5
 
6
- sys_msg = """#Context:
7
- You are an expert financial advisor named IRAI. You have a comprehensive understanding of finance and investing with experience and expertise in all areas of finance.
 
 
 
8
  #Objective:
9
- Answer questions accurately and truthfully given your current knowledge. You do not have access to up-to-date current market data; this will be available in the future.
10
  Style and tone:
11
  Please answer in a friendly and engaging manner representing a top female investment professional working at a leading investment bank.
12
  #Audience:
@@ -14,7 +17,8 @@ The questions will be asked by top technology executives and CFO of large fintec
14
  #Response:
15
  Answer, concise yet insightful."""
16
 
17
- @st.cache_resource(show_spinner="Loading model..")
 
18
  def init_llm():
19
  huggingface_hub.login(token=os.getenv("HF_TOKEN"))
20
  llm = LLM(model="InvestmentResearchAI/LLM-ADE-dev")
@@ -22,31 +26,36 @@ def init_llm():
22
  tok.eos_token = '<|im_end|>' # Override to use turns
23
  return llm
24
 
25
- def get_response(prompt):
 
26
  try:
27
  convo = [
28
- {"role": "system", "content": sys_msg},
29
  {"role": "user", "content": prompt},
30
  ]
31
- llm = init_llm()
32
  prompts = [llm.get_tokenizer().apply_chat_template(convo, tokenize=False)]
33
- sampling_params = SamplingParams(temperature=0.3, top_p=0.95, max_tokens=500, stop_token_ids=[128009])
34
  outputs = llm.generate(prompts, sampling_params)
35
  for output in outputs:
36
  return output.outputs[0].text
37
  except Exception as e:
38
  return f"An error occurred: {str(e)}"
39
 
40
-
41
  def main():
42
  st.title("LLM-ADE 9B Demo")
43
 
 
 
 
 
 
 
44
  input_text = st.text_area("Enter your text here:", value="", height=200)
45
 
46
  if st.button("Generate"):
47
  if input_text:
48
  with st.spinner('Generating response...'):
49
- response_text = get_response(input_text)
50
  st.write(response_text)
51
  else:
52
  st.warning("Please enter some text to generate a response.")
 
3
  import streamlit as st
4
  from vllm import LLM, SamplingParams
5
 
6
+
7
+ @st.cache_data(show_spinner=False)
8
+ def get_system_message():
9
+ return """#Context:
10
+ You are an AI-based automated expert financial advisor named IRAI. You have a comprehensive understanding of finance and investing because you have trained on a extensive dataset based on of financial news, analyst reports, books, company filings, earnings call transcripts, and finance websites.
11
  #Objective:
12
+ Answer questions accurately and truthfully given the data you have trained on. You do not have access to up-to-date current market data; this will be available in the future.
13
  Style and tone:
14
  Please answer in a friendly and engaging manner representing a top female investment professional working at a leading investment bank.
15
  #Audience:
 
17
  #Response:
18
  Answer, concise yet insightful."""
19
 
20
+
21
+ @st.cache_resource(show_spinner=False)
22
  def init_llm():
23
  huggingface_hub.login(token=os.getenv("HF_TOKEN"))
24
  llm = LLM(model="InvestmentResearchAI/LLM-ADE-dev")
 
26
  tok.eos_token = '<|im_end|>' # Override to use turns
27
  return llm
28
 
29
+
30
+ def get_response(prompt, custom_sys_msg):
31
  try:
32
  convo = [
33
+ {"role": "system", "content": custom_sys_msg},
34
  {"role": "user", "content": prompt},
35
  ]
 
36
  prompts = [llm.get_tokenizer().apply_chat_template(convo, tokenize=False)]
37
+ sampling_params = SamplingParams(temperature=0.3, top_p=0.95, max_tokens=2000, stop_token_ids=[128009])
38
  outputs = llm.generate(prompts, sampling_params)
39
  for output in outputs:
40
  return output.outputs[0].text
41
  except Exception as e:
42
  return f"An error occurred: {str(e)}"
43
 
 
44
  def main():
45
  st.title("LLM-ADE 9B Demo")
46
 
47
+ # Retrieve the default system message
48
+ sys_msg = get_system_message()
49
+
50
+ # UI for editable preprompt
51
+ user_modified_sys_msg = st.text_area("Preprompt: ", value=sys_msg, height=200)
52
+
53
  input_text = st.text_area("Enter your text here:", value="", height=200)
54
 
55
  if st.button("Generate"):
56
  if input_text:
57
  with st.spinner('Generating response...'):
58
+ response_text = get_response(input_text, user_modified_sys_msg)
59
  st.write(response_text)
60
  else:
61
  st.warning("Please enter some text to generate a response.")