forked from microsoft/generative-ai-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8139eff
commit c5a520d
Showing
5 changed files
with
313 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
# Used to authenticate with the Azure OpenAI. Retrieve these | ||
|
||
# values from an Azure OpenAI instance in the Azure Portal. | ||
|
||
ENDPOINT="https://<resource name>.openai.azure.com" | ||
AZURE_API_KEY="<azure api key>" | ||
OPENAI_API_KEY="<openai api key>" | ||
OPENAI_API_KEY="<openai api key>" | ||
|
||
# get your pat token from: https://github.com/settings/tokens?type=beta | ||
|
||
GITHUB_TOKEN="github_pat*****" |
8 changes: 6 additions & 2 deletions
8
06-text-generation-apps/typescript/recipe-app/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
06-text-generation-apps/typescript/recipe-app/src/main-ghmodels.js
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,44 @@ | ||
import ModelClient from "@azure-rest/ai-inference"; | ||
import { AzureKeyCredential } from "@azure/core-auth"; | ||
|
||
const token = process.env["GITHUB_TOKEN"]; | ||
const endpoint = "https://models.inference.ai.azure.com"; | ||
|
||
/* By using the Azure AI Inference SDK, you can easily experiment with different models | ||
by modifying the value of `modelName` in the code below. The following models are | ||
available in the GitHub Models service: | ||
AI21 Labs: AI21-Jamba-Instruct | ||
Cohere: Cohere-command-r, Cohere-command-r-plus | ||
Meta: Meta-Llama-3-70B-Instruct, Meta-Llama-3-8B-Instruct, Meta-Llama-3.1-405B-Instruct, Meta-Llama-3.1-70B-Instruct, Meta-Llama-3.1-8B-Instruct | ||
Mistral AI: Mistral-large, Mistral-large-2407, Mistral-Nemo, Mistral-small | ||
Azure OpenAI: gpt-4o-mini, gpt-4o | ||
Microsoft: Phi-3-medium-128k-instruct, Phi-3-medium-4k-instruct, Phi-3-mini-128k-instruct, Phi-3-mini-4k-instruct, Phi-3-small-128k-instruct, Phi-3-small-8k-instruct */ | ||
const modelName = "gpt-4o-mini"; | ||
|
||
export async function main() { | ||
const client = new ModelClient(endpoint, new AzureKeyCredential(token)); | ||
|
||
const response = await client.path("/chat/completions").post({ | ||
body: { | ||
messages: [ | ||
{ role: "system", content: "You are a helpful assistant." }, | ||
{ role: "user", content: "What is the capital of France?" }, | ||
], | ||
model: modelName, | ||
// Optional parameters | ||
temperature: 1, | ||
max_tokens: 1000, | ||
top_p: 1, | ||
}, | ||
}); | ||
|
||
if (response.status !== "200") { | ||
throw response.body.error; | ||
} | ||
console.log(response.body.choices[0].message.content); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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