From c02326e0bbf9bfe6e1ea144e3767adc07199b5e8 Mon Sep 17 00:00:00 2001 From: hahuyhoang411 Date: Fri, 24 Nov 2023 09:59:51 +0700 Subject: [PATCH 1/3] Update views --- docs/docs/examples/openai-node.md | 108 +++++++++++++++++------------- 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/docs/docs/examples/openai-node.md b/docs/docs/examples/openai-node.md index e556f7164..6a75982de 100644 --- a/docs/docs/examples/openai-node.md +++ b/docs/docs/examples/openai-node.md @@ -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 = ''; -// 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 = ''; const 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(); ``` +> 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 @@ -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(); ``` @@ -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(); ``` @@ -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 = ''; -// 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 = ''; const 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(); ``` From 78f3b4205685d64137b55424f0216cc81d689b39 Mon Sep 17 00:00:00 2001 From: hahuyhoang411 Date: Fri, 24 Nov 2023 10:22:20 +0700 Subject: [PATCH 2/3] update faqs to dropdown --- docs/docs/new/faq.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/docs/new/faq.md b/docs/docs/new/faq.md index 6edba5c06..1f7c1541f 100644 --- a/docs/docs/new/faq.md +++ b/docs/docs/new/faq.md @@ -3,18 +3,30 @@ title: FAQs slug: /faq --- -### 1. Is Nitro the same as Llama.cpp with an API server? +
+ 1. Is Nitro the same as Llama.cpp with an API server? 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? +
+ +
+ 2. Is Nitro simply Llama-cpp-python? 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? +
+ +
+ 3. Why should I switch to Nitro over Ollama? 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"? +
+ +
+ 4. Why is the model named "chat-gpt-3.5"? + +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. \ No newline at end of file +
From a9caf594474a294b28a0021a1f4dbe9ac7bdb631 Mon Sep 17 00:00:00 2001 From: hahuyhoang411 Date: Fri, 24 Nov 2023 13:13:42 +0700 Subject: [PATCH 3/3] remove chatbox --- docs/sidebars.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/sidebars.js b/docs/sidebars.js index 628b1b8ec..7e268ff83 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -60,7 +60,7 @@ const sidebars = { collapsed: false, items: [ "examples/jan", - "examples/chatbox", + // "examples/chatbox", "examples/palchat", "examples/openai-node", "examples/openai-python", @@ -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", ],