Spaces:
Sleeping
Sleeping
| from langchain.prompts import PromptTemplate | |
| from llm_client import LLMClient | |
| from langchain.agents import Tool | |
| class Redommend: | |
| ## class for generating recommendations based on user input | |
| def __init__(self, llm_client: LLMClient): | |
| self.llm_client = llm_client | |
| # Define the prompt template for generating recommendations. | |
| # Note: now the input variable is called "maladie" (same as the placeholder). | |
| template = """ | |
| Vous êtes en culture de pommes de terre | |
| * Pour guérir cette {maladie} : | |
| - Vous devez recommander les meilleures pratiques de culture pour cette maladie. | |
| - Veuillez lister les recommandations de manière concise, étape par étape. | |
| - Donnez la réponse sous forme de liste numérotée, en JSON. | |
| - Donnez simplement la réponse en JSON, sans explications supplémentaires. | |
| - Donnez la reponse en Français. | |
| """ | |
| self.prompt_template = PromptTemplate( | |
| input_variables=["maladie"], | |
| template=template | |
| ) | |
| self.tool = Tool( | |
| name="recommender", | |
| func=self._run, | |
| description="Use this tool to get recommendations for potato cultivation based on the disease." | |
| ) | |
| def _run(self, maladie: str) -> str: | |
| # Generate the prompt with the maladie string that comes from the query parameter. | |
| prompt = self.prompt_template.format(maladie=maladie) | |
| # Invoke the LLM client to get recommendations | |
| response = self.llm_client.invoke(prompt) | |
| return response | |