mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
ollama去除回复中的think字段 (#373)
* ollama调用修复,并且去除回复中的think字段(deepseek) * ollama调用修复,并且去除回复中的think字段(deepseek) * ollama去除回复中的think字段(deepseek) deepseek 14b,qwen2.5测试通过 * ollama去除回复中的think字段(deepseek) deepseek 14b,qwen2.5测试通过 * Update ollama.py --------- Co-authored-by: aileenfun <105077614@qq.com> Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com>
This commit is contained in:
parent
490a66d3fe
commit
7b1e17bf14
1 changed files with 13 additions and 6 deletions
|
|
@ -12,7 +12,7 @@ class LLMProvider(LLMProviderBase):
|
|||
self.model_name = config.get("model_name")
|
||||
self.base_url = config.get("base_url", "http://localhost:11434")
|
||||
# Initialize OpenAI client with Ollama base URL
|
||||
#如果没有v1,增加v1
|
||||
# 如果没有v1,增加v1
|
||||
if not self.base_url.endswith("/v1"):
|
||||
self.base_url = f"{self.base_url}/v1"
|
||||
|
||||
|
|
@ -28,13 +28,20 @@ class LLMProvider(LLMProviderBase):
|
|||
messages=dialogue,
|
||||
stream=True
|
||||
)
|
||||
|
||||
is_active=True
|
||||
for chunk in responses:
|
||||
try:
|
||||
delta = chunk.choices[0].delta if getattr(chunk, 'choices', None) else None
|
||||
content = delta.content if hasattr(delta, 'content') else ''
|
||||
if content:
|
||||
yield content
|
||||
if '<think>' in content:
|
||||
is_active = False
|
||||
content = content.split('<think>')[0]
|
||||
if '</think>' in content:
|
||||
is_active = True
|
||||
content = content.split('</think>')[-1]
|
||||
if is_active:
|
||||
yield content
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).error(f"Error processing chunk: {e}")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue