zliang commited on
Commit
2fff144
·
1 Parent(s): 32e9725

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -22
app.py CHANGED
@@ -14,7 +14,7 @@ import time
14
 
15
  # import e5-large-v2 embedding model
16
  model_name = "intfloat/e5-large-v2"
17
- model_kwargs = {'device': 'cpu'}
18
  encode_kwargs = {'normalize_embeddings': False}
19
  embeddings = HuggingFaceEmbeddings(
20
  model_name=model_name,
@@ -38,31 +38,51 @@ def generate_response(input_text):
38
  #st.write({"source1":json1["source"], "source2":json2["source"],"source3":json3["source"]})
39
 
40
 
41
- climate_TEMPLATE = """ You are ChatClimate, take a deep breath and use the following pieces of context to provide an answer for general audience. If you don't know the answer, just say that you don't know, don't try to make up an answer. Format your answer in Markdown:"
 
 
42
 
43
-
44
- Context: {context}
45
 
46
- Question: {question}
 
 
 
 
 
 
47
 
48
- Answer:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
 
51
-
52
- Check if you use the source in your ansewer, make sure list used sources you refer to and their hyperlinks as below in a section named "sources":
53
-
54
- [{source1} page {page1}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source1}.pdf#page={page1})
55
- [{source2} page {page2}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source2}.pdf#page={page2})
56
- [{source3} page {page3}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source3}.pdf#page={page3})
57
- [{source4} page {page4}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source4}.pdf#page={page4})
58
- [{source5} page {page5}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source5}.pdf#page={page5})
59
-
60
-
61
-
62
-
63
- at the end of your answer, make sure to add a short highlight of your answer in humor and make sure no more than 5 words.
64
-
65
- Highlight:
66
  """
67
  climate_PROMPT = PromptTemplate(input_variables=["question", "context"],
68
  partial_variables={"source1":json1["source"], "source2":json2["source"],
@@ -73,7 +93,7 @@ def generate_response(input_text):
73
  #climate_PROMPT.partial(source = docs[0].metadata)
74
 
75
  llm = ChatOpenAI(
76
- model_name="gpt-3.5-turbo",
77
  temperature=0.1,
78
  max_tokens=2000,
79
  openai_api_key=openai_api_key
 
14
 
15
  # import e5-large-v2 embedding model
16
  model_name = "intfloat/e5-large-v2"
17
+ model_kwargs = {'device': 'cuda'}
18
  encode_kwargs = {'normalize_embeddings': False}
19
  embeddings = HuggingFaceEmbeddings(
20
  model_name=model_name,
 
38
  #st.write({"source1":json1["source"], "source2":json2["source"],"source3":json3["source"]})
39
 
40
 
41
+ climate_TEMPLATE = """\
42
+ You are a professor in climate change, tasked with answering any question \
43
+ about climate change.
44
 
45
+ {question}
 
46
 
47
+ Generate a comprehensive and informative answer to the general audience of 100 words or less for the \
48
+ given question based solely on the provided search results (hyperlink and source). You must \
49
+ only use information from the provided search results. Use an unbiased and \
50
+ journalistic tone. Combine search results together into a coherent answer. Do not \
51
+ repeat text. Only use the most \
52
+ relevant results that answer the question accurately. cite them at the end of your answer, list these citations \
53
+ in a section named "source".
54
 
55
+ After the "source" section, add a "highlight" section\
56
+ And add a short highlight of your answer in humor and make sure no more than 5 words.\
57
+
58
+ Format your answer in markdown format
59
+
60
+ If there is nothing in the context relevant to the question at hand, just say "Hmm, \
61
+ I'm not sure." Don't try to make up an answer.
62
+
63
+ Anything between the following `context` html blocks is retrieved from a knowledge \
64
+ bank, not part of the conversation with the user.
65
+
66
+ <context>
67
+ {context}
68
+ <context/>
69
+
70
+ Anything between the following `sources` html blocks is the source and hyperlink you should use and list them into a source section\
71
+ <sources>
72
+ [{source1} page {page1}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source1}.pdf#page={page1})
73
+ [{source2} page {page2}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source2}.pdf#page={page2})
74
+ [{source3} page {page3}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source3}.pdf#page={page3})
75
+ [{source4} page {page4}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source4}.pdf#page={page4})
76
+ [{source5} page {page5}](https://www.ipcc.ch/report/ar6/wg3/downloads/report/{source5}.pdf#page={page5})
77
+ <sources/>
78
+
79
+ REMEMBER: If there is no relevant information within the context, just say "Hmm, I'm \
80
+ not sure." Don't try to make up an answer. Anything between the preceding 'context' \
81
+ html blocks is retrieved from a knowledge bank, not part of the conversation with the \
82
+ user.\
83
 
84
 
85
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  """
87
  climate_PROMPT = PromptTemplate(input_variables=["question", "context"],
88
  partial_variables={"source1":json1["source"], "source2":json2["source"],
 
93
  #climate_PROMPT.partial(source = docs[0].metadata)
94
 
95
  llm = ChatOpenAI(
96
+ model_name="gpt-3.5-turbo-16k",
97
  temperature=0.1,
98
  max_tokens=2000,
99
  openai_api_key=openai_api_key