Skip to content

Commit 4a55d47

Browse files
authored
Merge pull request #302 from hlo-world/num_ctx-for-ollama
feat: add num_ctx slider when provider is ollama and add predefined model names for ollama
2 parents 3fd3ab2 + f24668c commit 4a55d47

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

src/utils/default_config_settings.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def default_config():
1414
"tool_calling_method": "auto",
1515
"llm_provider": "openai",
1616
"llm_model_name": "gpt-4o",
17+
"llm_num_ctx": 32000,
1718
"llm_temperature": 1.0,
1819
"llm_base_url": "",
1920
"llm_api_key": "",
@@ -59,20 +60,21 @@ def save_current_config(*args):
5960
"tool_calling_method": args[4],
6061
"llm_provider": args[5],
6162
"llm_model_name": args[6],
62-
"llm_temperature": args[7],
63-
"llm_base_url": args[8],
64-
"llm_api_key": args[9],
65-
"use_own_browser": args[10],
66-
"keep_browser_open": args[11],
67-
"headless": args[12],
68-
"disable_security": args[13],
69-
"enable_recording": args[14],
70-
"window_w": args[15],
71-
"window_h": args[16],
72-
"save_recording_path": args[17],
73-
"save_trace_path": args[18],
74-
"save_agent_history_path": args[19],
75-
"task": args[20],
63+
"llm_num_ctx": args[7],
64+
"llm_temperature": args[8],
65+
"llm_base_url": args[9],
66+
"llm_api_key": args[10],
67+
"use_own_browser": args[11],
68+
"keep_browser_open": args[12],
69+
"headless": args[13],
70+
"disable_security": args[14],
71+
"enable_recording": args[15],
72+
"window_w": args[16],
73+
"window_h": args[17],
74+
"save_recording_path": args[18],
75+
"save_trace_path": args[19],
76+
"save_agent_history_path": args[20],
77+
"task": args[21],
7678
}
7779
return save_config_to_file(current_config)
7880

@@ -89,6 +91,7 @@ def update_ui_from_config(config_file):
8991
gr.update(value=loaded_config.get("tool_calling_method", True)),
9092
gr.update(value=loaded_config.get("llm_provider", "openai")),
9193
gr.update(value=loaded_config.get("llm_model_name", "gpt-4o")),
94+
gr.update(value=loaded_config.get("llm_num_ctx", 32000)),
9295
gr.update(value=loaded_config.get("llm_temperature", 1.0)),
9396
gr.update(value=loaded_config.get("llm_base_url", "")),
9497
gr.update(value=loaded_config.get("llm_api_key", "")),

src/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get_llm_model(provider: str, **kwargs):
167167
"openai": ["gpt-4o", "gpt-4", "gpt-3.5-turbo", "o3-mini"],
168168
"deepseek": ["deepseek-chat", "deepseek-reasoner"],
169169
"google": ["gemini-2.0-flash", "gemini-2.0-flash-thinking-exp", "gemini-1.5-flash-latest", "gemini-1.5-flash-8b-latest", "gemini-2.0-flash-thinking-exp-01-21", "gemini-2.0-pro-exp-02-05"],
170-
"ollama": ["qwen2.5:7b", "llama2:7b", "deepseek-r1:14b", "deepseek-r1:32b"],
170+
"ollama": ["qwen2.5:7b", "qwen2.5:14b", "qwen2.5:32b", "qwen2.5-coder:14b", "qwen2.5-coder:32b", "llama2:7b", "deepseek-r1:14b", "deepseek-r1:32b"],
171171
"azure_openai": ["gpt-4o", "gpt-4", "gpt-3.5-turbo"],
172172
"mistral": ["pixtral-large-latest", "mistral-large-latest", "mistral-small-latest", "ministral-8b-latest"],
173173
"alibaba": ["qwen-plus", "qwen-max", "qwen-turbo", "qwen-long"],

