Skip to content

Commit b65f4b0

Browse files
Allow user to select model from the assistant setup page
1 parent 06ddac2 commit b65f4b0

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

routers/setup.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,25 @@ async def read_setup(
5252
status: Optional[str] = None,
5353
message_text: Optional[str] = None
5454
) -> Response:
55-
# Check if assistant ID is missing
56-
current_tools = []
57-
setup_message = "" # Message specific to setup state (e.g., API key missing)
55+
# Variable initializations
56+
current_tools: List[str] = []
57+
current_model: Optional[str] = None
58+
# Populate with all models extracted from user-provided HTML, sorted
59+
available_models: List[str] = sorted([
60+
"gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k",
61+
"gpt-4", "gpt-4-0125-preview", "gpt-4-0613", "gpt-4-1106-preview",
62+
"gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-turbo-preview",
63+
"gpt-4.1", "gpt-4.1-2025-04-14", "gpt-4.1-mini", "gpt-4.1-mini-2025-04-14",
64+
"gpt-4.1-nano", "gpt-4.1-nano-2025-04-14",
65+
"gpt-4.5-preview", "gpt-4.5-preview-2025-02-27",
66+
"gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-2024-11-20",
67+
"gpt-4o-mini", "gpt-4o-mini-2024-07-18",
68+
"o1", "o1-2024-12-17",
69+
"o3-mini", "o3-mini-2025-01-31"
70+
])
71+
setup_message: str = ""
72+
73+
# Check if env variables are set
5874
load_dotenv(override=True)
5975
openai_api_key = os.getenv("OPENAI_API_KEY")
6076
assistant_id = os.getenv("ASSISTANT_ID")
@@ -67,6 +83,7 @@ async def read_setup(
6783
try:
6884
assistant = await client.beta.assistants.retrieve(assistant_id)
6985
current_tools = [tool.type for tool in assistant.tools]
86+
current_model = assistant.model # Get the model from the assistant
7087
except Exception as e:
7188
logger.error(f"Failed to retrieve assistant {assistant_id}: {e}")
7289
# If we can't retrieve the assistant, proceed as if it doesn't exist
@@ -81,14 +98,17 @@ async def read_setup(
8198
"status": status, # Pass status from query params
8299
"status_message": message_text, # Pass message from query params
83100
"assistant_id": assistant_id,
84-
"current_tools": current_tools
101+
"current_tools": current_tools,
102+
"current_model": current_model,
103+
"available_models": available_models # Pass available models to template
85104
}
86105
)
87106

88107

89108
@router.post("/assistant")
90109
async def create_update_assistant(
91110
tool_types: List[ToolTypes] = Form(...),
111+
model: str = Form(...),
92112
client: AsyncOpenAI = Depends(lambda: AsyncOpenAI())
93113
) -> RedirectResponse:
94114
"""
@@ -101,6 +121,7 @@ async def create_update_assistant(
101121
client=client,
102122
assistant_id=current_assistant_id,
103123
tool_types=tool_types,
124+
model=model,
104125
logger=logger
105126
)
106127

templates/setup.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,28 @@ <h3>Setup Required</h3>
3232
{% else %} {# Covers missing assistant ID or user wants to update #}
3333
<div class="setupSection">
3434
{% if assistant_id %}<h3>Update Assistant</h3>{% else %}<h3>Create Assistant</h3>{% endif %}
35-
<p class="setupMessage">Select tools for your assistant:</p>
35+
3636
<form action="{{ url_for('create_update_assistant') }}" method="POST">
37+
<div>
38+
<label for="model-select">Select Model:</label>
39+
<select name="model" id="model-select" class="input" required>
40+
{% if available_models %}
41+
{% for model_id in available_models %}
42+
<option value="{{ model_id }}" {% if model_id == current_model %}selected{% endif %}>{{ model_id }}</option>
43+
{% endfor %}
44+
{% else %}
45+
<option value="" disabled>Could not load models</option>
46+
{# Optionally include a default fallback if loading fails #}
47+
{% if current_model %}
48+
<option value="{{ current_model }}" selected>{{ current_model }} (current)</option>
49+
{% else %}
50+
<option value="gpt-4o" selected>gpt-4o (default)</option> {# Default fallback #}
51+
{% endif %}
52+
{% endif %}
53+
</select>
54+
</div>
55+
56+
<p class="setupMessage" style="margin-top: 15px;">Select tools for your assistant:</p>
3757
<div>
3858
<label>
3959
<input type="checkbox" name="tool_types" value="code_interpreter" {% if "code_interpreter" in current_tools %}checked{% endif %}>

utils/create_assistant.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ async def create_or_update_assistant(
6969
client: AsyncOpenAI,
7070
assistant_id: str | None,
7171
tool_types: List[ToolTypes],
72+
model: str,
7273
logger: logging.Logger
7374
) -> str | None:
7475
"""
@@ -83,7 +84,7 @@ async def create_or_update_assistant(
8384
assistant_id,
8485
instructions="You are a helpful assistant.",
8586
name="Quickstart Assistant",
86-
model="gpt-4o",
87+
model=model,
8788
tools=tool_params
8889
)
8990
logger.info(f"Updated assistant with ID: {assistant_id}")
@@ -92,7 +93,7 @@ async def create_or_update_assistant(
9293
assistant = await client.beta.assistants.create(
9394
instructions="You are a helpful assistant.",
9495
name="Quickstart Assistant",
95-
model="gpt-4o",
96+
model=model,
9697
tools=tool_params
9798
)
9899
logger.info(f"Created new assistant: {assistant.id}")

0 commit comments

Comments
 (0)