Rox-Turbo commited on
Commit
1e057a5
·
verified ·
1 Parent(s): 62e11c9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -100
README.md CHANGED
@@ -1,100 +1,110 @@
1
- ## NVIDIA Chat Proxy API
2
-
3
- This is a small FastAPI server that proxies requests from your static website to the NVIDIA/`OpenAI` compatible endpoint, so your API key stays on the server and is never exposed in the browser.
4
-
5
- ### 1. Setup
6
-
7
- Create and activate a virtual environment (optional but recommended), then install dependencies:
8
-
9
- ```bash
10
- pip install -r requirements.txt
11
- ```
12
-
13
- Create a `.env` file in this folder:
14
-
15
- ```bash
16
- echo NVIDIA_API_KEY=your_real_nvidia_key_here > .env
17
- ```
18
-
19
- > **Important**: Never commit your real key to git or paste it in client-side code.
20
-
21
- ### 2. Run the server
22
-
23
- ```bash
24
- python server.py
25
- ```
26
-
27
- The API will be available at `http://localhost:8000`.
28
-
29
- ### 3. HTTP API
30
-
31
- **Endpoint**: `POST /chat`
32
-
33
- **Request body**:
34
-
35
- ```json
36
- {
37
- "messages": [
38
- { "role": "user", "content": "Hello!" }
39
- ],
40
- "temperature": 1.0,
41
- "top_p": 1.0,
42
- "max_tokens": 512
43
- }
44
- ```
45
-
46
- **Response body**:
47
-
48
- ```json
49
- {
50
- "content": "Model reply here..."
51
- }
52
- ```
53
-
54
- ### 4. Example usage from a static website
55
-
56
- ```html
57
- <!DOCTYPE html>
58
- <html>
59
- <head>
60
- <meta charset="UTF-8" />
61
- <title>Chat with NVIDIA Model</title>
62
- </head>
63
- <body>
64
- <textarea id="input" placeholder="Ask something..."></textarea>
65
- <button id="send">Send</button>
66
- <pre id="output"></pre>
67
-
68
- <script>
69
- const API_URL = "http://localhost:8000/chat"; // or your deployed URL
70
-
71
- document.getElementById("send").addEventListener("click", async () => {
72
- const userText = document.getElementById("input").value;
73
-
74
- const body = {
75
- messages: [{ role: "user", content: userText }],
76
- temperature: 1,
77
- top_p: 1,
78
- max_tokens: 512,
79
- };
80
-
81
- const res = await fetch(API_URL, {
82
- method: "POST",
83
- headers: { "Content-Type": "application/json" },
84
- body: JSON.stringify(body),
85
- });
86
-
87
- if (!res.ok) {
88
- document.getElementById("output").textContent =
89
- "Error: " + (await res.text());
90
- return;
91
- }
92
-
93
- const data = await res.json();
94
- document.getElementById("output").textContent = data.content;
95
- });
96
- </script>
97
- </body>
98
- </html>
99
- ```
100
-
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: nvidia-chat-proxy
3
+ emoji: 💬
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ sdk_version: "1.0"
8
+ app_port: 8000
9
+ pinned: false
10
+ ---
11
+
12
+ ## NVIDIA Chat Proxy API
13
+
14
+ This is a small FastAPI server that proxies requests from your static website to the NVIDIA/`OpenAI` compatible endpoint, so your API key stays on the server and is never exposed in the browser.
15
+
16
+ ### 1. Setup
17
+
18
+ Create and activate a virtual environment (optional but recommended), then install dependencies:
19
+
20
+ ```bash
21
+ pip install -r requirements.txt
22
+ ```
23
+
24
+ Create a `.env` file in this folder:
25
+
26
+ ```bash
27
+ echo NVIDIA_API_KEY=your_real_nvidia_key_here > .env
28
+ ```
29
+
30
+ > **Important**: Never commit your real key to git or paste it in client-side code.
31
+
32
+ ### 2. Run the server
33
+
34
+ ```bash
35
+ python server.py
36
+ ```
37
+
38
+ The API will be available at `http://localhost:8000`.
39
+
40
+ ### 3. HTTP API
41
+
42
+ **Endpoint**: `POST /chat`
43
+
44
+ **Request body**:
45
+
46
+ ```json
47
+ {
48
+ "messages": [
49
+ { "role": "user", "content": "Hello!" }
50
+ ],
51
+ "temperature": 1.0,
52
+ "top_p": 1.0,
53
+ "max_tokens": 512
54
+ }
55
+ ```
56
+
57
+ **Response body**:
58
+
59
+ ```json
60
+ {
61
+ "content": "Model reply here..."
62
+ }
63
+ ```
64
+
65
+ ### 4. Example usage from a static website
66
+
67
+ ```html
68
+ <!DOCTYPE html>
69
+ <html>
70
+ <head>
71
+ <meta charset="UTF-8" />
72
+ <title>Chat with NVIDIA Model</title>
73
+ </head>
74
+ <body>
75
+ <textarea id="input" placeholder="Ask something..."></textarea>
76
+ <button id="send">Send</button>
77
+ <pre id="output"></pre>
78
+
79
+ <script>
80
+ const API_URL = "http://localhost:8000/chat"; // or your deployed URL
81
+
82
+ document.getElementById("send").addEventListener("click", async () => {
83
+ const userText = document.getElementById("input").value;
84
+
85
+ const body = {
86
+ messages: [{ role: "user", content: userText }],
87
+ temperature: 1,
88
+ top_p: 1,
89
+ max_tokens: 512,
90
+ };
91
+
92
+ const res = await fetch(API_URL, {
93
+ method: "POST",
94
+ headers: { "Content-Type": "application/json" },
95
+ body: JSON.stringify(body),
96
+ });
97
+
98
+ if (!res.ok) {
99
+ document.getElementById("output").textContent =
100
+ "Error: " + (await res.text());
101
+ return;
102
+ }
103
+
104
+ const data = await res.json();
105
+ document.getElementById("output").textContent = data.content;
106
+ });
107
+ </script>
108
+ </body>
109
+ </html>
110
+ ```