You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generates a chat response using the provided message history and updates memory if enabled.
264
+
Generate a chat response based on the provided message history and update conversation memory if enabled.
265
265
266
-
If the first message is not a system prompt, prepends the system prompt. Processes the API response and returns a cleaned answer, or None if the answer is empty or only punctuation/underscores. Updates internal memory with the latest question and answer if memory is enabled.
266
+
If the first message is not a system prompt, prepends the system prompt. Returns a cleaned response string, or None if the response is empty or contains only punctuation or underscores. Updates internal memory with the latest user message and answer when memory is enabled.
267
267
268
-
Args:
269
-
messages: List of chat messages with 'role' and 'content' keys.
270
-
lang: Optional language code for the response.
271
-
units: Optional unit system for numerical values.
268
+
Parameters:
269
+
messages (MessageList): List of chat messages, each with 'role' and 'content' keys.
270
+
lang (Optional[str]): Language code for the response.
271
+
units (Optional[str]): Unit system for numerical values.
272
272
273
273
Returns:
274
-
The generated response as a string, or None if no valid response is produced.
274
+
Optional[str]: The generated response string, or None if no valid response is produced.
Constructs the complete message list for the LLM, including RAG context and chat history.
143
+
Constructs the message list for the LLM by combining retrieved context, recent chat history, and the current user query.
144
144
145
-
Args:
146
-
user_query (str): The current user's utterance.
147
-
retrieved_context_chunks (List[str]): List of text chunks retrieved from the vector store.
148
-
chat_history (List[Dict[str, str]]): The conversation history from `self.qa_pairs`.
145
+
The method concatenates relevant context chunks (up to a token limit), formats the system prompt with this context and the user's question, appends recent Q&A pairs from memory, and adds the current user query as the final message.
146
+
147
+
Parameters:
148
+
user_query (str): The user's current question or utterance.
149
+
retrieved_context_chunks (List[str]): Relevant text segments retrieved from the vector store.
150
+
chat_history (List[Dict[str, str]]): Previous conversation history.
149
151
150
152
Returns:
151
-
List[Dict[str, str]]: A new list of messages, augmented with the RAG context and history.
153
+
List[Dict[str, str]]: The complete list of messages to send to the LLM, including system prompt, chat history, and user query.
Generates a chat response using RAG by directly calling the Persona Server's
206
-
chat completions endpoint.
209
+
Generate a chat response by augmenting the user query with retrieved context from a vector store and sending the constructed prompt to the Persona Server's chat completions endpoint.
207
210
208
-
Args:
209
-
messages: List of chat messages with 'role' and 'content' keys.
210
-
The last user message is used for RAG retrieval and as the current query.
211
-
lang: Optional language code for the response.
212
-
units: Optional unit system for numerical values.
211
+
Parameters:
212
+
messages (List[Dict[str, str]]): List of chat messages, where the last message is treated as the current user query.
213
+
lang (Optional[str]): Optional language code for the response.
214
+
units (Optional[str]): Optional unit system for numerical values.
213
215
214
216
Returns:
215
-
The generated response as a string, or None if no valid response is produced.
217
+
Optional[str]: The generated response as a string, or None if no valid response is produced.
218
+
219
+
Raises:
220
+
RequestException: If the Persona Server's chat completions endpoint returns an error or an invalid response.
216
221
"""
217
222
user_query=messages[-1]["content"] # Get the current user query
units: Optional[str] =None) ->Iterable[str]: # Yields raw data: lines
267
272
"""
268
-
Stream utterances for the given chat history using RAG by directly calling the Persona Server's
269
-
chat completions endpoint in streaming mode.
273
+
Streams chat completion responses from the Persona Server using Retrieval Augmented Generation (RAG), yielding each line of streamed data as it arrives.
270
274
271
-
Args:
272
-
messages: The chat messages. The last user message is used for RAG retrieval and as the current query.
273
-
lang (Optional[str]): Optional language code. Defaults to None.
274
-
units (Optional[str]): Optional units for the query. Defaults to None.
275
+
The method retrieves relevant context from the vector store based on the latest user query, augments the chat history, and streams the LLM's response line by line. If enabled, it stores the full answer in memory for multi-turn conversations.
276
+
277
+
Parameters:
278
+
messages (List[Dict[str, str]]): The chat history, with the last message as the current user query.
279
+
lang (Optional[str]): Optional language code for the query.
280
+
units (Optional[str]): Optional units for the query.
275
281
276
282
Returns:
277
-
Iterable[str]: An iterable of raw data: [JSON] strings from the streaming API.
283
+
Iterable[str]: Yields each raw data line (as a string) from the streaming API response.
278
284
"""
279
285
user_query=messages[-1]["content"] # Get the current user query
0 commit comments