Skip to content

Commit a0204c7

Browse files
committed
refactor: Dockerfile
1 parent 887d7d0 commit a0204c7

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Use the official Python image from the Docker Hub.
22
# This runs on Debian Linux.
3-
FROM python:3.13-slim-trixie
3+
FROM python:3.13-slim-trixie AS base
4+
5+
6+
FROM base AS requirements
47

58
# Set the working directory to /app
69
WORKDIR /dist
710

811
# Copy the current directory contents into the container at /app
9-
COPY app /dist/app
1012
COPY requirements/prod.txt requirements.txt
1113

1214
# Set environment variables
@@ -16,6 +18,12 @@ ENV PYTHONPATH=/dist
1618
# Install any needed packages specified in requirements.txt
1719
RUN pip install --no-cache-dir -r requirements.txt
1820

21+
FROM requirements AS app
22+
23+
WORKDIR /dist
24+
COPY app /dist/app
25+
26+
FROM app AS runtime
1927

2028
# Run the application when the container launches
2129
CMD ["python", "-m", "app.agent"]

app/agent.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,27 @@ def main(prompts: Optional[Tuple[str, ...]] = None) -> None:
3939
followup_question = None
4040

4141
if "get_courses" in functions_called:
42-
user_prompt = (
43-
prompts[i]
44-
if prompts and len(prompts) >= i
45-
else input(followup_question or "Would you like to register for a course? ")
46-
)
42+
default_prompt = "Would you like to register for a course? "
4743
elif "register_course" in functions_called:
48-
user_prompt = (
49-
prompts[i]
50-
if prompts and len(prompts) >= i
51-
else input(followup_question or "Can I help you with anything else? ")
52-
)
44+
default_prompt = "Can I help you with anything else? "
45+
else:
46+
default_prompt = "Please let me know: "
47+
48+
user_prompt = prompts[i] if prompts and len(prompts) > i else input(followup_question or default_prompt)
49+
50+
if user_prompt and user_prompt.lower().strip() in [
51+
"no",
52+
"no thanks",
53+
"nothing",
54+
"exit",
55+
"quit",
56+
"bye",
57+
"goodbye",
58+
"that's all",
59+
"nothing else",
60+
]:
61+
print("Thank you for using Stackademy! Goodbye!")
62+
break
5363

5464
response, functions_called = completion(prompt=user_prompt)
5565

app/prompt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,16 @@ def handle_completion(tools, tool_choice) -> ChatCompletion:
168168
functions_called = []
169169

170170
response = handle_completion(
171-
tool_choice={"type": "function", "function": {"name": "get_courses"}},
171+
# tool_choice={"type": "function", "function": {"name": "get_courses"}},
172+
tool_choice="required",
172173
tools=[stackademy_app.tool_factory_get_courses()],
173174
)
174175
logger.debug("Initial response: %s", response.model_dump())
175176

176177
message = response.choices[0].message
177178
while message.tool_calls:
179+
if message.content and "Goodbye!" in message.content:
180+
break
178181
functions_called = process_tool_calls(message)
179182

180183
response = handle_completion(

app/stackademy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,27 @@ def _log_success(self, message: str) -> None:
6666

6767
def tool_factory_get_courses(self) -> ChatCompletionFunctionToolParam:
6868
"""LLM Factory function to create a tool for getting courses"""
69+
schema = StackademyGetCoursesParams.model_json_schema()
70+
schema["required"] = [] # Both parameters are optional
6971
return ChatCompletionFunctionToolParam(
7072
type="function",
7173
function={
7274
"name": "get_courses",
7375
"description": "returns up to 10 rows of course detail data, filtered by the maximum cost a student is willing to pay for a course and the area of specialization.",
74-
"parameters": StackademyGetCoursesParams.model_json_schema(),
76+
"parameters": schema,
7577
},
7678
)
7779

7880
def tool_factory_register(self) -> ChatCompletionFunctionToolParam:
7981
"""LLMFactory function to create a tool for registering a user"""
82+
schema = StackademyRegisterCourseParams.model_json_schema()
83+
schema["required"] = ["course_code", "email", "full_name"] # All parameters are required
8084
return ChatCompletionFunctionToolParam(
8185
type="function",
8286
function={
8387
"name": "register_course",
8488
"description": "Register a student in a course with the provided details.",
85-
"parameters": StackademyRegisterCourseParams.model_json_schema(),
89+
"parameters": schema,
8690
},
8791
)
8892

0 commit comments

Comments
 (0)