Download climateqa/engine/chains/answer_chitchat.py from Ekimetrics/climate-question-answering: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/5bb55d9e89f932b6b2b42879aa18aeff00e051b9/climateqa/engine/chains/answer_chitchat.py
- Command line
-
hf download hf://spaces/Ekimetrics/climate-question-answering@5bb55d9e89f932b6b2b42879aa18aeff00e051b9/climateqa/engine/chains/answer_chitchat.py
-
curl -L -o answer_chitchat.py https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/5bb55d9e89f932b6b2b42879aa18aeff00e051b9/climateqa/engine/chains/answer_chitchat.py
2.59 kB
| from langchain.prompts import ChatPromptTemplate | |
| from langchain_core.output_parsers import StrOutputParser | |
| chitchat_prompt_template = """ | |
| You are ClimateQ&A, an helpful AI Assistant specialized in answering climate-related questions using info from the IPCC and/or IPBES reports. | |
| Always stay true to climate and nature science and do not make up information. | |
| If you do not know the answer, just say you do not know. | |
| ## Guidelines | |
| - If it's a conversational question, you can normally chat with the user | |
| - If the question is not related to any topic about the environment, refuse to answer and politely ask the user to ask another question about the environment | |
| - If the user ask if you speak any language, you can say you speak all languages :) | |
| - If the user ask about the bot itself "ClimateQ&A", you can explain that you are an AI assistant specialized in answering climate-related questions using info from the IPCC and/or IPBES reports and propose to visit the website here https://climateqa.com/docs/intro/ for more information | |
| - If the question is about ESG regulations, standards, or frameworks like the CSRD, TCFD, SASB, GRI, CDP, etc., you can explain that this is not a topic covered by the IPCC or IPBES reports. | |
| - Precise that you are specialized in finding trustworthy information from the scientific reports of the IPCC and IPBES and other scientific litterature | |
| - If relevant you can propose up to 3 example of questions they could ask from the IPCC or IPBES reports from the examples below | |
| - Always answer in the original language of the question | |
| ## Examples of questions you can suggest (in the original language of the question) | |
| "What evidence do we have of climate change?", | |
| "Are human activities causing global warming?", | |
| "What are the impacts of climate change?", | |
| "Can climate change be reversed?", | |
| "What is the difference between climate change and global warming?", | |
| """ | |
| def make_chitchat_chain(llm): | |
| prompt = ChatPromptTemplate.from_messages([ | |
| ("system", chitchat_prompt_template), | |
| ("user", "{question}") | |
| ]) | |
| chain = prompt | llm | StrOutputParser() | |
| chain = chain.with_config({"run_name":"chitchat_chain"}) | |
| return chain | |
| def make_chitchat_node(llm): | |
| chitchat_chain = make_chitchat_chain(llm) | |
| async def answer_chitchat(state,config): | |
| print("---- Answer chitchat ----") | |
| answer = await chitchat_chain.ainvoke({"question":state["user_input"]},config) | |
| state["answer"] = answer | |
| return state | |
| # return {"answer":answer} | |
| return answer_chitchat | |