jaothan commited on
Commit
e8ad316
·
verified ·
1 Parent(s): 85488d0

Update llamacpp_python/base/chat-app.py

Browse files
Files changed (1) hide show
  1. llamacpp_python/base/chat-app.py +38 -38
llamacpp_python/base/chat-app.py CHANGED
@@ -1,38 +1,38 @@
1
- #2. **Set the `MODEL_ENDPOINT` Environment Variable**
2
- #In your chat application, ensure the `MODEL_ENDPOINT` environment variable is set to the correct URL of the model server. For example:
3
- #```python
4
- import os
5
- import requests
6
-
7
- # Get the model endpoint from the environment variable
8
- model_service = os.getenv("MODEL_ENDPOINT", "http://localhost:8001")
9
-
10
- # Example function to call the model server
11
- def call_model(prompt):
12
- url = f"{model_service}/generate"
13
- payload = {"prompt": prompt}
14
- response = requests.post(url, json=payload)
15
- if response.status_code == 200:
16
- return response.json().get("response", "No response from model")
17
- else:
18
- return f"Error: {response.status_code}"
19
-
20
- # Test the connection
21
- if __name__ == "__main__":
22
- prompt = "Hello, model!"
23
- result = call_model(prompt)
24
- print(result)
25
- #### 3. **Test the Connection**
26
- #Run the chat application and test the connection to the model server:
27
-
28
- #```bash
29
- # Set the MODEL_ENDPOINT environment variable
30
- #export MODEL_ENDPOINT="http://localhost:8001"
31
-
32
- # Run the chat application
33
- #python chat_app.py
34
- #```
35
-
36
- #If everything is set up correctly, the chat application should be able to call #the model server and receive a response.
37
-
38
-
 
1
+ #2. **Set the `MODEL_ENDPOINT` Environment Variable**
2
+ #In your chat application, ensure the `MODEL_ENDPOINT` environment variable is set to the correct URL of the model server. For example:
3
+ #```python
4
+ import os
5
+ import requests
6
+
7
+ # Get the model endpoint from the environment variable
8
+ model_service = os.getenv("MODEL_ENDPOINT", "http://127.0.0.1:8001")
9
+
10
+ # Example function to call the model server
11
+ def call_model(prompt):
12
+ url = f"{model_service}/generate"
13
+ payload = {"prompt": prompt}
14
+ response = requests.post(url, json=payload)
15
+ if response.status_code == 200:
16
+ return response.json().get("response", "No response from model")
17
+ else:
18
+ return f"Error: {response.status_code}"
19
+
20
+ # Test the connection
21
+ if __name__ == "__main__":
22
+ prompt = "Hello, model!"
23
+ result = call_model(prompt)
24
+ print(result)
25
+ #### 3. **Test the Connection**
26
+ #Run the chat application and test the connection to the model server:
27
+
28
+ #```bash
29
+ # Set the MODEL_ENDPOINT environment variable
30
+ #export MODEL_ENDPOINT="http://localhost:8001"
31
+
32
+ # Run the chat application
33
+ #python chat_app.py
34
+ #```
35
+
36
+ #If everything is set up correctly, the chat application should be able to call #the model server and receive a response.
37
+
38
+