diff --git a/.env.example b/.env.example index d99f3580..e16219af 100644 --- a/.env.example +++ b/.env.example @@ -30,6 +30,9 @@ UNBOUND_API_KEY= SiliconFLOW_ENDPOINT=https://api.siliconflow.cn/v1/ SiliconFLOW_API_KEY= +LOCAL_ENDPOINT=http://localhost:8000/v1 +LOCAL_API_KEY= + # Set to false to disable anonymized telemetry ANONYMIZED_TELEMETRY=false diff --git a/src/agent/custom_agent.py b/src/agent/custom_agent.py index 4b0eff39..3817e4e3 100644 --- a/src/agent/custom_agent.py +++ b/src/agent/custom_agent.py @@ -7,6 +7,7 @@ import os import base64 import io +import re import asyncio import time import platform @@ -223,6 +224,7 @@ async def get_next_action(self, input_messages: list[BaseMessage]) -> AgentOutpu ai_content = ai_message.content try: + ai_content = re.sub(r".*?", "", ai_content, flags=re.DOTALL).strip() ai_content = ai_content.replace("```json", "").replace("```", "") ai_content = repair_json(ai_content) parsed_json = json.loads(ai_content) diff --git a/src/utils/utils.py b/src/utils/utils.py index 62fc8a8e..40b83c3f 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -24,7 +24,8 @@ "google": "Google", "alibaba": "Alibaba", "moonshot": "MoonShot", - "unbound": "Unbound AI" + "unbound": "Unbound AI", + "local": "Local Model" } @@ -180,7 +181,22 @@ def get_llm_model(provider: str, **kwargs): return ChatOpenAI( api_key=api_key, base_url=base_url, - model_name=kwargs.get("model_name", "Qwen/QwQ-32B"), + model=kwargs.get("model_name", "Qwen/QwQ-32B"), + temperature=kwargs.get("temperature", 0.0), + ) + elif provider == "local": + if not kwargs.get("api_key", ""): + api_key = os.getenv("LOCAL_API_KEY", "") + else: + api_key = kwargs.get("api_key") + if not kwargs.get("base_url", ""): + base_url = os.getenv("LOCAL_ENDPOINT", "") + else: + base_url = kwargs.get("base_url") + return ChatOpenAI( + api_key=api_key, + base_url=base_url, + model=kwargs.get("model_name", ""), temperature=kwargs.get("temperature", 0.0), ) else: @@ -201,6 +217,7 @@ def get_llm_model(provider: str, **kwargs): "alibaba": ["qwen-plus", "qwen-max", "qwen-turbo", "qwen-long"], "moonshot": ["moonshot-v1-32k-vision-preview", "moonshot-v1-8k-vision-preview"], "unbound": ["gemini-2.0-flash", "gpt-4o-mini", "gpt-4o", "gpt-4.5-preview"], + "local": ["local-model"], "siliconflow": [ "deepseek-ai/DeepSeek-R1", "deepseek-ai/DeepSeek-V3",