Download climateqa/engine/keywords.py from Ekimetrics/climate-question-answering: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/aba2a7c615cca7b77dcd09bbc5db2ac03a61013d/climateqa/engine/keywords.py
- Command line
-
hf download hf://spaces/Ekimetrics/climate-question-answering@aba2a7c615cca7b77dcd09bbc5db2ac03a61013d/climateqa/engine/keywords.py
-
curl -L -o keywords.py https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/aba2a7c615cca7b77dcd09bbc5db2ac03a61013d/climateqa/engine/keywords.py
1.29 kB
| from typing import List | |
| from typing import Literal | |
| from langchain_core.pydantic_v1 import BaseModel, Field | |
| from langchain.prompts import ChatPromptTemplate | |
| from langchain_core.utils.function_calling import convert_to_openai_function | |
| from langchain.output_parsers.openai_functions import JsonOutputFunctionsParser | |
| class KeywordsOutput(BaseModel): | |
| """Analyzing the user query to get keywords for a search engine""" | |
| keywords: list = Field( | |
| description=""" | |
| Generate 1 or 2 relevant keywords from the user query to ask a search engine for scientific research papers. Answer only with English keywords. | |
| Do not use special characters or accents. | |
| Example: | |
| - "What is the impact of deep sea mining ?" -> ["deep sea mining"] | |
| - "Quel est l'impact de l'exploitation minière en haute mer ?" -> ["deep sea mining"] | |
| - "How will El Nino be impacted by climate change" -> ["el nino"] | |
| - "Is climate change a hoax" -> [Climate change","hoax"] | |
| """ | |
| ) | |
| def make_keywords_chain(llm): | |
| functions = [convert_to_openai_function(KeywordsOutput)] | |
| llm_functions = llm.bind(functions = functions,function_call={"name":"KeywordsOutput"}) | |
| chain = llm_functions | JsonOutputFunctionsParser() | |
| return chain |