minor context window fixes

frdel committed Nov 25, 2024 at 20:48 UTC ea9c8bf63bd6a460bf4b8001e39af48ce9f165ad
4 files changed +20 -17
agent.py
+3 -1
@@ -404,9 +404,11 @@ class Agent:
404 ): # if agent has custom folder, use it and use default as backup
405 prompt_dir = files.get_abs_path("prompts", self.config.prompts_subdir)
406 backup_dir.append(files.get_abs_path("prompts/default"))
407 - return files.read_file(
407 + prompt = files.read_file(
408 files.get_abs_path(prompt_dir, file), _backup_dirs=backup_dir, **kwargs
409 )
410 + prompt = files.remove_code_fences(prompt)
411 + return prompt
412
413 def get_data(self, field: str):
414 return self.data.get(field, None)
python/helpers/history.py
+1 -1
@@ -145,7 +145,7 @@ class Topic(Record):
145 for msg, tok, leng, out in large_msgs:
146 trim_to_chars = leng * (msg_max_size / tok)
147 trunc = messages.truncate_dict_by_ratio(
148 - self.history.agent, out, trim_to_chars * 1.15, trim_to_chars * 0.85
148 + self.history.agent, out["content"], trim_to_chars * 1.15, trim_to_chars * 0.85
149 )
150 msg.summary = trunc
151
python/helpers/settings.py
+14 -14
@@ -112,16 +112,6 @@ def convert_out(settings: Settings) -> SettingsOutput:
112 }
113 )
114
115 - chat_model_fields.append(
116 - {
117 - "id": "chat_model_kwargs",
118 - "title": "Chat model additional parameters",
119 - "description": "Any other parameters supported by the model. Format is KEY=VALUE on individual lines, just like .env file.",
120 - "type": "textarea",
121 - "value": _dict_to_env(settings["chat_model_kwargs"]),
122 - }
123 - )
124 -
115 chat_model_fields.append(
116 {
117 "id": "chat_model_ctx_length",
@@ -129,7 +119,8 @@ def convert_out(settings: Settings) -> SettingsOutput:
119 "description": "Maximum number of tokens in the context window for LLM. System prompt, chat history, RAG and response all count towards this limit.",
120 "type": "input",
121 "value": settings["chat_model_ctx_length"],
132 - })
122 + }
123 + )
124
125 chat_model_fields.append(
126 {
@@ -141,8 +132,18 @@ def convert_out(settings: Settings) -> SettingsOutput:
132 "max": 1,
133 "step": 0.01,
134 "value": settings["chat_model_ctx_history"],
144 - })
145 -
135 + }
136 + )
137 +
138 + chat_model_fields.append(
139 + {
140 + "id": "chat_model_kwargs",
141 + "title": "Chat model additional parameters",
142 + "description": "Any other parameters supported by the model. Format is KEY=VALUE on individual lines, just like .env file.",
143 + "type": "textarea",
144 + "value": _dict_to_env(settings["chat_model_kwargs"]),
145 + }
146 + )
147
148 chat_model_section: SettingsSection = {
149 "title": "Chat Model",
@@ -483,7 +484,6 @@ def normalize_settings(settings: Settings) -> Settings:
484 return copy
485
486
486 -
487 def get_chat_model(settings: Settings | None = None) -> BaseChatModel:
488 if not settings:
489 settings = get_settings()
webui/history.js
+2 -1
@@ -11,7 +11,7 @@ export async function openCtxWindowModal() {
11 const win = await window.sendJsonData("/ctx_window_get", { context: getContext() });
12 const data = win.content
13 const size = win.tokens
14 - await showEditorModal(data, "text", `Context window ~${size} tokens`,"Data passed to the LLM during last interaction. Contains system message, conversation history and RAG.");
14 + await showEditorModal(data, "markdown", `Context window ~${size} tokens`,"Data passed to the LLM during last interaction. Contains system message, conversation history and RAG.");
15 }
16
17 async function showEditorModal(data, type = "json", title, description="") {
@@ -33,6 +33,7 @@ async function showEditorModal(data, type = "json", title, description="") {
33
34 editor.session.setMode("ace/mode/" + type);
35 editor.setValue(data);
36 + editor.clearSelection();
37 // editor.session.$toggleFoldWidget(5, {})
38 }
39 }