Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/docs/demos/04-llm-model.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def ask_question(question):

try:
response = requests.post(
f"{SERVICE_URL}/v1/chat",
f"{SERVICE_URL}/v1/completions",
headers=headers,
json=payload
)
Comment on lines 88 to 92

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The requests.post call can be made more robust. It's missing a timeout, which can cause the script to hang indefinitely if the remote server is unresponsive. Additionally, concatenating URL parts with an f-string can be fragile if SERVICE_URL contains a trailing slash, leading to double slashes in the URL.

I'd recommend adding a timeout and also stripping any trailing slash from the service URL to make the code more resilient.

        response = requests.post(
            f"{SERVICE_URL.rstrip('/')}/v1/completions",
            headers=headers,
            json=payload,
            timeout=60  # Add a timeout to prevent requests from hanging
        )

Expand Down
Loading