fix regressions in system prompt handling (#2219)

* python: fix system prompt being ignored
* fix unintended whitespace after system prompt

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel
2024-04-15 11:39:48 -04:00
committed by GitHub
parent 2273cf145e
commit ac498f79ac
4 changed files with 12 additions and 19 deletions

View File

@@ -497,16 +497,16 @@ class GPT4All:
if self._history is not None:
# check if there is only one message, i.e. system prompt:
reset = len(self._history) == 1
generate_kwargs["reset_context"] = reset
self._history.append({"role": "user", "content": prompt})
fct_func = self._format_chat_prompt_template.__func__ # type: ignore[attr-defined]
if fct_func is GPT4All._format_chat_prompt_template:
if reset:
# ingest system prompt
self.model.prompt_model(self._history[0]["content"], "%1",
# use "%1%2" and not "%1" to avoid implicit whitespace
self.model.prompt_model(self._history[0]["content"], "%1%2",
empty_response_callback,
n_batch=n_batch, n_predict=0, special=True)
n_batch=n_batch, n_predict=0, reset_context=True, special=True)
prompt_template = self._current_prompt_template.format("%1", "%2")
else:
warnings.warn(
@@ -519,6 +519,7 @@ class GPT4All:
self._history[0]["content"] if reset else "",
)
prompt_template = "%1"
generate_kwargs["reset_context"] = reset
else:
prompt_template = "%1"
generate_kwargs["reset_context"] = True

View File

@@ -68,7 +68,7 @@ def get_long_description():
setup(
name=package_name,
version="2.5.1",
version="2.5.2",
description="Python bindings for GPT4All",
long_description=get_long_description(),
long_description_content_type="text/markdown",