Skip to content

Commit a9ca8f2

Browse files
committed
Removed manual version edit
Removed specific OpenAIPersonaSolver class to use OpenAIChatCompletionsSolver Moved specifics for system_prompt to OpenAIChatCompletionsSolver Updated docs to reflect changes
1 parent badaf9c commit a9ca8f2

File tree

6 files changed

+12
-50
lines changed

6 files changed

+12
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Spoken answers api with OpenAI or [LocalAI](https://github.com/go-skynet/LocalAI
1313
from ovos_solver_openai_persona import OpenAIPersonaSolver
1414

1515
bot = OpenAIPersonaSolver({"key": "sk-XXX",
16-
"system_prompt": "helpful, creative, clever, and very friendly"})
16+
"system_prompt": "You are a helpful assistant."})
1717
print(bot.get_spoken_answer("describe quantum mechanics in simple terms"))
1818
# Quantum mechanics is a branch of physics that deals with the behavior of particles on a very small scale, such as atoms and subatomic particles. It explores the idea that particles can exist in multiple states at once and that their behavior is not predictable in the traditional sense.
1919
print(bot.spoken_answer("Quem encontrou o caminho maritimo para o Brazil", {"lang": "pt-pt"}))

ovos_solver_openai_persona/__init__.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,5 @@
1-
from typing import Optional, Iterable, List, Dict
2-
31
from ovos_solver_openai_persona.engines import OpenAIChatCompletionsSolver
42

5-
6-
class OpenAIPersonaSolver(OpenAIChatCompletionsSolver):
7-
"""default "Persona" engine"""
8-
9-
def __init__(self, config=None):
10-
# defaults to gpt-3.5-turbo
11-
super().__init__(config=config)
12-
self.system_prompt = config.get("system_prompt") or "You are a helpful assistant. You are creative, clever, and very friendly."
13-
14-
def get_chat_history(self, persona=None):
15-
return super().get_chat_history(self.system_prompt)
16-
17-
# officially exported Solver methods
18-
def get_spoken_answer(self, query: str,
19-
lang: Optional[str] = None,
20-
units: Optional[str] = None) -> Optional[str]:
21-
"""
22-
Obtain the spoken answer for a given query.
23-
24-
Args:
25-
query (str): The query text.
26-
lang (Optional[str]): Optional language code. Defaults to None.
27-
units (Optional[str]): Optional units for the query. Defaults to None.
28-
29-
Returns:
30-
str: The spoken answer as a text response.
31-
"""
32-
answer = super().get_spoken_answer(query, lang, units)
33-
if not answer or not answer.strip("?") or not answer.strip("_"):
34-
return None
35-
return answer
36-
37-
def stream_chat_utterances(self, messages: List[Dict[str, str]],
38-
lang: Optional[str] = None,
39-
units: Optional[str] = None) -> Iterable[str]:
40-
messages = [{"role": "system", "content": self.system_prompt }] + messages
41-
answer = super().stream_chat_utterances(messages, lang, units)
42-
yield from answer
43-
443
# for ovos-persona
454
LLAMA_DEMO = {
465
"name": "Remote LLama",
@@ -53,9 +12,8 @@ def stream_chat_utterances(self, messages: List[Dict[str, str]],
5312
}
5413
}
5514

56-
5715
if __name__ == "__main__":
58-
bot = OpenAIPersonaSolver(LLAMA_DEMO["ovos-solver-openai-persona-plugin"])
16+
bot = OpenAIChatCompletionsSolver(LLAMA_DEMO["ovos-solver-openai-persona-plugin"])
5917
#for utt in bot.stream_utterances("describe quantum mechanics in simple terms"):
6018
# print(utt)
6119
# Quantum mechanics is a branch of physics that studies the behavior of atoms and particles at the smallest scales.

ovos_solver_openai_persona/dialog_transformers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, name="ovos-dialog-transformer-openai-plugin", priority=10, co
1212
"key": self.config.get("key"),
1313
'api_url': self.config.get('api_url', 'https://api.openai.com/v1'),
1414
"enable_memory": False,
15-
"initial_prompt": "your task is to rewrite text as if it was spoken by a different character"
15+
"system_prompt": "Your task is to rewrite text as if it was spoken by a different character"
1616
})
1717

1818
def transform(self, dialog: str, context: dict = None) -> Tuple[str, dict]:

ovos_solver_openai_persona/engines.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def stream_chat_utterances(self, messages: List[Dict[str, str]],
216216
Returns:
217217
Iterable[str]: An iterable of utterances.
218218
"""
219+
messages = [{"role": "system", "content": self.system_prompt }] + messages
219220
answer = ""
220221
query = messages[-1]["content"]
221222
if self.memory:
@@ -266,4 +267,7 @@ def get_spoken_answer(self, query: str,
266267
"""
267268
messages = self.get_messages(query)
268269
# just for api compat since it's a subclass, shouldn't be directly used
269-
return self.continue_chat(messages=messages, lang=lang, units=units)
270+
answer = self.continue_chat(messages=messages, lang=lang, units=units)
271+
if not answer or not answer.strip("?") or not answer.strip("_"):
272+
return None
273+
return answer
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# START_VERSION_BLOCK
2-
VERSION_MAJOR = 2
3-
VERSION_MINOR = 0
4-
VERSION_BUILD = 0
2+
VERSION_MAJOR = 1
3+
VERSION_MINOR = 1
4+
VERSION_BUILD = 2
55
VERSION_ALPHA = 0
66
# END_VERSION_BLOCK

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_version():
4848

4949

5050
PERSONA_ENTRY_POINT = 'Remote Llama=ovos_solver_openai_persona:LLAMA_DEMO'
51-
PLUGIN_ENTRY_POINT = 'ovos-solver-openai-persona-plugin=ovos_solver_openai_persona:OpenAIPersonaSolver'
51+
PLUGIN_ENTRY_POINT = 'ovos-solver-openai-persona-plugin=ovos_solver_openai_persona.engines:OpenAIChatCompletionsSolver'
5252
DIALOG_PLUGIN_ENTRY_POINT = 'ovos-dialog-transformer-openai-plugin=ovos_solver_openai_persona.dialog_transformers:OpenAIDialogTransformer'
5353

5454

0 commit comments

Comments
 (0)