Skip to content

Commit

Permalink
improve: [ChatBot] remove prints
Browse files Browse the repository at this point in the history
  • Loading branch information
luochen1990 committed Aug 5, 2024
1 parent 8e01e20 commit 58f3dcf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/ai_powered/chat_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ai_powered.constants import DEBUG, OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL_NAME
from ai_powered.llm_adapter.known_models import complete_model_config
from ai_powered.llm_adapter.openai.param_types import ChatCompletionMessageParam
from ai_powered.tool_call import MakeTool
from ai_powered.tool_call import ChatCompletionToolParam, MakeTool

default_client = openai.OpenAI(base_url=OPENAI_BASE_URL, api_key=OPENAI_API_KEY)
model_config = complete_model_config(OPENAI_BASE_URL, OPENAI_MODEL_NAME)
Expand All @@ -24,6 +24,7 @@ def __post_init__(self):
if len(self.system_prompt) > 0:
self.conversation.append({"role": "system", "content": self.system_prompt})
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

def chat_continue(self) -> str:
if DEBUG:
Expand All @@ -32,7 +33,7 @@ def chat_continue(self) -> str:
response = self.client.chat.completions.create(
model = model_config.model_name,
messages = self.conversation,
tools = [ t.schema() for t in self.tools ] if len(self.tools) > 0 else openai.NOT_GIVEN,
tools = self._tool_schemas,
)
assistant_message = response.choices[0].message

Expand Down
4 changes: 3 additions & 1 deletion src/ai_powered/tool_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def schema(self) -> ChatCompletionToolParam:

raw_schema = msgspec.json.schema(self.struct_of_parameters())
parameters_schema = deref(raw_schema)
print(yellow(f"{parameters_schema =}"))

if DEBUG:
print(yellow(f"{parameters_schema =}"))

return {
"type": "function",
Expand Down

0 comments on commit 58f3dcf

Please sign in to comment.