SimpleResponseGenerator.generate_response:v0
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
import weave
from typing import List
from typing import Dict
@weave.op()
def generate_response(self, query: str, context: List[Dict[str, any]]) -> str:
"""
Generate a response from the chat model based on the query and context.
Args:
query (str): The user's query.
context (List[Dict[str, any]]): A list of dictionaries containing context data.
Returns:
str: The generated response from the chat model.
"""
documents = self.generate_context(context)
messages = self.create_messages(query, documents)
kwargs = {
"model": self.model,
"messages": messages,
"temperature": 0.1,
"max_tokens": 2000,
}
if self.model.startswith("cohere"):
kwargs["documents"] = documents