Skip to content

Commit

Permalink
Merge pull request #188 from janhq/update-docs-view
Browse files Browse the repository at this point in the history
Update views
  • Loading branch information
tikikun authored Nov 24, 2023
2 parents 6395c17 + a9caf59 commit 07a38de
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 60 deletions.
108 changes: 63 additions & 45 deletions docs/docs/examples/openai-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,54 +85,60 @@ chatCompletion()

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

// Corresponds to your Model deployment within your OpenAI resource, e.g. my-gpt35-16k-deployment
// Navigate to the Azure OpenAI Studio to deploy a model.
const resource = '<your resource name>';
const model = '<your model>';

// https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
const apiVersion = '2023-06-01-preview';

const apiKey = process.env['AZURE_OPENAI_API_KEY'];

if (!apiKey) {
throw new Error('The AZURE_OPENAI_API_KEY environment variable is missing or empty.');
throw new Error('The AZURE_OPENAI_API_KEY variable is missing.');
}

const baseURL = `https://${resource}.openai.azure.com/openai/` +
`deployments/${model}`;

const openai = new OpenAI({
apiKey,
baseURL: `https://${resource}.openai.azure.com/openai/deployments/${model}`,
baseURL,
defaultQuery: { 'api-version': apiVersion },
defaultHeaders: { 'api-key': apiKey },
});

async function chatCompletion() {
const stream = await openai.beta.chat.completions.stream({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Say this is a test' }],
stream: true,
});

stream.on('content', (delta, snapshot) => {
process.stdout.write(delta);
});

for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
try {
const stream = await openai.beta.chat.completions.stream({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Say this is a test' }],
stream: true,
});

stream.on('content', (delta, snapshot) => {
process.stdout.write(delta);
});

for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

const chatCompletion = await stream.finalChatCompletion();
console.log(chatCompletion); // Log the final completion
} catch (error) {
console.error('Error in chat completion:', error);
}

const chatCompletion = await stream.finalChatCompletion();
console.log(chatCompletion); // {id: "…", choices: […], …}
}
chatCompletion()

chatCompletion();
```

</td>
</tr>
</table>

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

const openai = new OpenAI({
apiKey: '', // defaults to process.env["OPENAI_API_KEY"]
baseURL: "http://localhost:3928/v1/" // https://api.openai.com/v1
apiKey: '', // Defaults to process.env["OPENAI_API_KEY"]
baseURL: 'http://localhost:3928/v1/'
// 'https://api.openai.com/v1'
});

async function embedding() {
const embedding = await openai.embeddings.create({input: 'Hello How are you?', model: 'text-embedding-ada-002'});
console.log(embedding); // {object: "list", data: […], …}
try {
const response = await openai.embeddings.create({
input: 'Hello How are you?',
model: 'text-embedding-ada-002'
});
console.log(response); // Log the response
} catch (error) {
console.error('Error in fetching embedding:', error);
}
}

chatCompletion();
embedding();
```
</td>
</tr>
Expand All @@ -171,11 +185,14 @@ const openai = new OpenAI({
});

async function embedding() {
const embedding = await openai.embeddings.create({input: 'Hello How are you?', model: 'text-embedding-ada-002'});
const embedding = await openai.embeddings.create({
input: 'Hello How are you?',
model: 'text-embedding-ada-002'
});
console.log(embedding); // {object: "list", data: […], …}
}

chatCompletion();
embedding();
```

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

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

// Corresponds to your Model deployment within your OpenAI resource, e.g. my-gpt35-16k-deployment
// Navigate to the Azure OpenAI Studio to deploy a model.
const resource = '<your resource name>';
const model = '<your model>';

// https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
const apiVersion = '2023-06-01-preview';

const apiKey = process.env['AZURE_OPENAI_API_KEY'];

if (!apiKey) {
throw new Error('The AZURE_OPENAI_API_KEY environment variable is missing or empty.');
throw new Error('The AZURE_OPENAI_API_KEY variable is missing.');
}

// Splitting the baseURL into concatenated parts for readability
const baseURL = `https://${resource}.openai.azure.com/openai/` +
`deployments/${model}`;

const openai = new OpenAI({
apiKey,
baseURL: `https://${resource}.openai.azure.com/openai/deployments/${model}`,
baseURL,
defaultQuery: { 'api-version': apiVersion },
defaultHeaders: { 'api-key': apiKey },
});

async function embedding() {
const embedding = await openai.embeddings.create({input: 'Hello How are you?', model: 'text-embedding-ada-002'});
const embedding = await openai.embeddings.create({
input: 'Hello How are you?',
model: 'text-embedding-ada-002'
});
console.log(embedding); // {object: "list", data: […], …}
}

chatCompletion();
embedding();
```

</td>
Expand Down
22 changes: 17 additions & 5 deletions docs/docs/new/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@ title: FAQs
slug: /faq
---

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

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.

### 2. Is Nitro simply Llama-cpp-python?
</details>

<details>
<summary>2. Is Nitro simply Llama-cpp-python?</summary>

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.

### 3. Why should I switch to Nitro over Ollama?
</details>

<details>
<summary>3. Why should I switch to Nitro over Ollama?</summary>

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.

### 4. Why is the model named "chat-gpt-3.5"?
</details>

<details>
<summary>4. Why is the model named "chat-gpt-3.5"?</summary>

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.

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.
</details>
20 changes: 10 additions & 10 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const sidebars = {
collapsed: false,
items: [
"examples/jan",
"examples/chatbox",
// "examples/chatbox",
"examples/palchat",
"examples/openai-node",
"examples/openai-python",
Expand All @@ -73,15 +73,15 @@ const sidebars = {
// collapsed: false,
// items: [{ type: "doc", id: "new/architecture", label: "Architecture" }],
// },
{
type: "category",
label: "Demos",
collapsible: true,
collapsed: true,
items: [
"demos/chatbox-vid",
],
},
// {
// type: "category",
// label: "Demos",
// collapsible: true,
// collapsed: true,
// items: [
// "demos/chatbox-vid",
// ],
// },
"new/faq",
],

Expand Down

0 comments on commit 07a38de

Please sign in to comment.