Skip to content

Commit d5e5b6f

Browse files
authored
feat(gen-ai): add eval tests COMPASS-10084 (#7641)
* add feature flag * migrate prompts to compass * co-pilot feedback * clean up * use edu api for gen ai * clean up a bit * fix url for test and ensure aggregations have content * tests * fix error handling * clean up transport * changes in field name * use query parser * fix check * fix test * clean up * copilot feedback * fix log id * fix cors issue on e2e tests * more tests * add type * wip * fix alltext * make expected output xml string * add fixtures and run gen ai eval tests * ts fixes * reformat * clean up scorer * bootstrap * remove extra files * bootstrap * fix prompts and data * copilot review * reduce num of docs * reduce fixtures * check fix
1 parent a75a09b commit d5e5b6f

File tree

15 files changed

+2649
-1
lines changed

15 files changed

+2649
-1
lines changed

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-generative-ai/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"test-watch": "npm run test -- --watch",
5050
"test-ci": "npm run test-cov",
5151
"test-ci-electron": "npm run test-electron",
52-
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
52+
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write .",
53+
"eval": "braintrust eval tests/evals"
5354
},
5455
"dependencies": {
5556
"@mongodb-js/atlas-service": "^0.74.1",
@@ -84,10 +85,13 @@
8485
"@types/mocha": "^9.0.0",
8586
"@types/react": "^17.0.5",
8687
"@types/sinon-chai": "^3.2.5",
88+
"autoevals": "^0.0.130",
89+
"braintrust": "^0.2.4",
8790
"chai": "^4.3.6",
8891
"depcheck": "^1.4.1",
8992
"electron-mocha": "^12.2.0",
9093
"mocha": "^10.2.0",
94+
"mongodb-ns": "^3.1.0",
9195
"nyc": "^15.1.0",
9296
"p-queue": "^7.4.1",
9397
"sinon": "^9.2.3",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { streamText } from 'ai';
2+
import { createOpenAI } from '@ai-sdk/openai';
3+
import type {
4+
ConversationEvalCaseInput,
5+
ConversationTaskOutput,
6+
} from './types';
7+
8+
export async function makeChatbotCall(
9+
input: ConversationEvalCaseInput
10+
): Promise<ConversationTaskOutput> {
11+
const openai = createOpenAI({
12+
baseURL:
13+
process.env.COMPASS_ASSISTANT_BASE_URL_OVERRIDE ??
14+
'https://eval.knowledge-dev.mongodb.com/api/v1',
15+
apiKey: '',
16+
headers: {
17+
'X-Request-Origin': 'compass-gen-ai-braintrust',
18+
'User-Agent': 'mongodb-compass/x.x.x',
19+
},
20+
});
21+
const result = streamText({
22+
model: openai.responses('mongodb-slim-latest'),
23+
temperature: undefined,
24+
prompt: input.messages,
25+
providerOptions: {
26+
openai: {
27+
instructions: input.instructions.content,
28+
store: false,
29+
},
30+
},
31+
});
32+
33+
const chunks: string[] = [];
34+
for await (const chunk of result.toUIMessageStream()) {
35+
if (chunk.type === 'text-delta') {
36+
chunks.push(chunk.delta);
37+
}
38+
}
39+
return {
40+
messages: [{ content: chunks.join('') }],
41+
};
42+
}

0 commit comments

Comments
 (0)