optimize code

This commit is contained in:
= 2025-04-26 21:58:44 +08:00
parent c1029e0ab7
commit bc6115442d

View File

@ -1,24 +1,21 @@
from dotenv import load_dotenv
import os, time
import time
import json
from openai import OpenAI
import chat_tools
load_dotenv()
from bot_util import get_api_details
# initialize parameters
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
DEEPSEEK_API_URL = os.getenv("DEEPSEEK_API_URL")
MODEL = "deepseek-chat"
chat_tools = chat_tools.get_chat_tools()
history = []
# Initialize the OpenAI client with the API key and base URL
client = OpenAI(
api_key=DEEPSEEK_API_KEY,
base_url=DEEPSEEK_API_URL,
api_key=get_api_details().api_key,
base_url=get_api_details().api_url,
)
MAX_RETRIES = 3
RETRY_DELAY = 2 # seconds
count = 0
@ -52,7 +49,6 @@ def chat_with_deepseek(max_retries: int =MAX_RETRIES, retry_delay: int =RETRY_DE
tool_name = tool_call.function.name
tool_args = tool_call.function.arguments
tool_id = tool_call.id
# Call the function with the arguments
if tool_name == "write_file":
params = json.loads(tool_args)