-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_model.js
More file actions
executable file
·51 lines (40 loc) · 1.53 KB
/
run_model.js
File metadata and controls
executable file
·51 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { AzureOpenAI } from "openai";
import dotenv from "dotenv";
dotenv.config();
export async function main() {
// Load environment variables
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"];
const apiKey = process.env["AZURE_OPENAI_API_KEY"];
const apiVersion = "2025-01-01-preview";
const deployment = "gpt-35-turbo"; // This must match your deployment name
const model = process.env["MODEL_NAME"];
// Check for missing environment variables
if (!endpoint || !apiKey || apiKey === "<REPLACE_WITH_YOUR_KEY_VALUE_HERE>") {
console.error("Error: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_API_KEY must be set in your .env file.");
return;
}
// Get user prompt from command line arguments
const userPrompt = process.argv[2];
if (!userPrompt) {
console.error("Error: Please provide a prompt as a command-line argument.");
console.error('Usage: node run_model.js "Your prompt here"');
return;
}
const client = new AzureOpenAI({ endpoint, apiKey, apiVersion, deployment });
// In-memory conversation history
const messages = [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: userPrompt },
];
console.log(`Sending prompt to Azure OpenAI: "${userPrompt}"`);
const result = await client.chat.completions.create({
model : model,
messages: messages,
max_tokens: 800,
temperature: 0.7,
});
console.log("Assistant:", result.choices[0].message.content);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});