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
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.
14
+
"""
10
15
super().__init__(name, priority, config)
11
16
self.solver=OpenAIChatCompletionsSolver({
12
17
"key": self.config.get("key"),
@@ -17,9 +22,16 @@ def __init__(self, name="ovos-dialog-transformer-openai-plugin", priority=10, co
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.
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.
210
267
211
268
Args:
212
-
messages (List[Dict[str, str]]): List of chat messages, each containing 'role' and 'content'.
213
-
lang (Optional[str]): The language code for the response. If None, will be auto-detected.
214
-
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.
215
272
216
273
Returns:
217
-
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