-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add templates for JS Chat quickstart and viewcode #313
Open
brandom-msft
wants to merge
9
commits into
main
Choose a base branch
from
brandom/js-docs-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
34f3585
view code and docs template 1st draft
brandom-msft d597468
create separate template dirs
brandom-msft cdad912
add quickstart-js template and test
brandom-msft 939b37d
Merge branch 'brandom/js-docs-template' of https://github.com/Azure/a…
brandom-msft 2d8a657
[chore]
brandom-msft 8e5c5c9
revert chat template
brandom-msft 22f7ece
reverting incorrect template changes
brandom-msft 316ac3e
remove duplicate template entry
brandom-msft d6bb4b2
[chore]
brandom-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] || "<endpoint>"; | ||
const apiKey = process.env["AZURE_OPENAI_API_KEY"] || "<api key>"; | ||
const apiVersion = "2024-05-01-preview"; | ||
const deployment = process.env["AZURE_OPENAI_DEPLOYMENT"] || "<deployment name>"; //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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"_LongName": "OpenAI Chat Completions quickstart", | ||
"_ShortName": "openai-chat-quickstart", | ||
"_Language": "JavaScript", | ||
|
||
"ClassName": "OpenAIChatCompletionsClass", | ||
"AZURE_OPENAI_AUTH_METHOD": "KEY", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the values in this _.json file used anywhere? I'm not seeing them elsewhere. |
||
"OPENAI_CLOUD": "Azure", | ||
|
||
"_IS_BROWSER_TEMPLATE": "false", | ||
"_IMPORT_EXPORT_USING_ES6": "false", | ||
"__process_env_or_import_meta_env": "process.env" | ||
} |
17 changes: 17 additions & 0 deletions
17
src/ai/.x/templates/openai-chat-quickstart-js/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
17 changes: 17 additions & 0 deletions
17
src/ai/.x/templates/openai-chat-studioviewcode-js/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line what puts the env vars into the
process.env
object? Where did the env vars get defined?