Download climateqa/engine/reformulation.py from Ekimetrics/climate-question-answering: direct link, hf CLI and curl.
- Browser
- Download file 933 Bytes
-
https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/3e0b86d37609dcf7c25b96bfe60b2184d1db468c/climateqa/engine/reformulation.py
- Command line
-
hf download hf://spaces/Ekimetrics/climate-question-answering@3e0b86d37609dcf7c25b96bfe60b2184d1db468c/climateqa/engine/reformulation.py
-
curl -L -o reformulation.py https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/3e0b86d37609dcf7c25b96bfe60b2184d1db468c/climateqa/engine/reformulation.py
933 Bytes
| from langchain.output_parsers import StructuredOutputParser, ResponseSchema | |
| from langchain.prompts import PromptTemplate | |
| from langchain.llms import OpenAI | |
| from langchain.chat_models import ChatOpenAI | |
| from climateqa.engine.prompts import reformulation_prompt_template | |
| response_schemas = [ | |
| ResponseSchema(name="language", description="The detected language of the input message"), | |
| ResponseSchema(name="question", description="The reformulated question always in English") | |
| ] | |
| output_parser = StructuredOutputParser.from_response_schemas(response_schemas) | |
| format_instructions = output_parser.get_format_instructions() | |
| def make_reformulation_chain(llm): | |
| prompt = PromptTemplate( | |
| template=reformulation_prompt_template, | |
| input_variables=["query"], | |
| partial_variables={"format_instructions": format_instructions} | |
| ) | |
| chain = (prompt | llm.bind(stop=["```"]) | output_parser) | |
| return chain | |