webui.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ async def run_browser_agent(
100100
agent_type,
101101
llm_provider,
102102
llm_model_name,
103+
llm_num_ctx,
103104
llm_temperature,
104105
llm_base_url,
105106
llm_api_key,
@@ -144,6 +145,7 @@ async def run_browser_agent(
144145
llm = utils.get_llm_model(
145146
provider=llm_provider,
146147
model_name=llm_model_name,
148+
num_ctx=llm_num_ctx,
147149
temperature=llm_temperature,
148150
base_url=llm_base_url,
149151
api_key=llm_api_key,
@@ -435,6 +437,7 @@ async def run_with_stream(
435437
agent_type,
436438
llm_provider,
437439
llm_model_name,
440+
llm_num_ctx,
438441
llm_temperature,
439442
llm_base_url,
440443
llm_api_key,
@@ -463,6 +466,7 @@ async def run_with_stream(
463466
agent_type=agent_type,
464467
llm_provider=llm_provider,
465468
llm_model_name=llm_model_name,
469+
llm_num_ctx=llm_num_ctx,
466470
llm_temperature=llm_temperature,
467471
llm_base_url=llm_base_url,
468472
llm_api_key=llm_api_key,
@@ -495,6 +499,7 @@ async def run_with_stream(
495499
agent_type=agent_type,
496500
llm_provider=llm_provider,
497501
llm_model_name=llm_model_name,
502+
llm_num_ctx=llm_num_ctx,
498503
llm_temperature=llm_temperature,
499504
llm_base_url=llm_base_url,
500505
llm_api_key=llm_api_key,
@@ -627,7 +632,7 @@ async def close_global_browser():
627632
await _global_browser.close()
628633
_global_browser = None
629634

630-
async def run_deep_search(research_task, max_search_iteration_input, max_query_per_iter_input, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key, use_vision, use_own_browser, headless):
635+
async def run_deep_search(research_task, max_search_iteration_input, max_query_per_iter_input, llm_provider, llm_model_name, llm_num_ctx, llm_temperature, llm_base_url, llm_api_key, use_vision, use_own_browser, headless):
631636
from src.utils.deep_research import deep_research
632637
global _global_agent_state
633638

@@ -637,6 +642,7 @@ async def run_deep_search(research_task, max_search_iteration_input, max_query_p
637642
llm = utils.get_llm_model(
638643
provider=llm_provider,
639644
model_name=llm_model_name,
645+
num_ctx=llm_num_ctx,
640646
temperature=llm_temperature,
641647
base_url=llm_base_url,
642648
api_key=llm_api_key,
@@ -740,6 +746,15 @@ def create_ui(config, theme_name="Ocean"):
740746
allow_custom_value=True, # Allow users to input custom model names
741747
info="Select a model from the dropdown or type a custom model name"
742748
)
749+
llm_num_ctx = gr.Slider(
750+
minimum=2**8,
751+
maximum=2**16,
752+
value=config['llm_num_ctx'],
753+
step=1,
754+
label="Max Context Length",
755+
info="Controls max context length model needs to handle (less = faster)",
756+
visible=config['llm_provider'] == "ollama"
757+
)
743758
llm_temperature = gr.Slider(
744759
minimum=0.0,
745760
maximum=2.0,
@@ -761,6 +776,17 @@ def create_ui(config, theme_name="Ocean"):
761776
info="Your API key (leave blank to use .env)"
762777
)
763778

779+
# Change event to update context length slider
780+
def update_llm_num_ctx_visibility(llm_provider):
781+
return gr.update(visible=llm_provider == "ollama")
782+
783+
# Bind the change event of llm_provider to update the visibility of context length slider
784+
llm_provider.change(
785+
fn=update_llm_num_ctx_visibility,
786+
inputs=llm_provider,
787+
outputs=llm_num_ctx
788+
)
789+
764790
with gr.TabItem("🌐 Browser Settings", id=3):
765791
with gr.Group():
766792
with gr.Row():
@@ -903,7 +929,7 @@ def create_ui(config, theme_name="Ocean"):
903929
run_button.click(
904930
fn=run_with_stream,
905931
inputs=[
906-
agent_type, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
932+
agent_type, llm_provider, llm_model_name, llm_num_ctx, llm_temperature, llm_base_url, llm_api_key,
907933
use_own_browser, keep_browser_open, headless, disable_security, window_w, window_h,
908934
save_recording_path, save_agent_history_path, save_trace_path, # Include the new path
909935
enable_recording, task, add_infos, max_steps, use_vision, max_actions_per_step, tool_calling_method
@@ -925,7 +951,7 @@ def create_ui(config, theme_name="Ocean"):
925951
# Run Deep Research
926952
research_button.click(
927953
fn=run_deep_search,
928-
inputs=[research_task_input, max_search_iteration_input, max_query_per_iter_input, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key, use_vision, use_own_browser, headless],
954+
inputs=[research_task_input, max_search_iteration_input, max_query_per_iter_input, llm_provider, llm_model_name, llm_num_ctx, llm_temperature, llm_base_url, llm_api_key, use_vision, use_own_browser, headless],
929955
outputs=[markdown_output_display, markdown_download, stop_research_button, research_button]
930956
)
931957
# Bind the stop button click event after errors_output is defined
@@ -991,7 +1017,7 @@ def list_recordings(save_recording_path):
9911017
inputs=[config_file_input],
9921018
outputs=[
9931019
agent_type, max_steps, max_actions_per_step, use_vision, tool_calling_method,
994-
llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
1020+
llm_provider, llm_model_name, llm_num_ctx, llm_temperature, llm_base_url, llm_api_key,
9951021
use_own_browser, keep_browser_open, headless, disable_security, enable_recording,
9961022
window_w, window_h, save_recording_path, save_trace_path, save_agent_history_path,
9971023
task, config_status
@@ -1002,7 +1028,7 @@ def list_recordings(save_recording_path):
10021028
fn=save_current_config,
10031029
inputs=[
10041030
agent_type, max_steps, max_actions_per_step, use_vision, tool_calling_method,
1005-
llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
1031+
llm_provider, llm_model_name, llm_num_ctx, llm_temperature, llm_base_url, llm_api_key,
10061032
use_own_browser, keep_browser_open, headless, disable_security,
10071033
enable_recording, window_w, window_h, save_recording_path, save_trace_path,
10081034
save_agent_history_path, task,

0 commit comments

Comments
 (0)