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 time
import os, time
import json import json
from openai import OpenAI from openai import OpenAI
import chat_tools import chat_tools
from bot_util import get_api_details
load_dotenv()
# initialize parameters # initialize parameters
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
DEEPSEEK_API_URL = os.getenv("DEEPSEEK_API_URL")
MODEL = "deepseek-chat" MODEL = "deepseek-chat"
chat_tools = chat_tools.get_chat_tools() chat_tools = chat_tools.get_chat_tools()
history = [] history = []
# Initialize the OpenAI client with the API key and base URL # Initialize the OpenAI client with the API key and base URL
client = OpenAI( client = OpenAI(
api_key=DEEPSEEK_API_KEY, api_key=get_api_details().api_key,
base_url=DEEPSEEK_API_URL, base_url=get_api_details().api_url,
) )
MAX_RETRIES = 3 MAX_RETRIES = 3
RETRY_DELAY = 2 # seconds RETRY_DELAY = 2 # seconds
count = 0 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_name = tool_call.function.name
tool_args = tool_call.function.arguments tool_args = tool_call.function.arguments
tool_id = tool_call.id tool_id = tool_call.id
# Call the function with the arguments # Call the function with the arguments
if tool_name == "write_file": if tool_name == "write_file":
params = json.loads(tool_args) params = json.loads(tool_args)