-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathplayground.ts
108 lines (99 loc) · 2.76 KB
/
playground.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {
AnthropicBedrockChatApi,
AnthropicChatApi,
OpenAIChatApi,
} from './src';
import { GroqChatApi } from './src/models/groq';
(async function go() {
let client:
| OpenAIChatApi
| AnthropicChatApi
| AnthropicBedrockChatApi
| GroqChatApi
| undefined;
if (process.env.OPENAI_KEY) {
client = new OpenAIChatApi(
{
apiKey: process.env.OPENAI_KEY ?? 'YOUR_client_KEY',
},
{ stream: true, contextSize: 4096, model: 'gpt-4-turbo' },
);
const resfn = await client?.textCompletion('Hello', {
callFunction: 'print',
functions: [
{
name: 'print',
parameters: {
type: 'object',
properties: {
text: { type: 'string', description: 'the string to print' },
},
},
description: 'ALWAYS call this function',
},
],
});
console.info('Response fn: ', resfn);
} else if (process.env.ANTHROPIC_KEY) {
client = new AnthropicChatApi(
{
apiKey: process.env.ANTHROPIC_KEY ?? 'YOUR_client_KEY',
},
{ stream: true, temperature: 0 },
);
} else if (
process.env.AWS_BEDROCK_ACCESS_KEY &&
process.env.AWS_BEDROCK_SECRET_KEY
) {
client = new AnthropicBedrockChatApi(
{
accessKeyId: process.env.AWS_BEDROCK_ACCESS_KEY ?? 'YOUR_access_key',
secretAccessKey:
process.env.AWS_BEDROCK_SECRET_KEY ?? 'YOUR_secret_key',
},
{ stream: true, temperature: 0, model: 'anthropic.claude-v2' },
);
} else if (process.env.GROQ_KEY) {
client = new GroqChatApi(
{
apiKey: process.env.GROQ_KEY ?? 'YOUR_client_KEY',
},
{ stream: true, temperature: 0 },
);
}
const res0 = await client?.textCompletion('Hello', {
systemMessage: 'You will respond to all human messages in JSON',
responsePrefix: '{ "message": "',
});
console.info('Response 0: ', res0);
const res01 = await res0?.respond('Hello 2');
console.info('Response 0.1: ', res01);
const resEm = await client?.textCompletion('✨');
console.info('Response em: ', resEm);
const res1 = await client?.textCompletion('Hello', {
maximumResponseTokens: 2,
});
console.info('Response 1: ', res1);
const res2 = await client?.chatCompletion([
{ role: 'user', content: 'hello' },
{
role: 'assistant',
toolCall: {
id: '1',
type: 'function',
function: {
name: 'print',
arguments: '{"hello": "world"}',
},
},
},
{
role: 'tool',
toolCallId: '1',
content: '{ success: true }',
},
]);
console.info('Response 2: ', res2);
const res3 = await res2?.respond({ role: 'user', content: 'testing 123' });
console.info('Response 3: ', res3);
})();