Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 07a38de

Browse files
authored
Merge pull request #188 from janhq/update-docs-view
Update views
2 parents 6395c17 + a9caf59 commit 07a38de

File tree

3 files changed

+90
-60
lines changed

3 files changed

+90
-60
lines changed

docs/docs/examples/openai-node.md

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -85,54 +85,60 @@ chatCompletion()
8585

8686
```typescript
8787
import OpenAI from 'openai';
88-
// The name of your Azure OpenAI Resource.
89-
// https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
90-
const resource = '<your resource name>';
9188

92-
// Corresponds to your Model deployment within your OpenAI resource, e.g. my-gpt35-16k-deployment
93-
// Navigate to the Azure OpenAI Studio to deploy a model.
89+
const resource = '<your resource name>';
9490
const model = '<your model>';
95-
96-
// https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
9791
const apiVersion = '2023-06-01-preview';
98-
9992
const apiKey = process.env['AZURE_OPENAI_API_KEY'];
93+
10094
if (!apiKey) {
101-
throw new Error('The AZURE_OPENAI_API_KEY environment variable is missing or empty.');
95+
throw new Error('The AZURE_OPENAI_API_KEY variable is missing.');
10296
}
10397

98+
const baseURL = `https://${resource}.openai.azure.com/openai/` +
99+
`deployments/${model}`;
100+
104101
const openai = new OpenAI({
105102
apiKey,
106-
baseURL: `https://${resource}.openai.azure.com/openai/deployments/${model}`,
103+
baseURL,
107104
defaultQuery: { 'api-version': apiVersion },
108105
defaultHeaders: { 'api-key': apiKey },
109106
});
110107

