Skip to content

Commit 977466e

Browse files
committed
persona
1 parent 1af51b9 commit 977466e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

ovos_solver_chatgpt_plugin/__init__.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, config=None):
1616
# this is a leaked gpt model that is free to use, unmoderated free and slow
1717
self.engine = "text-chat-davinci-002-20221122" # "ada" cheaper and faster, "davinci" better
1818
self.stop_token = "<|im_end|>"
19-
self.key = self.config.get("key") or "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"
19+
self.key = self.config.get("key")
2020
ai.api_key = self.key
2121
self.chatgpt = ai.Completion()
2222
self.memory = True # todo config
@@ -25,21 +25,20 @@ def __init__(self, config=None):
2525
self.current_q = None
2626
self.current_a = None
2727

28-
@property
29-
def initial_prompt(self):
30-
start_chat_log = """The assistant is helpful, creative, clever, and very friendly."""
31-
s = self.config.get("initial_prompt", start_chat_log)
32-
return f"The following is a conversation with an AI assistant. The assistant understands all languages. The assistant gives short and factual answers. {s}"
33-
34-
@property
35-
def chat_history(self):
28+
def get_chat_history(self, persona=None):
3629
# TODO - intro question from skill settings
3730
intro_q = ("Hello, who are you?", "I am an AI created by OpenAI. How can I help you today?")
3831
if len(self.qa_pairs) > self.max_utts:
3932
qa = [intro_q] + self.qa_pairs[-1*self.max_utts:]
4033
else:
4134
qa = [intro_q] + self.qa_pairs
42-
chat = self.initial_prompt.strip() + "\n\n"
35+
36+
persona = persona or self.config.get("persona") or "helpful, creative, clever, and very friendly."
37+
initial_prompt = f"The following is a conversation with an AI assistant. " \
38+
f"The assistant understands all languages. " \
39+
f"The assistant gives short and factual answers. " \
40+
f"The assistant is {persona}"
41+
chat = initial_prompt.strip() + "\n\n"
4342
if qa:
4443
qa = "\n".join([f"Human: {q}\nAI: {a}" for q, a in qa])
4544
if chat.endswith("\nHuman: "):
@@ -49,10 +48,10 @@ def chat_history(self):
4948
chat += qa
5049
return chat
5150

52-
def get_prompt(self, utt):
51+
def get_prompt(self, utt, persona=None):
5352
self.current_q = None
5453
self.current_a = None
55-
prompt = self.chat_history
54+
prompt = self.get_chat_history(persona)
5655
if not prompt.endswith("\nHuman: "):
5756
prompt += f"\nHuman: {utt}?\nAI: "
5857
else:
@@ -61,7 +60,9 @@ def get_prompt(self, utt):
6160

6261
# officially exported Solver methods
6362
def get_spoken_answer(self, query, context=None):
64-
prompt = self.get_prompt(query)
63+
context = context or {}
64+
persona = context.get("persona")
65+
prompt = self.get_prompt(query, persona)
6566
# TODO - params from config
6667
response = self.chatgpt.create(prompt=prompt, engine=self.engine, temperature=0.85,
6768
top_p=1, frequency_penalty=0,

0 commit comments

Comments
 (0)