Skip to content

Commit c5a520d

Browse files
committed
recipe-testjs
1 parent 8139eff commit c5a520d

File tree

5 files changed

+313
-6
lines changed

5 files changed

+313
-6
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Used to authenticate with the Azure OpenAI. Retrieve these
2+
23
# values from an Azure OpenAI instance in the Azure Portal.
34

45
ENDPOINT="https://<resource name>.openai.azure.com"
56
AZURE_API_KEY="<azure api key>"
6-
OPENAI_API_KEY="<openai api key>"
7+
OPENAI_API_KEY="<openai api key>"
8+
9+
# get your pat token from: https://github.com/settings/tokens?type=beta
10+
11+
GITHUB_TOKEN="github_pat*****"

06-text-generation-apps/typescript/recipe-app/package-lock.json

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import ModelClient from "@azure-rest/ai-inference";
2+
import { AzureKeyCredential } from "@azure/core-auth";
3+
4+
const token = process.env["GITHUB_TOKEN"];
5+
const endpoint = "https://models.inference.ai.azure.com";
6+
7+
/* By using the Azure AI Inference SDK, you can easily experiment with different models
8+
by modifying the value of `modelName` in the code below. The following models are
9+
available in the GitHub Models service:
10+
11+
AI21 Labs: AI21-Jamba-Instruct
12+
Cohere: Cohere-command-r, Cohere-command-r-plus
13+
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
14+
Mistral AI: Mistral-large, Mistral-large-2407, Mistral-Nemo, Mistral-small
15+
Azure OpenAI: gpt-4o-mini, gpt-4o
16+
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 */
17+
const modelName = "gpt-4o-mini";
18+
19+
export async function main() {
20+
const client = new ModelClient(endpoint, new AzureKeyCredential(token));
21+
22+
const response = await client.path("/chat/completions").post({
23+
body: {
24+
messages: [
25+
{ role: "system", content: "You are a helpful assistant." },
26+
{ role: "user", content: "What is the capital of France?" },
27+
],
28+
model: modelName,
29+
// Optional parameters
30+
temperature: 1,
31+
max_tokens: 1000,
32+
top_p: 1,
33+
},
34+
});
35+
36+
if (response.status !== "200") {
37+
throw response.body.error;
38+
}
39+
console.log(response.body.choices[0].message.content);
40+
}
41+
42+
main().catch((err) => {
43+
console.error("The sample encountered an error:", err);
44+
});

package-lock.json

Lines changed: 254 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
},
2323
"homepage": "https://github.com/microsoft/generative-ai-for-beginners#readme",
2424
"devDependencies": {
25+
"@types/node": "^22.5.5",
2526
"docsify-to-pdf": "0.0.5"
2627
},
2728
"dependencies": {
29+
"@azure-rest/ai-inference": "^1.0.0-beta.2",
30+
"@azure/core-auth": "^1.8.0",
2831
"openai": "^4.10.0"
2932
}
3033
}

0 commit comments

Comments
 (0)