Skip to content

Commit

Permalink
recipe-testjs
Browse files Browse the repository at this point in the history
  • Loading branch information
koreyspace committed Sep 17, 2024
1 parent 8139eff commit c5a520d
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 6 deletions.
7 changes: 6 additions & 1 deletion 06-text-generation-apps/typescript/recipe-app/.env-sample
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*****"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions 06-text-generation-apps/typescript/recipe-app/src/main-ghmodels.js
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);
});
257 changes: 254 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
},
"homepage": "https://github.com/microsoft/generative-ai-for-beginners#readme",
"devDependencies": {
"@types/node": "^22.5.5",
"docsify-to-pdf": "0.0.5"
},
"dependencies": {
"@azure-rest/ai-inference": "^1.0.0-beta.2",
"@azure/core-auth": "^1.8.0",
"openai": "^4.10.0"
}
}

0 comments on commit c5a520d

Please sign in to comment.