|
| 1 | +import { describeAccuracyTests } from "./sdk/describe-accuracy-tests.js"; |
| 2 | +import { getAvailableModels } from "./sdk/models.js"; |
| 3 | +import { AccuracyTestConfig } from "./sdk/describe-accuracy-tests.js"; |
| 4 | +import { findResponse } from "../../src/tools/mongodb/read/find.js"; |
| 5 | +import { MockedTools } from "./sdk/test-tools.js"; |
| 6 | +import { collectionSchemaResponse } from "../../src/tools/mongodb/metadata/collectionSchema.js"; |
| 7 | +import { getSimplifiedSchema } from "mongodb-schema"; |
| 8 | + |
| 9 | +const documents = [ |
| 10 | + { |
| 11 | + title: "book1", |
| 12 | + author: "author1", |
| 13 | + date_of_publish: "01.01.1990", |
| 14 | + }, |
| 15 | + { |
| 16 | + title: "book2", |
| 17 | + author: "author1", |
| 18 | + date_of_publish: "01.01.1992", |
| 19 | + }, |
| 20 | + { |
| 21 | + title: "book3", |
| 22 | + author: "author2", |
| 23 | + date_of_publish: "01.01.1990", |
| 24 | + }, |
| 25 | +]; |
| 26 | + |
| 27 | +function callsFindNoFilter(prompt: string): AccuracyTestConfig { |
| 28 | + return { |
| 29 | + injectConnectedAssumption: true, |
| 30 | + prompt: prompt, |
| 31 | + mockedTools: { |
| 32 | + "collection-schema": async () => |
| 33 | + collectionSchemaResponse("db1", "coll1", await getSimplifiedSchema(documents)), |
| 34 | + find: () => findResponse("coll1", documents), |
| 35 | + }, |
| 36 | + expectedToolCalls: [ |
| 37 | + { |
| 38 | + toolName: "find", |
| 39 | + parameters: { |
| 40 | + database: "db1", |
| 41 | + collection: "coll1", |
| 42 | + }, |
| 43 | + }, |
| 44 | + ], |
| 45 | + }; |
| 46 | +} |
| 47 | + |
| 48 | +function callsFindWithFilter(prompt: string): AccuracyTestConfig { |
| 49 | + return { |
| 50 | + injectConnectedAssumption: true, |
| 51 | + prompt: prompt, |
| 52 | + mockedTools: { |
| 53 | + "collection-schema": async () => |
| 54 | + collectionSchemaResponse("db1", "coll1", await getSimplifiedSchema(documents)), |
| 55 | + find: () => |
| 56 | + findResponse( |
| 57 | + "coll1", |
| 58 | + documents.filter((doc) => doc.author === "author1") |
| 59 | + ), |
| 60 | + }, |
| 61 | + expectedToolCalls: [ |
| 62 | + { |
| 63 | + toolName: "find", |
| 64 | + parameters: { |
| 65 | + database: "db1", |
| 66 | + collection: "coll1", |
| 67 | + filter: { author: "author1" }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + ], |
| 71 | + }; |
| 72 | +} |
| 73 | + |
| 74 | +function callsFindWithProjection(prompt: string): AccuracyTestConfig { |
| 75 | + return { |
| 76 | + injectConnectedAssumption: true, |
| 77 | + prompt: prompt, |
| 78 | + mockedTools: { |
| 79 | + "collection-schema": async () => |
| 80 | + collectionSchemaResponse("db1", "coll1", await getSimplifiedSchema(documents)), |
| 81 | + find: () => findResponse("coll1", documents), |
| 82 | + }, |
| 83 | + expectedToolCalls: [ |
| 84 | + { |
| 85 | + toolName: "find", |
| 86 | + parameters: { |
| 87 | + database: "db1", |
| 88 | + collection: "coll1", |
| 89 | + projection: { title: 1 }, |
| 90 | + }, |
| 91 | + }, |
| 92 | + ], |
| 93 | + }; |
| 94 | +} |
| 95 | + |
| 96 | +function callsFindWithProjectionAndFilters(prompt: string): AccuracyTestConfig { |
| 97 | + return { |
| 98 | + injectConnectedAssumption: true, |
| 99 | + prompt: prompt, |
| 100 | + mockedTools: { |
| 101 | + "collection-schema": async () => |
| 102 | + collectionSchemaResponse("db1", "coll1", await getSimplifiedSchema(documents)), |
| 103 | + find: () => |
| 104 | + findResponse( |
| 105 | + "coll1", |
| 106 | + documents.filter((doc) => doc.date_of_publish === "01.01.1992") |
| 107 | + ), |
| 108 | + }, |
| 109 | + expectedToolCalls: [ |
| 110 | + { |
| 111 | + toolName: "find", |
| 112 | + parameters: { |
| 113 | + database: "db1", |
| 114 | + collection: "coll1", |
| 115 | + filter: { date_of_publish: "01.01.1992" }, |
| 116 | + projection: { title: 1 }, |
| 117 | + }, |
| 118 | + }, |
| 119 | + ], |
| 120 | + }; |
| 121 | +} |
| 122 | + |
| 123 | +function callsFindWithSortAndLimit(prompt: string): AccuracyTestConfig { |
| 124 | + return { |
| 125 | + injectConnectedAssumption: true, |
| 126 | + prompt: prompt, |
| 127 | + mockedTools: { |
| 128 | + "collection-schema": async () => |
| 129 | + collectionSchemaResponse("db1", "coll1", await getSimplifiedSchema(documents)), |
| 130 | + find: () => findResponse("coll1", [documents[0], documents[1]]), |
| 131 | + }, |
| 132 | + expectedToolCalls: [ |
| 133 | + { |
| 134 | + toolName: "find", |
| 135 | + parameters: { |
| 136 | + database: "db1", |
| 137 | + collection: "coll1", |
| 138 | + sort: { date_of_publish: 1 }, |
| 139 | + limit: 2, |
| 140 | + }, |
| 141 | + }, |
| 142 | + ], |
| 143 | + }; |
| 144 | +} |
| 145 | + |
| 146 | +describeAccuracyTests("find", getAvailableModels(), [ |
| 147 | + callsFindNoFilter("List all the documents in 'db1.coll1' namespace"), |
| 148 | + callsFindNoFilter("Find all the documents from collection coll1 in database db1"), |
| 149 | + callsFindWithFilter("Find all the books published by author name 'author1' in db1.coll1 namespace"), |
| 150 | + callsFindWithFilter("Find all the documents in coll1 collection and db1 database where author is 'author1'"), |
| 151 | + callsFindWithProjection("Give me all the title of the books available in 'db1.coll1' namespace"), |
| 152 | + callsFindWithProjection("Give me all the title of the books published in available in 'db1.coll1' namespace"), |
| 153 | + callsFindWithProjectionAndFilters( |
| 154 | + "Find all the book titles from 'db1.coll1' namespace where date_of_publish is '01.01.1992'" |
| 155 | + ), |
| 156 | + callsFindWithSortAndLimit("List first two books sorted by the field date_of_publish in namespace db1.coll1"), |
| 157 | +]); |
0 commit comments