新增了火山引擎的选择。
This commit is contained in:
@@ -8,6 +8,8 @@ from google.genai import types
|
|||||||
from azure.ai.inference import ChatCompletionsClient
|
from azure.ai.inference import ChatCompletionsClient
|
||||||
from azure.core.credentials import AzureKeyCredential
|
from azure.core.credentials import AzureKeyCredential
|
||||||
from azure.ai.inference.models import SystemMessage, UserMessage
|
from azure.ai.inference.models import SystemMessage, UserMessage
|
||||||
|
from openai import OpenAI
|
||||||
|
|
||||||
|
|
||||||
def check_base_url(url: str) -> str:
|
def check_base_url(url: str) -> str:
|
||||||
"""
|
"""
|
||||||
@@ -266,6 +268,36 @@ class AzureAIAdapter(BaseLLMAdapter):
|
|||||||
logging.error(f"Azure AI Inference API 调用失败: {e}")
|
logging.error(f"Azure AI Inference API 调用失败: {e}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
# 火山引擎实现
|
||||||
|
class VolcanoEngineAIAdapter(BaseLLMAdapter):
|
||||||
|
def __init__(self, api_key: str, base_url: str, model_name: str, max_tokens: int, temperature: float = 0.7, timeout: Optional[int] = 600):
|
||||||
|
self.base_url = check_base_url(base_url)
|
||||||
|
self.api_key = api_key
|
||||||
|
self.model_name = model_name
|
||||||
|
self.max_tokens = max_tokens
|
||||||
|
self.temperature = temperature
|
||||||
|
self.timeout = timeout
|
||||||
|
|
||||||
|
self._client = OpenAI(
|
||||||
|
# 此为默认路径,您可根据业务所在地域进行配置
|
||||||
|
base_url="https://ark.cn-beijing.volces.com/api/v3/bots",
|
||||||
|
# 从环境变量中获取您的 API Key
|
||||||
|
api_key=api_key
|
||||||
|
)
|
||||||
|
def invoke(self, prompt: str) -> str:
|
||||||
|
response = self._client.chat.completions.create(
|
||||||
|
model=self.model_name, # bot-20250223190248-2bq5k 为您当前的智能体的ID,注意此处与Chat API存在差异。差异对比详见 SDK使用指南
|
||||||
|
messages=[
|
||||||
|
{"role": "system", "content": "你是DeepSeek,是一个 AI 人工智能助手"},
|
||||||
|
{"role": "user", "content": prompt},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
# response = self._client.invoke(prompt)
|
||||||
|
if not response:
|
||||||
|
logging.warning("No response from DeepSeekAdapter.")
|
||||||
|
return ""
|
||||||
|
return response.choices[0].message.content
|
||||||
|
|
||||||
def create_llm_adapter(
|
def create_llm_adapter(
|
||||||
interface_format: str,
|
interface_format: str,
|
||||||
base_url: str,
|
base_url: str,
|
||||||
@@ -296,5 +328,7 @@ def create_llm_adapter(
|
|||||||
return GeminiAdapter(api_key, model_name, max_tokens, temperature, timeout)
|
return GeminiAdapter(api_key, model_name, max_tokens, temperature, timeout)
|
||||||
elif fmt == "阿里云百炼":
|
elif fmt == "阿里云百炼":
|
||||||
return OpenAIAdapter(api_key, base_url, model_name, max_tokens, temperature, timeout)
|
return OpenAIAdapter(api_key, base_url, model_name, max_tokens, temperature, timeout)
|
||||||
|
elif fmt == "火山引擎":
|
||||||
|
return VolcanoEngineAIAdapter(api_key, base_url, model_name, max_tokens, temperature, timeout)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown interface_format: {interface_format}")
|
raise ValueError(f"Unknown interface_format: {interface_format}")
|
||||||
|
|||||||
+1
-1
@@ -108,7 +108,7 @@ def build_ai_config_tab(self):
|
|||||||
|
|
||||||
# 3) 接口格式
|
# 3) 接口格式
|
||||||
create_label_with_help(self, parent=self.ai_config_tab, label_text="LLM 接口格式:", tooltip_key="interface_format", row=2, column=0, font=("Microsoft YaHei", 12))
|
create_label_with_help(self, parent=self.ai_config_tab, label_text="LLM 接口格式:", tooltip_key="interface_format", row=2, column=0, font=("Microsoft YaHei", 12))
|
||||||
interface_options = ["DeepSeek", "阿里云百炼", "OpenAI", "Azure OpenAI", "Azure AI", "Ollama", "ML Studio", "Gemini"]
|
interface_options = ["DeepSeek", "阿里云百炼", "OpenAI", "Azure OpenAI", "Azure AI", "Ollama", "ML Studio", "Gemini","火山引擎"]
|
||||||
interface_dropdown = ctk.CTkOptionMenu(self.ai_config_tab, values=interface_options, variable=self.interface_format_var, command=on_interface_format_changed, font=("Microsoft YaHei", 12))
|
interface_dropdown = ctk.CTkOptionMenu(self.ai_config_tab, values=interface_options, variable=self.interface_format_var, command=on_interface_format_changed, font=("Microsoft YaHei", 12))
|
||||||
interface_dropdown.grid(row=2, column=1, padx=5, pady=5, columnspan=2, sticky="nsew")
|
interface_dropdown.grid(row=2, column=1, padx=5, pady=5, columnspan=2, sticky="nsew")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user