-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathdemo-complete.ts
39 lines (32 loc) · 1.48 KB
/
demo-complete.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
37
38
39
import process from "node:process";
import { AzureOpenAI as OpenAI } from "openai";
const prompt = `
## Available products
| Product Name | Characteristics |
|--------------|-----------------|
| Contoso Trek | Waterproof hiking boots with advanced grip technology for all terrains. Features include breathable material and ankle support. |
| Contoso Dash | Lightweight running shoes with responsive cushioning. Designed for speed and comfort, with a mesh upper for breathability. |
| Contoso Glide | Slip-on casual shoes with a sleek design. Offers comfort for all-day wear with memory foam insoles and a flexible sole. |
| Contoso Flex | Athletic shoes with a flexible sole designed for a wide range of sports. Features include enhanced durability and support for lateral movements. |
| Contoso Chill | Cozy and stylish winter boots with thermal lining and waterproof exterior. Includes a slip-resistant sole for icy conditions. |
## User details
Name: John Doe
Assistant helps the user with questions about products for the company "Contoso Shoes".
Be brief, answer with 2 lines max. Be cheerful and mention user's name.
## Question
What shoes should I use for running?
## Answer
{
"text": "<answer>",
"product": "<product_name>"
}
`;
const openai = new OpenAI();
const chunks = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-4o",
stream: true,
});
for await (const chunk of chunks) {
process.stdout.write(chunk.choices[0]?.delta.content ?? '');
}