Skip to content

Commit

Permalink
improve: [chatbot] support system_prompts dynamically update
Browse files Browse the repository at this point in the history
  • Loading branch information
luochen1990 committed Oct 9, 2024
1 parent 0717161 commit be249b8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ai_powered/chat_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ChatBot:
conversation: list[ChatCompletionMessageParam] = field(default_factory = lambda: [])

def __post_init__(self):
self._system_prompts: list[ChatCompletionMessageParam] = [{"role": "system", "content": s} for s in self.system_prompts]
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 @@ -33,6 +32,9 @@ async def chat_continue(self) -> str:
if DEBUG:
print(gray(f"{self.conversation =}"))

# NOTE: system_prompts might be updated dynamically
self._system_prompts: list[ChatCompletionMessageParam] = [{"role": "system", "content": s} for s in self.system_prompts]

response = await self.connection.chat_completions(
model = model_config.model_name,
messages = [*self._system_prompts, *self.conversation],
Expand Down

0 comments on commit be249b8

Please sign in to comment.