-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path08-azure-openai.ts
36 lines (29 loc) · 1.05 KB
/
08-azure-openai.ts
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
// This example demonstrates how to use the Azure OpenAI API to generate chat
// completions and embeddings.
// You can learn more about Azure OpenAI at here:
// https://learn.microsoft.com/azure/ai-services/openai/overview
//
// NOTE: To run this example, you must first start the Azure OpenAI emulator by
// running the following command in a terminal and keeping it running:
//
// ollamazure -d
//
import { AzureOpenAI } from 'openai';
const openai = new AzureOpenAI({
endpoint: 'http://localhost:4041',
// Parameters below must be provided but are not used by the local server
apiKey: '__not_needed_by_ollama__',
apiVersion: '2024-02-01',
});
const chatCompletion = await openai.chat.completions.create({
model: 'phi3',
messages: [{ role: 'user', content: 'Say hello!' }]
});
console.log(chatCompletion.choices[0].message.content);
const embeddings = await openai.embeddings.create({
model: 'all-minilm:l6-v2',
input: ['Once upon a time', 'The end.']
});
for (const embedding of embeddings.data) {
console.log(embedding.embedding.slice(0, 3));
}