-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from koreyspace/main
Added Github Models JS Lessons
- Loading branch information
Showing
17 changed files
with
2,448 additions
and
58 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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"; | ||
const modelName = "gpt-4o"; | ||
|
||
export async function main() { | ||
|
||
console.log("== Recipe Recommendation App =="); | ||
|
||
console.log("Number of recipes: (for example: 5): "); | ||
const numRecipes = "3"; | ||
|
||
console.log("List of ingredients: (for example: chicken, potatoes, and carrots): "); | ||
const ingredients = "chocolate"; | ||
|
||
console.log("Filter (for example: vegetarian, vegan, or gluten-free): "); | ||
const filter = "peanuts"; | ||
|
||
const promptText = `Show me ${numRecipes} recipes for a dish with the following ingredients: ${ingredients}. Per recipe, list all the ingredients used, no ${filter}: `; | ||
|
||
|
||
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: promptText } | ||
], | ||
model: modelName, | ||
temperature: 1.0, | ||
max_tokens: 1000, | ||
top_p: 1.0 | ||
} | ||
}); | ||
|
||
try { | ||
|
||
|
||
if (response.status !== "200") { | ||
throw response.body.error; | ||
} | ||
console.log(response.body.choices[0].message.content); | ||
|
||
|
||
const oldPromptResult = response.body.choices[0].message.content; | ||
|
||
const promptShoppingList = 'Produce a shopping list, and please do not include the following ingredients that I already have at home: '; | ||
|
||
const newPrompt = `Given ingredients at home: ${ingredients} and these generated recipes: ${oldPromptResult}, ${promptShoppingList}`; | ||
|
||
const shoppingListMessage = | ||
await client.path("/chat/completions").post({ | ||
body: { | ||
messages: [ | ||
{ | ||
role: 'system', | ||
content: 'Here is your shopping list:' | ||
}, | ||
{ | ||
role: 'user', | ||
content: newPrompt | ||
}, | ||
], | ||
model: modelName, | ||
} | ||
|
||
}) | ||
|
||
} catch (error) { | ||
console.log('The sample encountered an error: ', error); | ||
} | ||
} | ||
|
||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); |
285 changes: 285 additions & 0 deletions
285
06-text-generation-apps/js-githubmodels/package-lock.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"@azure-rest/ai-inference": "latest", | ||
"@azure/core-auth": "latest", | ||
"@azure/core-sse": "latest" | ||
} | ||
} |
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*****" |
Oops, something went wrong.