-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem-prompt-perplexity-streaming.ts
More file actions
47 lines (42 loc) · 1.35 KB
/
system-prompt-perplexity-streaming.ts
File metadata and controls
47 lines (42 loc) · 1.35 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
import dotenv from "dotenv";
import { type PromptFinishReason, type Usage, systemPromptStreaming } from "../src";
// load api keys from .env
dotenv.config();
console.log("Streaming Perplexity llama-3-sonar-large-32k-online:")
await systemPromptStreaming(
"Be grounded and precise. If no answer is found, report that no evidence is available. When was the re-union of Germany?",
"perplexity",
async (partialText: string, elapsedMs: number) => {
// onChunk
// stream-write to console
process.stdout.write(partialText);
},
async (fullText: string,
elapsedMs: number,
usage: Usage,
finishReason: PromptFinishReason) => {
// onStop
// you will get the full text here again, accumulated
//console.log("Full result", fullText);
console.log("")
console.log("parsed JSON", JSON.parse(fullText));
console.log("finishReason", finishReason);
console.log("elapsedMs", elapsedMs);
console.log("usage", usage);
},
async (error: unknown, elapsedMs: number) => {
// onError
console.log("error", error, elapsedMs, 'ms elapsed');
},
{
// model identifier of the provider
model: "llama-3-sonar-large-32k-online",
temperature: 0.001,
return_citations: true,
return_images: true,
},
{
// union of options passed down, mapped internally
apiKey: process.env[`perplexity_api_key`],
},
);