Skip to content

Commit bd27b33

Browse files
Allow user to customize system prompt from setup.html
1 parent 14747dc commit bd27b33

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

routers/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async def read_setup(
5555
# Variable initializations
5656
current_tools: List[str] = []
5757
current_model: Optional[str] = None
58+
current_instructions: Optional[str] = None
5859
# Populate with all models extracted from user-provided HTML, sorted
5960
available_models: List[str] = sorted([
6061
"gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k",
@@ -84,6 +85,7 @@ async def read_setup(
8485
assistant = await client.beta.assistants.retrieve(assistant_id)
8586
current_tools = [tool.type for tool in assistant.tools]
8687
current_model = assistant.model # Get the model from the assistant
88+
current_instructions = assistant.instructions # Get instructions
8789
except Exception as e:
8890
logger.error(f"Failed to retrieve assistant {assistant_id}: {e}")
8991
# If we can't retrieve the assistant, proceed as if it doesn't exist
@@ -100,6 +102,7 @@ async def read_setup(
100102
"assistant_id": assistant_id,
101103
"current_tools": current_tools,
102104
"current_model": current_model,
105+
"current_instructions": current_instructions,
103106
"available_models": available_models # Pass available models to template
104107
}
105108
)
@@ -109,6 +112,7 @@ async def read_setup(
109112
async def create_update_assistant(
110113
tool_types: List[ToolTypes] = Form(...),
111114
model: str = Form(...),
115+
instructions: str = Form(...),
112116
client: AsyncOpenAI = Depends(lambda: AsyncOpenAI())
113117
) -> RedirectResponse:
114118
"""
@@ -122,6 +126,7 @@ async def create_update_assistant(
122126
assistant_id=current_assistant_id,
123127
tool_types=tool_types,
124128
model=model,
129+
instructions=instructions,
125130
logger=logger
126131
)
127132

static/styles.css

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pre {
173173
display: flex;
174174
flex-direction: column;
175175
justify-content: center;
176-
align-items: center;
176+
align-items: flex-start;
177177
width: 100%;
178178
height: 100%;
179179
padding: 20px;
@@ -188,7 +188,7 @@ pre {
188188
display: flex;
189189
flex-direction: column;
190190
gap: 12px;
191-
align-items: center;
191+
align-items: flex-start;
192192
width: 100%;
193193
}
194194

@@ -622,7 +622,7 @@ pre {
622622
.setupSection form {
623623
display: flex;
624624
flex-direction: column;
625-
align-items: center; /* Center form elements */
625+
align-items: flex-start; /* Changed from center to flex-start */
626626
gap: 20px;
627627
width: 100%;
628628
}
@@ -633,7 +633,7 @@ pre {
633633
flex-direction: column;
634634
align-items: flex-start; /* Align labels to the left */
635635
gap: 10px; /* Vertical gap between labels */
636-
width: auto; /* Fit content width */
636+
width: 100%; /* Changed from auto to 100% */
637637
margin-bottom: 1rem; /* Restore some margin below the group */
638638
}
639639

@@ -651,6 +651,14 @@ pre {
651651
margin-bottom: 8px;
652652
}
653653

654+
#file-list-container {
655+
display: flex;
656+
flex-direction: column;
657+
align-items: flex-start;
658+
gap: 20px;
659+
width: 100%;
660+
}
661+
654662
.fileList {
655663
list-style: none;
656664
padding: 0;
@@ -699,3 +707,13 @@ pre {
699707
margin-left: 10px;
700708
font-style: italic;
701709
}
710+
711+
/* Original selector: .centered-button-container */
712+
/* New selector increases specificity to override .setupSection form > div */
713+
.setupSection form .centered-button-container {
714+
display: flex;
715+
justify-content: center; /* Center button horizontally */
716+
align-items: center; /* Center button vertically (good practice) */
717+
width: 100%;
718+
margin-top: 10px; /* Optional: add some space above the button */
719+
}

templates/components/file-viewer.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ <h3>Upload Files</h3>
88
enctype="multipart/form-data">
99
<input type="file" name="file" required>
1010
<input type="hidden" name="purpose" value="assistants">
11-
<button type="submit" class="button">Upload File</button>
12-
<span id="upload-indicator" class="htmx-indicator">Uploading...</span>
11+
<div class="centered-button-container">
12+
<button type="submit" class="button">Upload File</button>
13+
<span id="upload-indicator" class="htmx-indicator">Uploading...</span>
14+
</div>
1315
</form>
1416

1517
<h3>Existing Files</h3>

templates/setup.html

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ <h3>Setup Required</h3>
5353
</select>
5454
</div>
5555

56+
<div style="margin-top: 15px;">
57+
<label for="instructions-input">System Prompt:</label>
58+
<textarea
59+
name="instructions"
60+
id="instructions-input"
61+
class="input"
62+
rows="4"
63+
placeholder="e.g., You are a helpful assistant."
64+
style="width: 100%; resize: none;"
65+
>{% if current_instructions %}{{ current_instructions }}{% else %}You are a helpful assistant.{% endif %}</textarea>
66+
</div>
67+
5668
<p class="setupMessage" style="margin-top: 15px;">Select tools for your assistant:</p>
5769
<div>
5870
<label>
@@ -68,12 +80,14 @@ <h3>Setup Required</h3>
6880
Get Weather (Custom Function)
6981
</label>
7082
</div>
71-
<button
72-
type="submit"
73-
class="button"
74-
>
75-
{% if assistant_id %}Update{% else %}Create{% endif %} Assistant
76-
</button>
83+
<div class="centered-button-container">
84+
<button
85+
type="submit"
86+
class="button"
87+
>
88+
{% if assistant_id %}Update{% else %}Create{% endif %} Assistant
89+
</button>
90+
</div>
7791
</form>
7892
</div>
7993
{% if assistant_id and "file_search" in current_tools %}

utils/create_assistant.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ async def create_or_update_assistant(
7070
assistant_id: str | None,
7171
tool_types: List[ToolTypes],
7272
model: str,
73+
instructions: str,
7374
logger: logging.Logger
7475
) -> str | None:
7576
"""
@@ -82,7 +83,7 @@ async def create_or_update_assistant(
8283
# Update the existing assistant
8384
assistant = await client.beta.assistants.update(
8485
assistant_id,
85-
instructions="You are a helpful assistant.",
86+
instructions=instructions,
8687
name="Quickstart Assistant",
8788
model=model,
8889
tools=tool_params
@@ -91,7 +92,7 @@ async def create_or_update_assistant(
9192
else:
9293
# Create a new assistant
9394
assistant = await client.beta.assistants.create(
94-
instructions="You are a helpful assistant.",
95+
instructions=instructions,
9596
name="Quickstart Assistant",
9697
model=model,
9798
tools=tool_params

0 commit comments

Comments
 (0)