Testing with qwen and updating tools
This commit is contained in:
@@ -8,16 +8,16 @@ from openai import OpenAI
|
||||
class ChatGPTTelegramInferenceBot(BaseTelegramInferenceBot):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
||||
self.model = "gpt-4o-mini"
|
||||
self.max_tokens = 16384
|
||||
self.client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"), base_url="http://localhost:1234/v1")
|
||||
self.model = "qwen3-1.7b"
|
||||
self.max_tokens = 32768
|
||||
|
||||
def get_chat_response(self, messages):
|
||||
response = self.client.chat.completions.create(
|
||||
model=self.model,
|
||||
messages=[{"role": "system", "content": self.system_prompt}] + messages,
|
||||
functions=self.functions,
|
||||
function_call="auto",
|
||||
tools=self.functions,
|
||||
tool_choice = "auto",
|
||||
max_tokens=self.max_tokens
|
||||
)
|
||||
return response
|
||||
@@ -34,8 +34,8 @@ class ChatGPTTelegramInferenceBot(BaseTelegramInferenceBot):
|
||||
tool_calls = []
|
||||
|
||||
for message_part in response.choices:
|
||||
if message_part.finish_reason == "function_call":
|
||||
tool_calls.append(message_part.message.function_call)
|
||||
if message_part.finish_reason == "tool_calls":
|
||||
tool_calls.extend(message_part.message.tool_calls)
|
||||
|
||||
messages.append(response.choices[0].message)
|
||||
|
||||
@@ -44,9 +44,13 @@ class ChatGPTTelegramInferenceBot(BaseTelegramInferenceBot):
|
||||
tool_use_results = []
|
||||
|
||||
while len(tool_calls) > 0:
|
||||
tool_call = tool_calls.pop(0)
|
||||
tool_call = tool_calls.pop(0).function
|
||||
tool_response = self.call_tool(tool_call.name, tool_call.arguments)
|
||||
tool_use_results.append({"role": "function", "name": tool_call.name, "content": json.dumps(tool_response)})
|
||||
try:
|
||||
tool_use_results.append({"role": "tool", "name": tool_call.name, "content": tool_response})
|
||||
except (TypeError, ValueError) as e:
|
||||
logging.error(f"Failed to serialize tool response: {e}")
|
||||
tool_use_results.append({"role": "function", "name": tool_call.name, "content": "Serialization error"})
|
||||
|
||||
messages.extend(tool_use_results)
|
||||
|
||||
@@ -84,12 +88,12 @@ class ChatGPTTelegramInferenceBot(BaseTelegramInferenceBot):
|
||||
return "No active processing to abort."
|
||||
|
||||
async def switch_model(self):
|
||||
if self.model == "gpt-4o-mini":
|
||||
self.model = "gpt-4o"
|
||||
self.max_tokens = 4096
|
||||
if self.model == "qwen3-4b":
|
||||
self.model = "qwen3-30b-a3b"
|
||||
# self.max_tokens = 4096
|
||||
else:
|
||||
self.model = "gpt-4o-mini"
|
||||
self.max_tokens = 16384
|
||||
self.model = "qwen3-4b"
|
||||
# self.max_tokens = 16384
|
||||
logging.info(f"Switched to model: {self.model}")
|
||||
return f"Switched to model: {self.model}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user