feat(llm): add thinking parameter support for Ollama API calls

Add optional thinking parameter to the call_ollama function and pass it from the request. Also enhance timezone handling in prompt generation to support configurable timezone preferences.
This commit is contained in:
2026-02-19 10:34:31 +08:00
parent aa6133e3ed
commit 065b4ac319
3 changed files with 41 additions and 22 deletions
+13 -8
View File
@@ -54,31 +54,36 @@ def _extract_message(response) -> tuple[str, str]:
return content, thinking
async def call_ollama(prompt: str, *, tag: str = "default", temperature: float = 0.7) -> dict:
async def call_ollama(prompt: str, *, tag: str = "default", temperature: float = 0.7, thinking: str = None) -> dict:
"""
调用 Ollama API 并返回 content 和 thinking。
"""
start = time.perf_counter()
start_dt = datetime.now()
logger.info(
"[LLM][%s] request model=%s host=%s prompt_chars=%d temp=%.2f",
"[LLM][%s] request model=%s host=%s prompt_chars=%d temp=%.2f thinking=%s",
tag,
OLLAMA_MODEL,
OLLAMA_HOST,
len(prompt),
temperature,
thinking,
)
try:
response = await client.chat(
model=OLLAMA_MODEL,
messages=[{'role': 'user', 'content': prompt}],
stream=False,
options={
kwargs = {
"model": OLLAMA_MODEL,
"messages": [{'role': 'user', 'content': prompt}],
"stream": False,
"options": {
'temperature': temperature,
'repeat_penalty': 1.1,
},
)
}
if thinking:
kwargs["thinking"] = thinking
response = await client.chat(**kwargs)
except Exception:
elapsed_ms = (time.perf_counter() - start) * 1000
end_dt = datetime.now()