Skip to content

Commit

Permalink
re-enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrenner committed Feb 13, 2025
1 parent 3d968fa commit a404326
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const {
} = require('../../../../integration-tests/helpers')
const { assert } = require('chai')

// there is currently an issue with langchain + esm loader hooks from IITM
// https://github.com/nodejs/import-in-the-middle/issues/163
describe.skip('esm', () => {
describe('esm', () => {
let agent
let proc
let sandbox
Expand Down Expand Up @@ -47,7 +45,9 @@ describe.skip('esm', () => {
assert.strictEqual(checkSpansForServiceName(payload, 'langchain.request'), true)
})

proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, null, {
NODE_OPTIONS: '--import dd-trace/register.js'
})

await res
}).timeout(20000)
Expand Down
14 changes: 12 additions & 2 deletions packages/datadog-plugin-langchain/test/integration-test/server.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import 'dd-trace/init.js'

import { OpenAI } from '@langchain/openai'
import { StringOutputParser } from '@langchain/core/output_parsers'
import nock from 'nock'

nock('https://api.openai.com:443')
.post('/v1/completions')
.reply(200, {})
.reply(200, {
model: 'gpt-3.5-turbo-instruct',
choices: [{
text: 'The answer is 4',
index: 0,
logprobs: null,
finish_reason: 'length'
}],
usage: { prompt_tokens: 8, completion_tokens: 12, otal_tokens: 20 }
})

const llm = new OpenAI({
apiKey: '<not-a-real-key>'
Expand All @@ -15,4 +25,4 @@ const parser = new StringOutputParser()

const chain = llm.pipe(parser)

await chain.invoke('a test')
await chain.invoke('what is 2 + 2?')
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('esm', () => {
let sandbox

// limit v4 tests while the IITM issue is resolved or a workaround is introduced
// this is only relevant for `openai` >=4.0 <=4.1
// issue link: https://github.com/DataDog/import-in-the-middle/issues/60
withVersions('openai', 'openai', '>=3 <4', version => {
withVersions('openai', 'openai', '>=3 <4.0.0 || >4.1.0', version => {
before(async function () {
this.timeout(20000)
sandbox = await createSandbox([`'openai@${version}'`, 'nock'], false, [
Expand All @@ -43,9 +44,11 @@ describe('esm', () => {
assert.strictEqual(checkSpansForServiceName(payload, 'openai.request'), true)
})

proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port)
proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port, null, {
NODE_OPTIONS: '--import dd-trace/register.js'
})

await res
}).timeout(20000)
}).timeout(5000)
})
})
33 changes: 23 additions & 10 deletions packages/datadog-plugin-openai/test/integration-test/server.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import 'dd-trace/init.js'
import openai from 'openai'
import OpenAI from 'openai'
import nock from 'nock'

nock('https://api.openai.com:443')
.post('/v1/completions')
.reply(200, {})

const openaiApp = new openai.OpenAIApi(new openai.Configuration({
apiKey: 'sk-DATADOG-ACCEPTANCE-TESTS'
}))
if (OpenAI.OpenAIApi) {
const openaiApp = new OpenAI.OpenAIApi(new OpenAI.Configuration({
apiKey: 'sk-DATADOG-ACCEPTANCE-TESTS'
}))

await openaiApp.createCompletion({
model: 'text-davinci-002',
prompt: 'Hello, ',
suffix: 'foo',
stream: true
})
await openaiApp.createCompletion({
model: 'text-davinci-002',
prompt: 'Hello, ',
suffix: 'foo',
stream: true
})
} else {
const client = new OpenAI({
apiKey: 'sk-DATADOG-ACCEPTANCE-TESTS'
})

await client.completions.create({
model: 'text-davinci-002',
prompt: 'Hello, ',
suffix: 'foo',
stream: false
})
}

0 comments on commit a404326

Please sign in to comment.