WilliamGazeley commited on
Commit
0583c4b
1 Parent(s): a818c02

Update preprompt

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -3,22 +3,17 @@ import huggingface_hub
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:
16
  The questions will be asked by top technology executives and CFO of large fintech companies and successful startups.
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,36 +21,31 @@ def init_llm():
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.")
 
3
  import streamlit as st
4
  from vllm import LLM, SamplingParams
5
 
6
+ sys_msg = """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.
 
 
 
 
7
  #Objective:
8
+ 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. Answer the question directly.
9
  Style and tone:
10
+ Answer in a friendly and engaging manner representing a top female investment professional working at a leading investment bank.
11
  #Audience:
12
  The questions will be asked by top technology executives and CFO of large fintech companies and successful startups.
13
  #Response:
14
+ Direct answer to question, concise yet insightful."""
 
15
 
16
+ @st.cache_resource(show_spinner="Loading model..")
17
  def init_llm():
18
  huggingface_hub.login(token=os.getenv("HF_TOKEN"))
19
  llm = LLM(model="InvestmentResearchAI/LLM-ADE-dev")
 
21
  tok.eos_token = '<|im_end|>' # Override to use turns
22
  return llm
23
 
24
+ def get_response(prompt):
 
25
  try:
26
  convo = [
27
+ {"role": "system", "content": sys_msg},
28
  {"role": "user", "content": prompt},
29
  ]
30
+ llm = init_llm()
31
  prompts = [llm.get_tokenizer().apply_chat_template(convo, tokenize=False)]
32
+ sampling_params = SamplingParams(temperature=0.3, top_p=0.95, max_tokens=500, stop_token_ids=[128009])
33
  outputs = llm.generate(prompts, sampling_params)
34
  for output in outputs:
35
  return output.outputs[0].text
36
  except Exception as e:
37
  return f"An error occurred: {str(e)}"
38
 
39
+
40
  def main():
41
  st.title("LLM-ADE 9B Demo")
42
 
 
 
 
 
 
 
43
  input_text = st.text_area("Enter your text here:", value="", height=200)
44
 
45
  if st.button("Generate"):
46
  if input_text:
47
  with st.spinner('Generating response...'):
48
+ response_text = get_response(input_text)
49
  st.write(response_text)
50
  else:
51
  st.warning("Please enter some text to generate a response.")