-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathanthropic-utils.test.ts
More file actions
56 lines (50 loc) · 1.85 KB
/
anthropic-utils.test.ts
File metadata and controls
56 lines (50 loc) · 1.85 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
52
53
54
55
56
import { describe, expect, it } from 'vitest';
import { messagesFromParams, shouldInstrument } from '../../../src/tracing/anthropic-ai/utils';
describe('anthropic-ai-utils', () => {
describe('shouldInstrument', () => {
it('should instrument known methods', () => {
expect(shouldInstrument('models.get')).toBe(true);
});
it('should not instrument unknown methods', () => {
expect(shouldInstrument('models.unknown.thing')).toBe(false);
});
});
describe('messagesFromParams', () => {
it('includes system message in messages list', () => {
expect(
messagesFromParams({
messages: [{ role: 'user', content: 'hello' }],
system: 'You are a friendly robot awaiting a greeting.',
}),
).toStrictEqual([
{ role: 'system', content: 'You are a friendly robot awaiting a greeting.' },
{ role: 'user', content: 'hello' },
]);
});
it('includes system message along with non-array messages', () => {
expect(
messagesFromParams({
messages: { role: 'user', content: 'hello' },
system: 'You are a friendly robot awaiting a greeting.',
}),
).toStrictEqual([
{ role: 'system', content: 'You are a friendly robot awaiting a greeting.' },
{ role: 'user', content: 'hello' },
]);
});
it('includes system message if no other messages', () => {
expect(
messagesFromParams({
system: 'You are a friendly robot awaiting a greeting.',
}),
).toStrictEqual([{ role: 'system', content: 'You are a friendly robot awaiting a greeting.' }]);
});
it('returns messages if no system message', () => {
expect(
messagesFromParams({
messages: [{ role: 'user', content: 'hello' }],
}),
).toStrictEqual([{ role: 'user', content: 'hello' }]);
});
});
});