From 34f35851ecec432994a05d54d4f4dea16e87439d Mon Sep 17 00:00:00 2001 From: brandom Date: Mon, 10 Jun 2024 15:48:06 -0700 Subject: [PATCH 1/8] view code and docs template 1st draft --- src/ai/.x/templates/openai-chat-js/Main.js | 90 +++++++++++++++++++--- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/src/ai/.x/templates/openai-chat-js/Main.js b/src/ai/.x/templates/openai-chat-js/Main.js index c68b9d35..41d04eff 100644 --- a/src/ai/.x/templates/openai-chat-js/Main.js +++ b/src/ai/.x/templates/openai-chat-js/Main.js @@ -1,21 +1,90 @@ -const { OpenAI } = require('openai'); +{{if {_IS_AUTHOR_COMMENT} }} + // Showcasing syntax differences for the same content: + // The Learn docs use CommonJS module syntax, which includes `require` and `module.exports` + // This is an older standard for working with modules in JavaScript and is widely supported, especially in Node.js. + // The Studio "view code" uses ES6 module syntax, which includes `import` and `export`. + // This is a newer standard for working with modules in JavaScript and is supported in modern browsers and Node.js versions +{{endif}} +{{if {_IS_STUDIO_VIEW_CODE_TEMPLATE}}} +import { AzureOpenAI } from "openai"; +import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; +{{else if {_IS_LEARN_DOC_TEMPLATE} || !{_IS_STUDIO_VIEW_CODE_TEMPLATE}}} +const { OpenAI } = require("openai"); +{{endif}} +{{if !{_IS_LEARN_DOC_TEMPLATE} || !{_IS_STUDIO_VIEW_CODE_TEMPLATE}}} const { {ClassName} } = require("./OpenAIChatCompletionsClass"); const { readline } = require("./ReadLineWrapper"); +{{endif}} +{{if {_IS_LEARN_DOC_TEMPLATE}}} +// Load the .env file if it exists +const dotenv = require("dotenv"); +dotenv.config(); + + {{if {_IS_ENTRA_ID}}} + const scope = "https://cognitiveservices.azure.com/.default"; + const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope); + {{else}} + // You will need to set these environment variables or edit the following values + const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || ""; + const apiKey = process.env["AZURE_OPENAI_API_KEY"] || ""; + {{endif}} + const apiVersion = "2024-05-01-preview"; + const deployment = "gpt-4o"; //This must match your deployment name. + require("dotenv/config"); +{{endif}} + +{{if {_IS_STUDIO_VIEW_CODE_TEMPLATE}}} +export async function main() { +{{else}} async function main() { +{{endif}} - // What's the system prompt? - const AZURE_OPENAI_SYSTEM_PROMPT = process.env.AZURE_OPENAI_SYSTEM_PROMPT ?? "You are a helpful AI assistant."; + {{if {_IS_LEARN_DOC_TEMPLATE}}} + const client = new AzureOpenAI({ endpoint, apiKey, apiVersion, deployment }); + const result = await client.chat.completions.create({ + messages: [ + { role: "system", content: "You are a helpful assistant." }, + { role: "user", content: "Does Azure OpenAI support customer managed keys?" }, + { role: "assistant", content: "Yes, customer managed keys are supported by Azure OpenAI?" }, + { role: "user", content: "Do other Azure AI services support this too?" }, + ], + model: "", + }); - {{@include openai.js/create.openai.js}} + {{else if {_IS_STUDIO_VIEW_CODE_TEMPLATE}}} + const scope = "https://cognitiveservices.azure.com/.default"; + const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope); + const deployment = "gpt-35-turbo"; + const apiVersion = "2024-04-01-preview"; + const client = new AzureOpenAI({ azureADTokenProvider, deployment, apiVersion }); + const result = await client.chat.completions.create({ + messages: [ + { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, + { role: "user", content: "Can you help me?" }, + ], + model: '', + }); - // Create the streaming chat completions helper - {{if contains(toupper("{OPENAI_CLOUD}"), "AZURE")}} - const chat = new {ClassName}(AZURE_OPENAI_CHAT_DEPLOYMENT, AZURE_OPENAI_SYSTEM_PROMPT, openai); {{else}} - const chat = new {ClassName}(OPENAI_MODEL_NAME, AZURE_OPENAI_SYSTEM_PROMPT, openai); + // What's the system prompt? + const AZURE_OPENAI_SYSTEM_PROMPT = process.env.AZURE_OPENAI_SYSTEM_PROMPT ?? "You are a helpful AI assistant."; + + {{@include openai.js/create.openai.js}} + // Create the streaming chat completions helper + {{if contains(toupper("{OPENAI_CLOUD}"), "AZURE")}} + const chat = new {ClassName}(AZURE_OPENAI_CHAT_DEPLOYMENT, AZURE_OPENAI_SYSTEM_PROMPT, openai); + {{else}} + const chat = new {ClassName}(OPENAI_MODEL_NAME, AZURE_OPENAI_SYSTEM_PROMPT, openai); + {{endif}} {{endif}} - + +{{if {_IS_LEARN_DOC_TEMPLATE}} || {_IS_STUDIO_VIEW_CODE_TEMPLATE}} + for (const choice of result.choices) { + console.log(choice.message); + } + } +{{else}} // Loop until the user types 'exit' while (true) { @@ -31,10 +100,13 @@ async function main() { console.log('Bye!'); process.exit(); } +{{endif}} main().catch((err) => { console.error("The sample encountered an error:", err); process.exit(1); }); +{{if !{_IS_STUDIO_VIEW_CODE_TEMPLATE}}} module.exports = { main }; +{{endif}} \ No newline at end of file From d597468e859b6e437406a8bf7dda39bae6809f09 Mon Sep 17 00:00:00 2001 From: brandom Date: Mon, 10 Jun 2024 17:44:44 -0700 Subject: [PATCH 2/8] create separate template dirs --- src/ai/.x/templates/openai-chat-js/_.json | 6 +++++- .../templates/openai-chat-learndocs-js/_.json | 16 ++++++++++++++++ .../openai-chat-learndocs-js/package.json | 17 +++++++++++++++++ .../openai-chat-studio-viewcode-js/_.json | 16 ++++++++++++++++ .../openai-chat-studio-viewcode-js/package.json | 17 +++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/ai/.x/templates/openai-chat-learndocs-js/_.json create mode 100644 src/ai/.x/templates/openai-chat-learndocs-js/package.json create mode 100644 src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json create mode 100644 src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json diff --git a/src/ai/.x/templates/openai-chat-js/_.json b/src/ai/.x/templates/openai-chat-js/_.json index ce31afbb..c6561749 100644 --- a/src/ai/.x/templates/openai-chat-js/_.json +++ b/src/ai/.x/templates/openai-chat-js/_.json @@ -10,5 +10,9 @@ "_IS_BROWSER_TEMPLATE": "false", "_IMPORT_EXPORT_USING_ES6": "false", "__process_env_or_import_meta_env": "process.env", - "_IS_OPENAI_ASST_TEMPLATE": "false" + "_IS_OPENAI_ASST_TEMPLATE": "false", + "_IS_STUDIO_VIEW_CODE_TEMPLATE": "false", + "_IS_LEARN_DOC_TEMPLATE": "true", + "_IS_AUTHOR_COMMENT": "false", + "_IS_ENTRA_ID": "false" } \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-learndocs-js/_.json b/src/ai/.x/templates/openai-chat-learndocs-js/_.json new file mode 100644 index 00000000..c049d4b4 --- /dev/null +++ b/src/ai/.x/templates/openai-chat-learndocs-js/_.json @@ -0,0 +1,16 @@ +{ + "_LongName": "OpenAI Chat Completions quickstart docs", + "_ShortName": "openai-chat-learndocs", + "_Language": "JavaScript", + + "ClassName": "OpenAIChatCompletionsClass", + "AZURE_OPENAI_AUTH_METHOD": "KEY", + "OPENAI_CLOUD": "Azure", + + "_IS_BROWSER_TEMPLATE": "false", + "_IMPORT_EXPORT_USING_ES6": "false", + "__process_env_or_import_meta_env": "process.env", + "_IS_OPENAI_ASST_TEMPLATE": "false", + "_IS_STUDIO_VIEW_CODE_TEMPLATE": "false", + "_IS_LEARN_DOC_TEMPLATE": "true" +} \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-learndocs-js/package.json b/src/ai/.x/templates/openai-chat-learndocs-js/package.json new file mode 100644 index 00000000..ff130119 --- /dev/null +++ b/src/ai/.x/templates/openai-chat-learndocs-js/package.json @@ -0,0 +1,17 @@ +{ + "name": "openai-chat", + "version": "1.0.0", + "description": "", + "main": "Main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "webpack": "webpack" + }, + "author": "", + "license": "MIT", + "dependencies": { + "@azure/identity": "4.1.0", + "openai": "^4.31.0" + } + } + \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json b/src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json new file mode 100644 index 00000000..b6ba41dc --- /dev/null +++ b/src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json @@ -0,0 +1,16 @@ +{ + "_LongName": "OpenAI Chat Completions Studio view code", + "_ShortName": "openai-chat-studio-viewcode", + "_Language": "JavaScript", + + "ClassName": "OpenAIChatCompletionsClass", + "AZURE_OPENAI_AUTH_METHOD": "KEY", + "OPENAI_CLOUD": "Azure", + + "_IS_BROWSER_TEMPLATE": "false", + "_IMPORT_EXPORT_USING_ES6": "false", + "__process_env_or_import_meta_env": "process.env", + "_IS_OPENAI_ASST_TEMPLATE": "false", + "_IS_STUDIO_VIEW_CODE_TEMPLATE": "true", + "_IS_LEARN_DOC_TEMPLATE": "false" +} \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json b/src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json new file mode 100644 index 00000000..ff130119 --- /dev/null +++ b/src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json @@ -0,0 +1,17 @@ +{ + "name": "openai-chat", + "version": "1.0.0", + "description": "", + "main": "Main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "webpack": "webpack" + }, + "author": "", + "license": "MIT", + "dependencies": { + "@azure/identity": "4.1.0", + "openai": "^4.31.0" + } + } + \ No newline at end of file From cdad91284cfeb94a7ba6c4d3de084ade708e5d72 Mon Sep 17 00:00:00 2001 From: brandom Date: Wed, 12 Jun 2024 16:14:35 -0700 Subject: [PATCH 3/8] add quickstart-js template and test --- .../openai-chat-quickstart-js/Main.js | 36 +++++++++++++++++++ .../openai-chat-quickstart-js/_.json | 13 +++++++ .../openai-chat-quickstart-js/package.json | 17 +++++++++ .../openai-chat-studioviewcode-js/Main.js | 25 +++++++++++++ .../openai-chat-studioviewcode-js/_.json | 14 ++++++++ .../package.json | 17 +++++++++ tests/ai-chat-quickstart-tests.yaml | 15 ++++++++ 7 files changed, 137 insertions(+) create mode 100644 src/ai/.x/templates/openai-chat-quickstart-js/Main.js create mode 100644 src/ai/.x/templates/openai-chat-quickstart-js/_.json create mode 100644 src/ai/.x/templates/openai-chat-quickstart-js/package.json create mode 100644 src/ai/.x/templates/openai-chat-studioviewcode-js/Main.js create mode 100644 src/ai/.x/templates/openai-chat-studioviewcode-js/_.json create mode 100644 src/ai/.x/templates/openai-chat-studioviewcode-js/package.json create mode 100644 tests/ai-chat-quickstart-tests.yaml diff --git a/src/ai/.x/templates/openai-chat-quickstart-js/Main.js b/src/ai/.x/templates/openai-chat-quickstart-js/Main.js new file mode 100644 index 00000000..2bf7e3e4 --- /dev/null +++ b/src/ai/.x/templates/openai-chat-quickstart-js/Main.js @@ -0,0 +1,36 @@ +const { AzureOpenAI } = require("openai"); + +// Load the .env file if it exists +const dotenv = require("dotenv"); +dotenv.config(); + +// You will need to set these environment variables or edit the following values +const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || ""; +const apiKey = process.env["AZURE_OPENAI_API_KEY"] || ""; +const apiVersion = "2024-05-01-preview"; +const deployment = process.env["AZURE_OPENAI_DEPLOYMENT"] || ""; //This must match your deployment name. +require("dotenv/config"); + +async function main() { + + const client = new AzureOpenAI({ endpoint, apiKey, apiVersion, deployment }); + const result = await client.chat.completions.create({ + messages: [ + { role: "system", content: "You are a helpful assistant." }, + { role: "user", content: "Does Azure OpenAI support customer managed keys?" }, + { role: "assistant", content: "Yes, customer managed keys are supported by Azure OpenAI?" }, + { role: "user", content: "Do other Azure AI services support this too?" }, + ], + model: "", + }); + + for (const choice of result.choices) { + console.log(choice.message); + } +} + +main().catch((err) => { + console.error("The sample encountered an error:", err); +}); + +module.exports = { main }; \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-quickstart-js/_.json b/src/ai/.x/templates/openai-chat-quickstart-js/_.json new file mode 100644 index 00000000..baf66a8b --- /dev/null +++ b/src/ai/.x/templates/openai-chat-quickstart-js/_.json @@ -0,0 +1,13 @@ +{ + "_LongName": "OpenAI Chat Completions quickstart", + "_ShortName": "openai-chat-quickstart", + "_Language": "JavaScript", + + "ClassName": "OpenAIChatCompletionsClass", + "AZURE_OPENAI_AUTH_METHOD": "KEY", + "OPENAI_CLOUD": "Azure", + + "_IS_BROWSER_TEMPLATE": "false", + "_IMPORT_EXPORT_USING_ES6": "false", + "__process_env_or_import_meta_env": "process.env", +} \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-quickstart-js/package.json b/src/ai/.x/templates/openai-chat-quickstart-js/package.json new file mode 100644 index 00000000..a6ef0b50 --- /dev/null +++ b/src/ai/.x/templates/openai-chat-quickstart-js/package.json @@ -0,0 +1,17 @@ +{ + "name": "openai-chat-docs", + "version": "1.0.0", + "description": "", + "main": "Main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "webpack": "webpack" + }, + "author": "", + "license": "MIT", + "dependencies": { + "@azure/identity": "4.1.0", + "openai": "^4.31.0", + "dotenv": "^16.0.0" + } + } diff --git a/src/ai/.x/templates/openai-chat-studioviewcode-js/Main.js b/src/ai/.x/templates/openai-chat-studioviewcode-js/Main.js new file mode 100644 index 00000000..5daca6b4 --- /dev/null +++ b/src/ai/.x/templates/openai-chat-studioviewcode-js/Main.js @@ -0,0 +1,25 @@ +import { AzureOpenAI } from "openai"; +import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; + +export async function main() { + const scope = "https://cognitiveservices.azure.com/.default"; + const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope); + const deployment = "gpt-35-turbo"; + const apiVersion = "2024-04-01-preview"; + const client = new AzureOpenAI({ azureADTokenProvider, deployment, apiVersion }); + const result = await client.chat.completions.create({ + messages: [ + { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, + { role: "user", content: "Can you help me?" }, + ], + model: '', + }); + + for (const choice of result.choices) { + console.log(choice.message); + } +} + +main().catch((err) => { + console.error("The sample encountered an error:", err); +}); \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-studioviewcode-js/_.json b/src/ai/.x/templates/openai-chat-studioviewcode-js/_.json new file mode 100644 index 00000000..1de8d6fa --- /dev/null +++ b/src/ai/.x/templates/openai-chat-studioviewcode-js/_.json @@ -0,0 +1,14 @@ +{ + "_LongName": "OpenAI Chat Completions playground viewcode", + "_ShortName": "openai-chat-studioviewcode", + "_Language": "JavaScript", + + "ClassName": "OpenAIChatCompletionsClass", + "AZURE_OPENAI_AUTH_METHOD": "KEY", + "OPENAI_CLOUD": "Azure", + + "_IS_BROWSER_TEMPLATE": "false", + "_IMPORT_EXPORT_USING_ES6": "false", + "__process_env_or_import_meta_env": "process.env", + "_IS_OPENAI_ASST_TEMPLATE": "false" +} \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-studioviewcode-js/package.json b/src/ai/.x/templates/openai-chat-studioviewcode-js/package.json new file mode 100644 index 00000000..c7d849de --- /dev/null +++ b/src/ai/.x/templates/openai-chat-studioviewcode-js/package.json @@ -0,0 +1,17 @@ +{ + "name": "openai-chat-viewcode", + "version": "1.0.0", + "description": "", + "main": "Main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "webpack": "webpack" + }, + "author": "", + "license": "MIT", + "dependencies": { + "@azure/identity": "4.1.0", + "openai": "^4.31.0" + } + } + \ No newline at end of file diff --git a/tests/ai-chat-quickstart-tests.yaml b/tests/ai-chat-quickstart-tests.yaml new file mode 100644 index 00000000..2183467b --- /dev/null +++ b/tests/ai-chat-quickstart-tests.yaml @@ -0,0 +1,15 @@ +- area: ai dev new openai-chat-quickstart-js (key) + tests: + + - class: dev new openai-chat-quickstart (javascript) + steps: + - name: generate template + command: ai dev new openai-chat-quickstart --javascript + - name: install dependencies + bash: | + cd openai-chat-quickstart-js + npm install + - name: run template + command: ai dev shell --bash "cd openai-chat-quickstart-js;node Main.js" + expect: | + The output should have positive confirmation that other Azure AI services support managed keys. \ No newline at end of file From 2d8a6577298430b2257195fcc1e88e8cb67ee820 Mon Sep 17 00:00:00 2001 From: brandom Date: Wed, 12 Jun 2024 16:18:18 -0700 Subject: [PATCH 4/8] [chore] --- src/ai/.x/templates/openai-chat-quickstart-js/_.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ai/.x/templates/openai-chat-quickstart-js/_.json b/src/ai/.x/templates/openai-chat-quickstart-js/_.json index baf66a8b..22e997e3 100644 --- a/src/ai/.x/templates/openai-chat-quickstart-js/_.json +++ b/src/ai/.x/templates/openai-chat-quickstart-js/_.json @@ -9,5 +9,4 @@ "_IS_BROWSER_TEMPLATE": "false", "_IMPORT_EXPORT_USING_ES6": "false", - "__process_env_or_import_meta_env": "process.env", -} \ No newline at end of file + "__process_env_or_import_meta_env": "process.env" \ No newline at end of file From 8e5c5c954f54851ade95fe45c7fe2cbff80941b8 Mon Sep 17 00:00:00 2001 From: brandom Date: Wed, 12 Jun 2024 16:19:01 -0700 Subject: [PATCH 5/8] revert chat template --- src/ai/.x/templates/openai-chat-js/Main.js | 90 +++------------------- 1 file changed, 9 insertions(+), 81 deletions(-) diff --git a/src/ai/.x/templates/openai-chat-js/Main.js b/src/ai/.x/templates/openai-chat-js/Main.js index 41d04eff..651f105d 100644 --- a/src/ai/.x/templates/openai-chat-js/Main.js +++ b/src/ai/.x/templates/openai-chat-js/Main.js @@ -1,90 +1,21 @@ -{{if {_IS_AUTHOR_COMMENT} }} - // Showcasing syntax differences for the same content: - // The Learn docs use CommonJS module syntax, which includes `require` and `module.exports` - // This is an older standard for working with modules in JavaScript and is widely supported, especially in Node.js. - // The Studio "view code" uses ES6 module syntax, which includes `import` and `export`. - // This is a newer standard for working with modules in JavaScript and is supported in modern browsers and Node.js versions -{{endif}} -{{if {_IS_STUDIO_VIEW_CODE_TEMPLATE}}} -import { AzureOpenAI } from "openai"; -import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity"; -{{else if {_IS_LEARN_DOC_TEMPLATE} || !{_IS_STUDIO_VIEW_CODE_TEMPLATE}}} -const { OpenAI } = require("openai"); -{{endif}} -{{if !{_IS_LEARN_DOC_TEMPLATE} || !{_IS_STUDIO_VIEW_CODE_TEMPLATE}}} +const { OpenAI } = require('openai'); const { {ClassName} } = require("./OpenAIChatCompletionsClass"); const { readline } = require("./ReadLineWrapper"); -{{endif}} -{{if {_IS_LEARN_DOC_TEMPLATE}}} -// Load the .env file if it exists -const dotenv = require("dotenv"); -dotenv.config(); - - {{if {_IS_ENTRA_ID}}} - const scope = "https://cognitiveservices.azure.com/.default"; - const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope); - {{else}} - // You will need to set these environment variables or edit the following values - const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || ""; - const apiKey = process.env["AZURE_OPENAI_API_KEY"] || ""; - {{endif}} - const apiVersion = "2024-05-01-preview"; - const deployment = "gpt-4o"; //This must match your deployment name. - require("dotenv/config"); -{{endif}} - -{{if {_IS_STUDIO_VIEW_CODE_TEMPLATE}}} -export async function main() { -{{else}} async function main() { -{{endif}} - {{if {_IS_LEARN_DOC_TEMPLATE}}} - const client = new AzureOpenAI({ endpoint, apiKey, apiVersion, deployment }); - const result = await client.chat.completions.create({ - messages: [ - { role: "system", content: "You are a helpful assistant." }, - { role: "user", content: "Does Azure OpenAI support customer managed keys?" }, - { role: "assistant", content: "Yes, customer managed keys are supported by Azure OpenAI?" }, - { role: "user", content: "Do other Azure AI services support this too?" }, - ], - model: "", - }); + // What's the system prompt? + const AZURE_OPENAI_SYSTEM_PROMPT = process.env.AZURE_OPENAI_SYSTEM_PROMPT ?? "You are a helpful AI assistant."; - {{else if {_IS_STUDIO_VIEW_CODE_TEMPLATE}}} - const scope = "https://cognitiveservices.azure.com/.default"; - const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), scope); - const deployment = "gpt-35-turbo"; - const apiVersion = "2024-04-01-preview"; - const client = new AzureOpenAI({ azureADTokenProvider, deployment, apiVersion }); - const result = await client.chat.completions.create({ - messages: [ - { role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, - { role: "user", content: "Can you help me?" }, - ], - model: '', - }); + {{@include openai.js/create.openai.js}} + // Create the streaming chat completions helper + {{if contains(toupper("{OPENAI_CLOUD}"), "AZURE")}} + const chat = new {ClassName}(AZURE_OPENAI_CHAT_DEPLOYMENT, AZURE_OPENAI_SYSTEM_PROMPT, openai); {{else}} - // What's the system prompt? - const AZURE_OPENAI_SYSTEM_PROMPT = process.env.AZURE_OPENAI_SYSTEM_PROMPT ?? "You are a helpful AI assistant."; - - {{@include openai.js/create.openai.js}} - // Create the streaming chat completions helper - {{if contains(toupper("{OPENAI_CLOUD}"), "AZURE")}} - const chat = new {ClassName}(AZURE_OPENAI_CHAT_DEPLOYMENT, AZURE_OPENAI_SYSTEM_PROMPT, openai); - {{else}} - const chat = new {ClassName}(OPENAI_MODEL_NAME, AZURE_OPENAI_SYSTEM_PROMPT, openai); - {{endif}} + const chat = new {ClassName}(OPENAI_MODEL_NAME, AZURE_OPENAI_SYSTEM_PROMPT, openai); {{endif}} -{{if {_IS_LEARN_DOC_TEMPLATE}} || {_IS_STUDIO_VIEW_CODE_TEMPLATE}} - for (const choice of result.choices) { - console.log(choice.message); - } - } -{{else}} // Loop until the user types 'exit' while (true) { @@ -100,13 +31,10 @@ async function main() { console.log('Bye!'); process.exit(); } -{{endif}} main().catch((err) => { console.error("The sample encountered an error:", err); process.exit(1); }); -{{if !{_IS_STUDIO_VIEW_CODE_TEMPLATE}}} -module.exports = { main }; -{{endif}} \ No newline at end of file +module.exports = { main }; \ No newline at end of file From 22f7ecefb7bd44a6849a41bc1cd8acaa815a143b Mon Sep 17 00:00:00 2001 From: brandom Date: Wed, 12 Jun 2024 16:21:42 -0700 Subject: [PATCH 6/8] reverting incorrect template changes --- src/ai/.x/templates/openai-chat-js/_.json | 6 +----- .../templates/openai-chat-learndocs-js/_.json | 16 ---------------- .../openai-chat-learndocs-js/package.json | 17 ----------------- 3 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 src/ai/.x/templates/openai-chat-learndocs-js/_.json delete mode 100644 src/ai/.x/templates/openai-chat-learndocs-js/package.json diff --git a/src/ai/.x/templates/openai-chat-js/_.json b/src/ai/.x/templates/openai-chat-js/_.json index c6561749..ce31afbb 100644 --- a/src/ai/.x/templates/openai-chat-js/_.json +++ b/src/ai/.x/templates/openai-chat-js/_.json @@ -10,9 +10,5 @@ "_IS_BROWSER_TEMPLATE": "false", "_IMPORT_EXPORT_USING_ES6": "false", "__process_env_or_import_meta_env": "process.env", - "_IS_OPENAI_ASST_TEMPLATE": "false", - "_IS_STUDIO_VIEW_CODE_TEMPLATE": "false", - "_IS_LEARN_DOC_TEMPLATE": "true", - "_IS_AUTHOR_COMMENT": "false", - "_IS_ENTRA_ID": "false" + "_IS_OPENAI_ASST_TEMPLATE": "false" } \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-learndocs-js/_.json b/src/ai/.x/templates/openai-chat-learndocs-js/_.json deleted file mode 100644 index c049d4b4..00000000 --- a/src/ai/.x/templates/openai-chat-learndocs-js/_.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "_LongName": "OpenAI Chat Completions quickstart docs", - "_ShortName": "openai-chat-learndocs", - "_Language": "JavaScript", - - "ClassName": "OpenAIChatCompletionsClass", - "AZURE_OPENAI_AUTH_METHOD": "KEY", - "OPENAI_CLOUD": "Azure", - - "_IS_BROWSER_TEMPLATE": "false", - "_IMPORT_EXPORT_USING_ES6": "false", - "__process_env_or_import_meta_env": "process.env", - "_IS_OPENAI_ASST_TEMPLATE": "false", - "_IS_STUDIO_VIEW_CODE_TEMPLATE": "false", - "_IS_LEARN_DOC_TEMPLATE": "true" -} \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-learndocs-js/package.json b/src/ai/.x/templates/openai-chat-learndocs-js/package.json deleted file mode 100644 index ff130119..00000000 --- a/src/ai/.x/templates/openai-chat-learndocs-js/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "openai-chat", - "version": "1.0.0", - "description": "", - "main": "Main.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "webpack": "webpack" - }, - "author": "", - "license": "MIT", - "dependencies": { - "@azure/identity": "4.1.0", - "openai": "^4.31.0" - } - } - \ No newline at end of file From 316ac3e12a57d9673b0152ddcb0d1ab8f2168833 Mon Sep 17 00:00:00 2001 From: brandom Date: Wed, 12 Jun 2024 16:45:55 -0700 Subject: [PATCH 7/8] remove duplicate template entry --- .../openai-chat-studio-viewcode-js/_.json | 16 ---------------- .../openai-chat-studio-viewcode-js/package.json | 17 ----------------- 2 files changed, 33 deletions(-) delete mode 100644 src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json delete mode 100644 src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json diff --git a/src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json b/src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json deleted file mode 100644 index b6ba41dc..00000000 --- a/src/ai/.x/templates/openai-chat-studio-viewcode-js/_.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "_LongName": "OpenAI Chat Completions Studio view code", - "_ShortName": "openai-chat-studio-viewcode", - "_Language": "JavaScript", - - "ClassName": "OpenAIChatCompletionsClass", - "AZURE_OPENAI_AUTH_METHOD": "KEY", - "OPENAI_CLOUD": "Azure", - - "_IS_BROWSER_TEMPLATE": "false", - "_IMPORT_EXPORT_USING_ES6": "false", - "__process_env_or_import_meta_env": "process.env", - "_IS_OPENAI_ASST_TEMPLATE": "false", - "_IS_STUDIO_VIEW_CODE_TEMPLATE": "true", - "_IS_LEARN_DOC_TEMPLATE": "false" -} \ No newline at end of file diff --git a/src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json b/src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json deleted file mode 100644 index ff130119..00000000 --- a/src/ai/.x/templates/openai-chat-studio-viewcode-js/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "openai-chat", - "version": "1.0.0", - "description": "", - "main": "Main.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "webpack": "webpack" - }, - "author": "", - "license": "MIT", - "dependencies": { - "@azure/identity": "4.1.0", - "openai": "^4.31.0" - } - } - \ No newline at end of file From d6bb4b27c150dec05411898c8bc6c9ae0dd19ae9 Mon Sep 17 00:00:00 2001 From: brandom Date: Wed, 12 Jun 2024 16:58:48 -0700 Subject: [PATCH 8/8] [chore] --- src/ai/.x/templates/openai-chat-quickstart-js/_.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ai/.x/templates/openai-chat-quickstart-js/_.json b/src/ai/.x/templates/openai-chat-quickstart-js/_.json index 22e997e3..f2e8a2ab 100644 --- a/src/ai/.x/templates/openai-chat-quickstart-js/_.json +++ b/src/ai/.x/templates/openai-chat-quickstart-js/_.json @@ -9,4 +9,5 @@ "_IS_BROWSER_TEMPLATE": "false", "_IMPORT_EXPORT_USING_ES6": "false", - "__process_env_or_import_meta_env": "process.env" \ No newline at end of file + "__process_env_or_import_meta_env": "process.env" +} \ No newline at end of file