Skip to content

Commit

Permalink
Refactor code after running make check. Update documentation with c…
Browse files Browse the repository at this point in the history
…orrect settings field.
  • Loading branch information
aly-shehata committed Dec 8, 2023
1 parent 394a955 commit 626a9e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
5 changes: 2 additions & 3 deletions fern/docs/pages/manual/ui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ Normal chat interface, self-explanatory ;)
You can view and change the system prompt being passed to the LLM by clicking "Additional Inputs"
in the chat interface. The system prompt is also logged on the server.

By default, the `Query Docs` mode uses the setting value `local.default_query_system_prompt`.
By default, the `Query Docs` mode uses the setting value `ui.default_query_system_prompt`.

The `LLM Chat` mode attempts to use the optional settings value `local.default_chat_system_prompt`,
falling back to the default system prompt defined in the llama_index.
The `LLM Chat` mode attempts to use the optional settings value `ui.default_chat_system_prompt`.

If no system prompt is entered, the UI will display the default system prompt being used
for the active mode.
Expand Down
7 changes: 2 additions & 5 deletions private_gpt/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,9 @@ class LocalSettings(BaseModel):
"Also note that this is only used if the first message is not a system message. "
),
)
default_query_system_prompt: str | None = Field(
default_query_system_prompt: str = Field(
None,
description=(
"The default system prompt to use for the query mode. "
# TODO - document what can be used as default query system prompt
),
description="The default system prompt to use for the query mode. ",
)


Expand Down
21 changes: 11 additions & 10 deletions private_gpt/ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def build_history() -> list[ChatMessage]:
ChatMessage(
content=self._system_prompt,
role=MessageRole.SYSTEM,
)
),
)
match mode:
case "Query Docs":
Expand Down Expand Up @@ -169,23 +169,26 @@ def _get_default_system_prompt(mode: str) -> str:
p = settings().local.default_query_system_prompt
# For chat mode, obtain default system prompt from settings or llama_utils
case "LLM Chat":
p = settings().local.default_chat_system_prompt or llama_utils.DEFAULT_SYSTEM_PROMPT
p = (
settings().local.default_chat_system_prompt
or llama_utils.DEFAULT_SYSTEM_PROMPT
)
# For any other mode, clear the system prompt
case _:
p = ""
return p

def _set_system_prompt(self, system_prompt_input: str) -> None:
logger.info("Setting system prompt to: {}".format(system_prompt_input))
logger.info(f"Setting system prompt to: {system_prompt_input}")
self._system_prompt = system_prompt_input

def _set_current_mode(self, mode: str) -> dict:
def _set_current_mode(self, mode: str) -> Any:
self.mode = mode
self._set_system_prompt(self._get_default_system_prompt(mode))
# Update Textbox placeholder and allow interaction if a default system prompt is present
# Update placeholder and allow interaction if default system prompt is set
if self._system_prompt:
return gr.update(placeholder=self._system_prompt, interactive=True)
# Update Textbox placeholder and disable interaction if no default system prompt is present
# Update placeholder and disable interaction if no default system prompt is set
else:
return gr.update(placeholder=self._system_prompt, interactive=False)

Expand Down Expand Up @@ -260,13 +263,11 @@ def _build_ui_blocks(self) -> gr.Blocks:
label="System Prompt",
lines=2,
interactive=True,
render=False
render=False,
)
# When mode changes, set default system prompt
mode.change(
self._set_current_mode,
inputs=mode,
outputs=system_prompt_input
self._set_current_mode, inputs=mode, outputs=system_prompt_input
)
# On blur, set system prompt to use in queries
system_prompt_input.blur(
Expand Down

0 comments on commit 626a9e0

Please sign in to comment.