更新环境变量配置,调整模型名称获取方式,新增Dify API相关配置,删除无用的脚本文件,优化意图识别逻辑,添加LLM提取词条逻辑
This commit is contained in:
@@ -236,7 +236,7 @@ class OpenAiLLM:
|
||||
self._model = kwargs.get("model")
|
||||
kwargs.pop("model")
|
||||
else:
|
||||
self._model = os.getenv("LLM_MODEL_NAME")
|
||||
self._model = os.getenv("MODEL_NAME")
|
||||
|
||||
self._kwargs = kwargs
|
||||
|
||||
@@ -284,13 +284,19 @@ class OpenAiLLM:
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"OpenAiLLM:invoke:error:{str(e)}.api_key:{api_key}") from e
|
||||
|
||||
async def invoke_async(self, user_prompt="你是谁?", need_retry=True):
|
||||
async def invoke_async(self, user_prompt="你是谁?", need_retry=True, **extra_kwargs):
|
||||
"""异步调用OpenAI API"""
|
||||
max_retries = 3
|
||||
retry_count = 0
|
||||
if "timeout" not in self._kwargs:
|
||||
|
||||
# 合并额外的kwargs与self._kwargs
|
||||
kwargs = {**self._kwargs}
|
||||
if extra_kwargs:
|
||||
kwargs.update(extra_kwargs)
|
||||
|
||||
if "timeout" not in kwargs:
|
||||
timeout = httpx.Timeout(300.0)
|
||||
self._kwargs["timeout"] = timeout
|
||||
kwargs["timeout"] = timeout
|
||||
|
||||
if need_retry:
|
||||
while retry_count < max_retries:
|
||||
@@ -302,7 +308,7 @@ class OpenAiLLM:
|
||||
completion = await client.chat.completions.create(
|
||||
model=self._model,
|
||||
messages=[{'role': 'user', 'content': user_prompt}],
|
||||
**self._kwargs
|
||||
**kwargs
|
||||
)
|
||||
return completion.choices[0].message
|
||||
|
||||
@@ -319,7 +325,7 @@ class OpenAiLLM:
|
||||
completion = await client.chat.completions.create(
|
||||
model=self._model,
|
||||
messages=[{'role': 'user', 'content': user_prompt}],
|
||||
**self._kwargs
|
||||
**kwargs
|
||||
)
|
||||
return completion.choices[0].message
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user