| | from langchain.chains import LLMChain |
| | from prompts import tailor_prompt |
| | import os |
| | from langchain_groq import ChatGroq |
| |
|
| | from prompts import tailor_prompt |
| |
|
| | def get_tailor_chain() -> LLMChain: |
| | """ |
| | Builds the chain that tailors the final response to DailyWellnessAI's style. |
| | """ |
| | chat_groq_model = ChatGroq( |
| | model="Gemma2-9b-It", |
| | groq_api_key=os.environ["GROQ_API_KEY"] |
| | ) |
| | chain = LLMChain( |
| | llm=chat_groq_model, |
| | prompt=tailor_prompt |
| | ) |
| | return chain |
| |
|
| | def tailor_with_history(response: str, chat_history: list) -> str: |
| | """ |
| | Tailors the assistant's response based on the history context. |
| | """ |
| | context = "\n".join([f"User: {msg['content']}" for msg in chat_history]) + "\nAssistant: " + response |
| | |
| | tailored_response = get_tailor_chain().run({"response": context}) |
| | return tailored_response |
| |
|