Refa: ollama keep alive issue. (#8216)

### What problem does this PR solve?

#8122

### Type of change

- [x] Refactoring
This commit is contained in:
Kevin Hu 2025-06-12 15:09:40 +08:00 committed by GitHub
parent e7c85e569b
commit d5236b71f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -871,7 +871,7 @@ class OllamaChat(Base):
ctx_size = self._calculate_dynamic_ctx(history) ctx_size = self._calculate_dynamic_ctx(history)
gen_conf["num_ctx"] = ctx_size gen_conf["num_ctx"] = ctx_size
response = self.client.chat(model=self.model_name, messages=history, options=gen_conf) response = self.client.chat(model=self.model_name, messages=history, options=gen_conf, keep_alive=-1)
ans = response["message"]["content"].strip() ans = response["message"]["content"].strip()
token_count = response.get("eval_count", 0) + response.get("prompt_eval_count", 0) token_count = response.get("eval_count", 0) + response.get("prompt_eval_count", 0)
return ans, token_count return ans, token_count
@ -898,7 +898,7 @@ class OllamaChat(Base):
ans = "" ans = ""
try: try:
response = self.client.chat(model=self.model_name, messages=history, stream=True, options=options) response = self.client.chat(model=self.model_name, messages=history, stream=True, options=options, keep_alive=-1)
for resp in response: for resp in response:
if resp["done"]: if resp["done"]:
token_count = resp.get("prompt_eval_count", 0) + resp.get("eval_count", 0) token_count = resp.get("prompt_eval_count", 0) + resp.get("eval_count", 0)

View File

@ -506,7 +506,8 @@ class OllamaCV(Base):
response = self.client.chat( response = self.client.chat(
model=self.model_name, model=self.model_name,
messages=history, messages=history,
options=options options=options,
keep_alive=-1
) )
ans = response["message"]["content"].strip() ans = response["message"]["content"].strip()
@ -536,7 +537,8 @@ class OllamaCV(Base):
model=self.model_name, model=self.model_name,
messages=history, messages=history,
stream=True, stream=True,
options=options options=options,
keep_alive=-1
) )
for resp in response: for resp in response:
if resp["done"]: if resp["done"]: