Skip to content

Commit

Permalink
improve: [chatbot] keep system prompt not lost
Browse files Browse the repository at this point in the history
  • Loading branch information
luochen1990 committed Aug 6, 2024
1 parent 98451cf commit b2e0a30
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/ai_powered/chat_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class ChatBot:
conversation : list[ChatCompletionMessageParam] = field(default_factory=lambda:[])

def __post_init__(self):
if len(self.system_prompt) > 0:
self.conversation.append({"role": "system", "content": self.system_prompt})
self._system_prompt = [{"role": "system", "content": s} for s in [self.system_prompt] if len(s) > 0]
self._tool_dict = {tool.fn.__name__: tool for tool in self.tools}
self._tool_schemas : list[ChatCompletionToolParam] | openai.NotGiven = [ t.schema() for t in self.tools ] if len(self.tools) > 0 else openai.NOT_GIVEN

Expand All @@ -32,7 +31,7 @@ def chat_continue(self) -> str:

response = self.client.chat.completions.create(
model = model_config.model_name,
messages = self.conversation,
messages = list(*self._system_prompt, *self.conversation),
tools = self._tool_schemas,
)
assistant_message = response.choices[0].message
Expand Down

0 comments on commit b2e0a30

Please sign in to comment.