Browse Source

Merge pull request #1 from henryclw/ollama

Pass the temperature and top p parameters to ollama backend correctly
pull/424/head
Henry 6 months ago committed by GitHub
parent
commit
4960778a6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      installer/client/cli/utils.py

20
installer/client/cli/utils.py

@ -63,12 +63,15 @@ class Standalone:
self.google = self.model in googleList
async def localChat(self, messages, host=''):
from ollama import AsyncClient
from ollama import AsyncClient, Options
response = None
if host:
response = await AsyncClient(host=host).chat(model=self.model, messages=messages)
response = await AsyncClient(host=host).chat(model=self.model, messages=messages,
options=Options(temperature=self.args.temp,
top_p=self.args.top_p))
else:
response = await AsyncClient().chat(model=self.model, messages=messages)
response = await AsyncClient().chat(model=self.model, messages=messages,
options=Options(temperature=self.args.temp, top_p=self.args.top_p))
print(response['message']['content'])
copy = self.args.copy
if copy:
@ -78,14 +81,19 @@ class Standalone:
f.write(response['message']['content'])
async def localStream(self, messages, host=''):
from ollama import AsyncClient
from ollama import AsyncClient, Options
buffer = ""
if host:
async for part in await AsyncClient(host=host).chat(model=self.model, messages=messages, stream=True):
# local ollama with stream and spec host
async for part in await AsyncClient(host=host).chat(model=self.model, messages=messages, stream=True,
options=Options(temperature=self.args.temp,
top_p=self.args.top_p)):
buffer += part['message']['content']
print(part['message']['content'], end='', flush=True)
else:
async for part in await AsyncClient().chat(model=self.model, messages=messages, stream=True):
async for part in await AsyncClient().chat(model=self.model, messages=messages, stream=True,
options=Options(temperature=self.args.temp,
top_p=self.args.top_p)):
buffer += part['message']['content']
print(part['message']['content'], end='', flush=True)
if self.args.output:

Loading…
Cancel
Save