Spaces:
Sleeping
Sleeping
File size: 1,593 Bytes
2c67191 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 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
|