Team Ai
Apppublic

jaothan/podman_llamacpp_python

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
call-model.py21 linesDownload Raw Back to base
1#### 6. **Handling Errors**
2#- If the chat application cannot connect to the model server, check the following:
3 # - Is the model server running?
4 # - Is the `MODEL_ENDPOINT` URL correct?
5 # - Are there any firewall or network restrictions blocking the connection?
6#  - Are the ports correctly mapped (if using Docker)?
7
8#- Add error handling in the chat application to handle cases where the model server is unavailable:
9
10#```python
11def call_model(prompt):
12    try:
13        url = f"{model_service}/generate"
14        payload = {"prompt": prompt}
15        response = requests.post(url, json=payload, timeout=10)  # Add a timeout
16        response.raise_for_status()  # Raise an error for bad status codes
17        return response.json().get("response", "No response from model")
18    except requests.exceptions.RequestException as e:
19        return f"Error connecting to the model server: {e}"
20
21