新增了火山引擎的选择。
This commit is contained in:
@@ -8,6 +8,8 @@ from google.genai import types
|
||||
from azure.ai.inference import ChatCompletionsClient
|
||||
from azure.core.credentials import AzureKeyCredential
|
||||
from azure.ai.inference.models import SystemMessage, UserMessage
|
||||
from openai import OpenAI
|
||||
|
||||
|
||||
def check_base_url(url: str) -> str:
|
||||
"""
|
||||
@@ -266,6 +268,36 @@ class AzureAIAdapter(BaseLLMAdapter):
|
||||
logging.error(f"Azure AI Inference API 调用失败: {e}")
|
||||
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(
|
||||
interface_format: str,
|
||||
base_url: str,
|
||||
@@ -296,5 +328,7 @@ def create_llm_adapter(
|
||||
return GeminiAdapter(api_key, model_name, max_tokens, temperature, timeout)
|
||||
elif fmt == "阿里云百炼":
|
||||
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:
|
||||
raise ValueError(f"Unknown interface_format: {interface_format}")
|
||||
|
||||
Reference in New Issue
Block a user