Skip to content

Commit b6ccfee

Browse files
authored
Merge pull request #21 from OpenVoiceOS/release-1.2.0a1
Release 1.2.0a1
2 parents 456ce57 + a990a2b commit b6ccfee

File tree

5 files changed

+82
-22
lines changed

5 files changed

+82
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Changelog
22

3-
## [1.1.2a1](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/tree/1.1.2a1) (2025-01-31)
3+
## [1.2.0a1](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/tree/1.2.0a1) (2025-02-05)
44

5-
[Full Changelog](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/compare/V1.1.1...1.1.2a1)
5+
[Full Changelog](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/compare/V1.1.2...1.2.0a1)
66

77
**Merged pull requests:**
88

9-
- fix:text post processing [\#17](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/pull/17) ([JarbasAl](https://github.com/JarbasAl))
9+
- feat: summarizer plugin [\#20](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/pull/20) ([JarbasAl](https://github.com/JarbasAl))
10+
- Log better error messages for streaming reply from ollama /v1/chat/completions API [\#14](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/pull/14) ([devvmh](https://github.com/devvmh))
1011

11-
## [V1.1.1](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/tree/V1.1.1) (2025-01-31)
12+
## [V1.1.2](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/tree/V1.1.2) (2025-01-31)
1213

13-
[Full Changelog](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/compare/1.1.1...V1.1.1)
14+
[Full Changelog](https://github.com/OpenVoiceOS/ovos-solver-openai-persona-plugin/compare/1.1.2...V1.1.2)
1415

1516

1617

ovos_solver_openai_persona/engines.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22
from typing import Optional, Iterable, List, Dict
33

44
import requests
5-
from ovos_plugin_manager.templates.solvers import QuestionSolver
6-
from ovos_utils.log import LOG
75

86
from ovos_plugin_manager.templates.solvers import ChatMessageSolver
7+
from ovos_plugin_manager.templates.solvers import QuestionSolver
8+
from ovos_plugin_manager.templates.language import LanguageTranslator, LanguageDetector
9+
from ovos_utils.log import LOG
910

1011
MessageList = List[Dict[str, str]] # for typing
1112

12-
class OpenAICompletionsSolver(QuestionSolver):
13-
enable_tx = False
14-
priority = 25
1513

16-
def __init__(self, config=None):
17-
super().__init__(config)
14+
class OpenAICompletionsSolver(QuestionSolver):
15+
def __init__(self, config=None,
16+
translator: Optional[LanguageTranslator] = None,
17+
detector: Optional[LanguageDetector] = None,
18+
priority: int = 50,
19+
enable_tx: bool = False,
20+
enable_cache: bool = False,
21+
internal_lang: Optional[str] = None):
22+
super().__init__(config=config, translator=translator,
23+
detector=detector, priority=priority,
24+
enable_tx=enable_tx, enable_cache=enable_cache,
25+
internal_lang=internal_lang)
1826
self.api_url = f"{self.config.get('api_url', 'https://api.openai.com/v1')}/completions"
1927
self.engine = self.config.get("model", "text-davinci-002") # "ada" cheaper and faster, "davinci" better
2028
self.stop_token = "<|im_end|>"
@@ -78,11 +86,17 @@ def post_process_sentence(text: str) -> str:
7886

7987

8088
class OpenAIChatCompletionsSolver(ChatMessageSolver):
81-
enable_tx = False
82-
priority = 25
83-
84-
def __init__(self, config=None):
85-
super().__init__(config)
89+
def __init__(self, config=None,
90+
translator: Optional[LanguageTranslator] = None,
91+
detector: Optional[LanguageDetector] = None,
92+
priority: int = 25,
93+
enable_tx: bool = False,
94+
enable_cache: bool = False,
95+
internal_lang: Optional[str] = None):
96+
super().__init__(config=config, translator=translator,
97+
detector=detector, priority=priority,
98+
enable_tx=enable_tx, enable_cache=enable_cache,
99+
internal_lang=internal_lang)
86100
self.api_url = f"{self.config.get('api_url', 'https://api.openai.com/v1')}/chat/completions"
87101
self.engine = self.config.get("model", "gpt-4o-mini") # "ada" cheaper and faster, "davinci" better
88102
self.stop_token = "<|im_end|>"
@@ -91,7 +105,7 @@ def __init__(self, config=None):
91105
LOG.error("key not set in config")
92106
raise ValueError("key must be set")
93107
self.memory = config.get("enable_memory", True)
94-
self.max_utts = config.get("memory_size", 15)
108+
self.max_utts = config.get("memory_size", 5)
95109
self.qa_pairs = [] # tuple of q+a
96110
self.initial_prompt = config.get("initial_prompt", "You are a helpful assistant.")
97111

@@ -154,6 +168,9 @@ def _do_streaming_api_request(self, messages):
154168
if chunk:
155169
chunk = chunk.decode("utf-8")
156170
chunk = json.loads(chunk.split("data: ", 1)[-1])
171+
if "error" in chunk and "message" in chunk["error"]:
172+
LOG.error("API returned an error: " + chunk["error"]["message"])
173+
break
157174
if chunk["choices"][0].get("finish_reason"):
158175
break
159176
if "content" not in chunk["choices"][0]["delta"]:
@@ -264,4 +281,3 @@ def get_spoken_answer(self, query: str,
264281
messages = self.get_messages(query)
265282
# just for api compat since it's a subclass, shouldn't be directly used
266283
return self.continue_chat(messages=messages, lang=lang, units=units)
267-
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from ovos_solver_openai_persona.engines import OpenAIChatCompletionsSolver
2+
from ovos_plugin_manager.templates.solvers import TldrSolver
3+
from ovos_plugin_manager.templates.language import LanguageTranslator, LanguageDetector
4+
from typing import Dict, Optional
5+
6+
7+
class OpenAISummarizer(TldrSolver):
8+
TEMPLATE = """Your task is to summarize the text into a suitable format.
9+
Answer in plaintext with no formatting, 2 paragraphs long at most.
10+
Focus on the most important information.
11+
---------------------
12+
{content}
13+
"""
14+
def __init__(self, config: Optional[Dict] = None,
15+
translator: Optional[LanguageTranslator] = None,
16+
detector: Optional[LanguageDetector] = None,
17+
priority: int = 50,
18+
enable_tx: bool = False,
19+
enable_cache: bool = False,
20+
internal_lang: Optional[str] = None):
21+
super().__init__(config=config, translator=translator,
22+
detector=detector, priority=priority,
23+
enable_tx=enable_tx, enable_cache=enable_cache,
24+
internal_lang=internal_lang)
25+
self.llm = OpenAIChatCompletionsSolver(config=config, translator=translator,
26+
detector=detector, priority=priority,
27+
enable_tx=enable_tx, enable_cache=enable_cache,
28+
internal_lang=internal_lang)
29+
self.prompt_template = self.config.get("prompt_template") or self.TEMPLATE
30+
31+
32+
def get_tldr(self, document: str, lang: Optional[str] = None) -> str:
33+
"""
34+
Summarize the provided document.
35+
36+
:param document: The text of the document to summarize, assured to be in the default language.
37+
:param lang: Optional language code.
38+
:return: A summary of the provided document.
39+
"""
40+
prompt = self.prompt_template.format(content=document)
41+
return self.llm.get_spoken_answer(prompt, lang)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# START_VERSION_BLOCK
22
VERSION_MAJOR = 1
3-
VERSION_MINOR = 1
4-
VERSION_BUILD = 2
5-
VERSION_ALPHA = 0
3+
VERSION_MINOR = 2
4+
VERSION_BUILD = 0
5+
VERSION_ALPHA = 1
66
# END_VERSION_BLOCK

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def get_version():
5050
PERSONA_ENTRY_POINT = 'Remote Llama=ovos_solver_openai_persona:LLAMA_DEMO'
5151
PLUGIN_ENTRY_POINT = 'ovos-solver-openai-persona-plugin=ovos_solver_openai_persona:OpenAIPersonaSolver'
5252
DIALOG_PLUGIN_ENTRY_POINT = 'ovos-dialog-transformer-openai-plugin=ovos_solver_openai_persona.dialog_transformers:OpenAIDialogTransformer'
53+
SUMMARIZER_ENTRY_POINT = 'ovos-summarizer-openai-plugin=ovos_solver_openai_persona.summarizer:OpenAISummarizer'
5354

5455

5556
setup(
@@ -66,6 +67,7 @@ def get_version():
6667
entry_points={
6768
'neon.plugin.solver': PLUGIN_ENTRY_POINT,
6869
"opm.transformer.dialog": DIALOG_PLUGIN_ENTRY_POINT,
70+
'opm.solver.summarization': SUMMARIZER_ENTRY_POINT,
6971
"opm.plugin.persona": PERSONA_ENTRY_POINT
7072
},
7173
install_requires=required("requirements.txt"),

0 commit comments

Comments
 (0)