no docs prompt ing
Browse files
app.py
CHANGED
@@ -62,22 +62,6 @@ def chat(
|
|
62 |
|
63 |
if sources:
|
64 |
messages.append({"role": "system", "content": f"{os.environ['sources']}\n\n{sources}"})
|
65 |
-
else:
|
66 |
-
messages.append(
|
67 |
-
{
|
68 |
-
"role": "system",
|
69 |
-
"content": """Tell the user you did not find any relevant documents. Answer using your knowledge. Then tell them if their message was too vague or too short and if relevant provide an example of an alternative query.
|
70 |
-
example:
|
71 |
-
user: forrest
|
72 |
-
assistant: I did not find any relevant documents to answer your question, I will answer using my knowledge as a language model.
|
73 |
-
Forests play a crucial role in mitigating climate change. They act as carbon sinks, absorbing carbon dioxide from the atmosphere through photosynthesis and storing it in their biomass and soil. Deforestation, on the other hand, releases carbon dioxide into the atmosphere and reduces the planet's capacity to absorb carbon. Therefore, protecting and restoring forests is an important strategy for mitigating climate change.
|
74 |
-
|
75 |
-
You may want to try one of those more specific questions:
|
76 |
-
- What is deforestation, and how does it contribute to climate change?
|
77 |
-
- How does climate change impact forests and their ecosystems?""",
|
78 |
-
}
|
79 |
-
)
|
80 |
-
sources = "No environmental report was used to provide this answer."
|
81 |
|
82 |
response = openai.ChatCompletion.create(
|
83 |
model="gpt-3.5-turbo",
|
@@ -85,11 +69,21 @@ def chat(
|
|
85 |
temperature=0.2,
|
86 |
stream=True,
|
87 |
)
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
for chunk in response:
|
90 |
if chunk_message := chunk["choices"][0]["delta"].get("content", None):
|
91 |
complete_response += chunk_message
|
92 |
-
messages[-1]
|
93 |
gradio_format = make_pairs([a["content"] for a in messages[1:]])
|
94 |
yield gradio_format, messages, sources
|
95 |
|
@@ -115,13 +109,7 @@ with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
|
|
115 |
gr.Markdown(
|
116 |
""" Climate GPT is an interactive exploration tool designed to help you easily find relevant information based on of Environmental reports such as IPCCs and other environmental reports.
|
117 |
\n **How does it work:** when a user sends a message, the system retrieves the most relevant paragraphs from scientific reports that are semantically related to the user's question. These paragraphs are then used to generate a comprehensive and well-sourced answer using a language model.
|
118 |
-
\n **Usage guideline:** more sources will be retrieved using precise questions
|
119 |
-
instead of "forrest", you may want to try one of those more specific questions
|
120 |
-
- How do forests help mitigate climate change?
|
121 |
-
- What is deforestation, and how does it contribute to climate change?
|
122 |
-
- How does climate change impact forests and their ecosystems?
|
123 |
-
- Can reforestation efforts help combat climate change?
|
124 |
-
- What role do forests play in the carbon cycle, and how does that impact climate change?
|
125 |
\n ⚠️ Always refer to the source to ensure the validity of the information communicated.
|
126 |
"""
|
127 |
)
|
|
|
62 |
|
63 |
if sources:
|
64 |
messages.append({"role": "system", "content": f"{os.environ['sources']}\n\n{sources}"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
response = openai.ChatCompletion.create(
|
67 |
model="gpt-3.5-turbo",
|
|
|
69 |
temperature=0.2,
|
70 |
stream=True,
|
71 |
)
|
72 |
+
|
73 |
+
if sources:
|
74 |
+
messages.pop()
|
75 |
+
complete_response = ""
|
76 |
+
else:
|
77 |
+
sources = "No environmental report was used to provide this answer."
|
78 |
+
complete_response = (
|
79 |
+
"No relevant documents found, for a sourced answer you may want to try a more specific question.\n\n"
|
80 |
+
)
|
81 |
+
|
82 |
+
messages.append({"role": "assistant", "content": complete_response})
|
83 |
for chunk in response:
|
84 |
if chunk_message := chunk["choices"][0]["delta"].get("content", None):
|
85 |
complete_response += chunk_message
|
86 |
+
messages[-1]["content"] = complete_response
|
87 |
gradio_format = make_pairs([a["content"] for a in messages[1:]])
|
88 |
yield gradio_format, messages, sources
|
89 |
|
|
|
109 |
gr.Markdown(
|
110 |
""" Climate GPT is an interactive exploration tool designed to help you easily find relevant information based on of Environmental reports such as IPCCs and other environmental reports.
|
111 |
\n **How does it work:** when a user sends a message, the system retrieves the most relevant paragraphs from scientific reports that are semantically related to the user's question. These paragraphs are then used to generate a comprehensive and well-sourced answer using a language model.
|
112 |
+
\n **Usage guideline:** more sources will be retrieved using precise questions.
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
\n ⚠️ Always refer to the source to ensure the validity of the information communicated.
|
114 |
"""
|
115 |
)
|
utils.py
CHANGED
@@ -30,6 +30,7 @@ def make_pairs(lst):
|
|
30 |
Returns:
|
31 |
list: the list as tupple pairs
|
32 |
"""
|
|
|
33 |
return [(lst[i], lst[i + 1]) for i in range(0, len(lst), 2)]
|
34 |
|
35 |
|
|
|
30 |
Returns:
|
31 |
list: the list as tupple pairs
|
32 |
"""
|
33 |
+
assert not (l := len(lst) % 2), f"your list is of lenght {l} which is not even"
|
34 |
return [(lst[i], lst[i + 1]) for i in range(0, len(lst), 2)]
|
35 |
|
36 |
|