From 1147b50a0ce9c9930517749151cf7ee95d30048d Mon Sep 17 00:00:00 2001 From: Henry <97804910+henryclw@users.noreply.github.com> Date: Sat, 25 May 2024 12:14:28 -0700 Subject: [PATCH 1/2] Pass the temperature and top p parameters to ollama backend correctly --- installer/client/cli/utils.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/installer/client/cli/utils.py b/installer/client/cli/utils.py index 9e7cea2..ac8e4b4 100644 --- a/installer/client/cli/utils.py +++ b/installer/client/cli/utils.py @@ -63,12 +63,16 @@ 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 +82,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: From d81ee84b32b4235dcc959720fc4fe4bd38c08e81 Mon Sep 17 00:00:00 2001 From: Henry <97804910+henryclw@users.noreply.github.com> Date: Sat, 25 May 2024 12:23:57 -0700 Subject: [PATCH 2/2] Fix format in utils.py --- installer/client/cli/utils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/installer/client/cli/utils.py b/installer/client/cli/utils.py index ac8e4b4..5f67c06 100644 --- a/installer/client/cli/utils.py +++ b/installer/client/cli/utils.py @@ -67,12 +67,11 @@ class Standalone: response = None if host: response = await AsyncClient(host=host).chat(model=self.model, messages=messages, - options=Options(temperature=self.args.temp, - top_p=self.args.top_p)) + options=Options(temperature=self.args.temp, + top_p=self.args.top_p)) else: response = await AsyncClient().chat(model=self.model, messages=messages, - options=Options(temperature=self.args.temp, - top_p=self.args.top_p)) + options=Options(temperature=self.args.temp, top_p=self.args.top_p)) print(response['message']['content']) copy = self.args.copy if copy: @@ -87,8 +86,8 @@ class Standalone: if host: # 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)): + options=Options(temperature=self.args.temp, + top_p=self.args.top_p)): buffer += part['message']['content'] print(part['message']['content'], end='', flush=True) else: