/
chat-completion-message.test.js
79 lines (70 loc) · 1.66 KB
/
chat-completion-message.test.js
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
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const tap = require('tap')
const LangChainCompletionMessage = require('../../../../lib/llm-events/langchain/chat-completion-message')
tap.beforeEach((t) => {
t.context._tx = {
trace: {
custom: {
get() {
return {
'llm.conversation_id': 'test-conversation'
}
}
}
}
}
t.context.agent = {
config: {
applications() {
return ['test-app']
}
},
tracer: {
getTransaction() {
return t.context._tx
}
}
}
t.context.segment = {
id: 'segment-1',
transaction: {
id: 'tx-1',
traceId: 'trace-1'
}
}
t.context.runId = 'run-1'
t.context.metadata = { foo: 'foo' }
})
tap.test('creates entity', async (t) => {
const msg = new LangChainCompletionMessage({
...t.context,
sequence: 1,
content: 'hello world'
})
t.match(msg, {
id: 'run-1-1',
appName: 'test-app',
['llm.conversation_id']: 'test-conversation',
span_id: 'segment-1',
request_id: 'run-1',
transaction_id: 'tx-1',
trace_id: 'trace-1',
['metadata.foo']: 'foo',
ingest_source: 'Node',
vendor: 'langchain',
virtual_llm: true,
sequence: 1,
content: 'hello world',
completion_id: /[a-z0-9-]{36}/
})
})
tap.test('assigns id correctly', async (t) => {
let msg = new LangChainCompletionMessage({ ...t.context, runId: '', sequence: 1 })
t.match(msg.id, /[a-z0-9-]{36}-1/)
msg = new LangChainCompletionMessage({ ...t.context, runId: '123456', sequence: 42 })
t.equal(msg.id, '123456-42')
})