111108
async function chatCompletion() {
112-
const stream = await openai.beta.chat.completions.stream({
113-
model: 'gpt-3.5-turbo',
114-
messages: [{ role: 'user', content: 'Say this is a test' }],
115-
stream: true,
116-
});
117-
118-
stream.on('content', (delta, snapshot) => {
119-
process.stdout.write(delta);
120-
});
121-
122-
for await (const chunk of stream) {
123-
process.stdout.write(chunk.choices[0]?.delta?.content || '');
109+
try {
110+
const stream = await openai.beta.chat.completions.stream({
111+
model: 'gpt-3.5-turbo',
112+
messages: [{ role: 'user', content: 'Say this is a test' }],
113+
stream: true,
114+
});
115+
116+
stream.on('content', (delta, snapshot) => {
117+
process.stdout.write(delta);
118+
});
119+
120+
for await (const chunk of stream) {
121+
process.stdout.write(chunk.choices[0]?.delta?.content || '');
122+
}
123+
124+
const chatCompletion = await stream.finalChatCompletion();
125+
console.log(chatCompletion); // Log the final completion
126+
} catch (error) {
127+
console.error('Error in chat completion:', error);
124128
}
125-
126-
const chatCompletion = await stream.finalChatCompletion();
127-
console.log(chatCompletion); // {id: "…", choices: […], …}
128129
}
129-
chatCompletion()
130+
131+
chatCompletion();
130132
```
131133

132134
</td>
133135
</tr>
134136
</table>
135137

138+
> Resource:
139+
> - [Azure Create a resource](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource)
140+
> - [Azure-OAI Rest API versoning](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning)
141+
136142
## Embedding
137143
<table>
138144
<tr>
@@ -146,16 +152,24 @@ chatCompletion()
146152
import OpenAI from 'openai';
147153

148154
const openai = new OpenAI({
149-
apiKey: '', // defaults to process.env["OPENAI_API_KEY"]
150-
baseURL: "http://localhost:3928/v1/" // https://api.openai.com/v1
155+
apiKey: '', // Defaults to process.env["OPENAI_API_KEY"]
156+
baseURL: 'http://localhost:3928/v1/'
157+
// 'https://api.openai.com/v1'
151158
});
152159

153160
async function embedding() {
154-
const embedding = await openai.embeddings.create({input: 'Hello How are you?', model: 'text-embedding-ada-002'});
155-
console.log(embedding); // {object: "list", data: […], …}
161+
try {
162+
const response = await openai.embeddings.create({
163+
input: 'Hello How are you?',
164+
model: 'text-embedding-ada-002'
165+
});
166+
console.log(response); // Log the response
167+
} catch (error) {
168+
console.error('Error in fetching embedding:', error);
169+
}
156170
}
157171

158-
chatCompletion();
172+
embedding();
159173
```
160174
</td>
161175
</tr>
@@ -171,11 +185,14 @@ const openai = new OpenAI({
171185
});
172186

173187
async function embedding() {
174-
const embedding = await openai.embeddings.create({input: 'Hello How are you?', model: 'text-embedding-ada-002'});
188+
const embedding = await openai.embeddings.create({
189+
input: 'Hello How are you?',
190+
model: 'text-embedding-ada-002'
191+
});
175192
console.log(embedding); // {object: "list", data: […], …}
176193
}
177194

178-
chatCompletion();
195+
embedding();
179196
```
180197

181198
</td>
@@ -186,35 +203,36 @@ chatCompletion();
186203

187204
```typescript
188205
import OpenAI from 'openai';
189-
// The name of your Azure OpenAI Resource.
190-
// https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
191-
const resource = '<your resource name>';
192206

193-
// Corresponds to your Model deployment within your OpenAI resource, e.g. my-gpt35-16k-deployment
194-
// Navigate to the Azure OpenAI Studio to deploy a model.
207+
const resource = '<your resource name>';
195208
const model = '<your model>';
196-
197-
// https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
198209
const apiVersion = '2023-06-01-preview';
199-
200210
const apiKey = process.env['AZURE_OPENAI_API_KEY'];
211+
201212
if (!apiKey) {
202-
throw new Error('The AZURE_OPENAI_API_KEY environment variable is missing or empty.');
213+
throw new Error('The AZURE_OPENAI_API_KEY variable is missing.');
203214
}
204215

216+
// Splitting the baseURL into concatenated parts for readability
217+
const baseURL = `https://${resource}.openai.azure.com/openai/` +
218+
`deployments/${model}`;
219+
205220
const openai = new OpenAI({
206221
apiKey,
207-
baseURL: `https://${resource}.openai.azure.com/openai/deployments/${model}`,
222+
baseURL,
208223
defaultQuery: { 'api-version': apiVersion },
209224
defaultHeaders: { 'api-key': apiKey },
210225
});
211226

212227
async function embedding() {
213-
const embedding = await openai.embeddings.create({input: 'Hello How are you?', model: 'text-embedding-ada-002'});
228+
const embedding = await openai.embeddings.create({
229+
input: 'Hello How are you?',
230+
model: 'text-embedding-ada-002'
231+
});
214232
console.log(embedding); // {object: "list", data: […], …}
215233
}
216234

217-
chatCompletion();
235+
embedding();
218236
```
219237

220238
</td>

docs/docs/new/faq.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ title: FAQs
33
slug: /faq
44
---
55

6-
### 1. Is Nitro the same as Llama.cpp with an API server?
6+
<details>
7+
<summary>1. Is Nitro the same as Llama.cpp with an API server?</summary>
78

89
Yes, that's correct. However, Nitro isn't limited to just Llama.cpp; it will soon integrate multiple other models like Whisper, Bark, and Stable Diffusion, all in a single binary. This eliminates the need for you to develop a separate API server on top of AI models. Nitro is a comprehensive solution, designed for ease of use and efficiency.
910

10-
### 2. Is Nitro simply Llama-cpp-python?
11+
</details>
12+
13+
<details>
14+
<summary>2. Is Nitro simply Llama-cpp-python?</summary>
1115

1216
Indeed, Nitro isn't bound to Python, which allows you to leverage high-performance software that fully utilizes your system's capabilities. With Nitro, learning how to deploy a Python web server or use FastAPI isn't necessary. The Nitro web server is already fully optimized.
1317

14-
### 3. Why should I switch to Nitro over Ollama?
18+
</details>
19+
20+
<details>
21+
<summary>3. Why should I switch to Nitro over Ollama?</summary>
1522

1623
While Ollama does provide similar functionalities, its design serves a different purpose. Ollama has a larger size (around 200MB) compared to Nitro's 3MB distribution. Nitro's compact size allows for easy embedding into subprocesses, ensuring minimal concerns about package size for your application. This makes Nitro a more suitable choice for applications where efficiency and minimal resource usage are key.
1724

18-
### 4. Why is the model named "chat-gpt-3.5"?
25+
</details>
26+
27+
<details>
28+
<summary>4. Why is the model named "chat-gpt-3.5"?</summary>
29+
30+
Many applications implement the OpenAI ChatGPT API, and we want Nitro to be versatile for any AI client. While you can use any model name, we've ensured that if you're already using the chatgpt API, switching to Nitro is seamless. Just replace api.openai.com with localhost:3928 in your client settings (like Chatbox, Sillytavern, Oobaboga, etc.), and it will work smoothly with Nitro.
1931

20-
Many applications implement the OpenAI ChatGPT API, and we want Nitro to be versatile for any AI client. While you can use any model name, we've ensured that if you're already using the chatgpt API, switching to Nitro is seamless. Just replace api.openai.com with localhost:3928 in your client settings (like Chatbox, Sillytavern, Oobaboga, etc.), and it will work smoothly with Nitro.
32+
</details>

docs/sidebars.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const sidebars = {
6060
collapsed: false,
6161
items: [
6262
"examples/jan",
63-
"examples/chatbox",
63+
// "examples/chatbox",
6464
"examples/palchat",
6565
"examples/openai-node",
6666
"examples/openai-python",
@@ -73,15 +73,15 @@ const sidebars = {
7373
// collapsed: false,
7474
// items: [{ type: "doc", id: "new/architecture", label: "Architecture" }],
7575
// },
76-
{
77-
type: "category",
78-
label: "Demos",
79-
collapsible: true,
80-
collapsed: true,
81-
items: [
82-
"demos/chatbox-vid",
83-
],
84-
},
76+
// {
77+
// type: "category",
78+
// label: "Demos",
79+
// collapsible: true,
80+
// collapsed: true,
81+
// items: [
82+
// "demos/chatbox-vid",
83+
// ],
84+
// },
8585
"new/faq",
8686
],
8787

0 commit comments

Comments
 (0)