File size: 922 Bytes
fb8e56f 36bf3eb fb8e56f 36bf3eb fb8e56f 36bf3eb fb8e56f 36bf3eb 363f267 |
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 |
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
# Use the context along with the response for tailoring
tailored_response = get_tailor_chain().run({"response": context})
return tailored_response
|