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
- Use system\_prompt in solver configuration \(breaking change\)[\#19](https://github.com/OpenVoiceOS/ovos-openai-plugin/pull/19) ([Delfshkrimm](https://github.com/Delfshkrimm))
22
+
23
+
**Merged pull requests:**
24
+
25
+
- 📝 Add docstrings to `patch-1`[\#26](https://github.com/OpenVoiceOS/ovos-openai-plugin/pull/26) ([coderabbitai[bot]](https://github.com/apps/coderabbitai))
Initializes the OpenAIDialogTransformer with a name, priority, and configuration.
12
+
13
+
Creates an OpenAIChatCompletionsSolver using the provided API key, API URL, and a system prompt from the configuration or a default prompt if not specified.
Transforms the dialog string using a character-specific prompt if available.
26
+
27
+
If a prompt is provided in the context or configuration, rewrites the dialog as if spoken by a different character using the solver; otherwise, returns the original dialog unchanged.
28
+
29
+
Args:
30
+
dialog: The dialog string to be transformed.
31
+
context: Optional dictionary containing transformation context, such as a prompt or language.
32
+
33
+
Returns:
34
+
A tuple containing the transformed (or original) dialog and the unchanged context.
Streams response content from the OpenAI chat completions API.
177
+
178
+
Sends a POST request with the provided chat messages and yields content chunks as they are received from the streaming API. Stops iteration if an error is encountered or the response is finished.
179
+
180
+
Args:
181
+
messages: A list of chat message dictionaries to send as context.
182
+
183
+
Yields:
184
+
str: Segments of the assistant's reply as they arrive from the API.
Builds a list of chat messages including the system prompt, recent conversation history, and the current user utterance.
247
+
248
+
Args:
249
+
utt: The current user input to be appended as the latest message.
250
+
system_prompt: Optional system prompt to use as the initial message.
251
+
252
+
Returns:
253
+
A list of message dictionaries representing the chat context for the API.
254
+
"""
255
+
messages=self.get_chat_history(system_prompt)
195
256
messages.append({"role": "user", "content": utt})
196
257
returnmessages
197
258
198
259
# abstract Solver methods
199
260
defcontinue_chat(self, messages: MessageList,
200
261
lang: Optional[str],
201
262
units: Optional[str] =None) ->Optional[str]:
202
-
"""Generate a response based on the chat history.
263
+
"""
264
+
Generates a chat response using the provided message history and updates memory if enabled.
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.
203
267
204
268
Args:
205
-
messages (List[Dict[str, str]]): List of chat messages, each containing 'role' and 'content'.
206
-
lang (Optional[str]): The language code for the response. If None, will be auto-detected.
207
-
units (Optional[str]): Optional unit system for numerical values.
269
+
messages: List of chat messages with 'role' and 'content' keys.
270
+
lang: Optionallanguage code for the response.
271
+
units: Optional unit system for numerical values.
208
272
209
273
Returns:
210
-
Optional[str]: The generated response or None if no response could be generated.
274
+
The generated response as a string, or None if no valid response is produced.
0 commit comments