@langchain/openai 1.1.3 → 1.2.0-dev-1765431816670
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +583 -2
- package/dist/azure/chat_models/common.d.cts.map +1 -0
- package/dist/azure/chat_models/common.d.ts.map +1 -0
- package/dist/azure/chat_models/completions.d.cts.map +1 -0
- package/dist/azure/chat_models/completions.d.ts.map +1 -0
- package/dist/azure/chat_models/index.d.cts +1 -1
- package/dist/azure/chat_models/index.d.cts.map +1 -0
- package/dist/azure/chat_models/index.d.ts.map +1 -0
- package/dist/azure/chat_models/responses.d.cts.map +1 -0
- package/dist/azure/chat_models/responses.d.ts.map +1 -0
- package/dist/azure/embeddings.d.cts.map +1 -0
- package/dist/azure/embeddings.d.ts.map +1 -0
- package/dist/azure/llms.d.cts +0 -1
- package/dist/azure/llms.d.cts.map +1 -0
- package/dist/azure/llms.d.ts +0 -1
- package/dist/azure/llms.d.ts.map +1 -0
- package/dist/chat_models/base.cjs +5 -1
- package/dist/chat_models/base.cjs.map +1 -1
- package/dist/chat_models/base.d.cts +8 -22
- package/dist/chat_models/base.d.cts.map +1 -0
- package/dist/chat_models/base.d.ts +6 -20
- package/dist/chat_models/base.d.ts.map +1 -0
- package/dist/chat_models/base.js +6 -2
- package/dist/chat_models/base.js.map +1 -1
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.d.cts +1 -3
- package/dist/chat_models/completions.d.cts.map +1 -0
- package/dist/chat_models/completions.d.ts +1 -3
- package/dist/chat_models/completions.d.ts.map +1 -0
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/index.d.cts +42 -4
- package/dist/chat_models/index.d.cts.map +1 -0
- package/dist/chat_models/index.d.ts +42 -4
- package/dist/chat_models/index.d.ts.map +1 -0
- package/dist/chat_models/responses.d.cts +2 -2
- package/dist/chat_models/responses.d.cts.map +1 -0
- package/dist/chat_models/responses.d.ts +2 -2
- package/dist/chat_models/responses.d.ts.map +1 -0
- package/dist/converters/completions.cjs +22 -12
- package/dist/converters/completions.cjs.map +1 -1
- package/dist/converters/completions.d.cts +0 -1
- package/dist/converters/completions.d.cts.map +1 -0
- package/dist/converters/completions.d.ts +0 -1
- package/dist/converters/completions.d.ts.map +1 -0
- package/dist/converters/completions.js +23 -13
- package/dist/converters/completions.js.map +1 -1
- package/dist/converters/responses.cjs +37 -4
- package/dist/converters/responses.cjs.map +1 -1
- package/dist/converters/responses.d.cts.map +1 -0
- package/dist/converters/responses.d.ts.map +1 -0
- package/dist/converters/responses.js +39 -6
- package/dist/converters/responses.js.map +1 -1
- package/dist/embeddings.d.cts +0 -1
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +0 -1
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -3
- package/dist/index.js +2 -2
- package/dist/llms.d.cts +0 -1
- package/dist/llms.d.cts.map +1 -0
- package/dist/llms.d.ts +0 -1
- package/dist/llms.d.ts.map +1 -0
- package/dist/tools/applyPatch.cjs +116 -0
- package/dist/tools/applyPatch.cjs.map +1 -0
- package/dist/tools/applyPatch.d.cts +148 -0
- package/dist/tools/applyPatch.d.cts.map +1 -0
- package/dist/tools/applyPatch.d.ts +148 -0
- package/dist/tools/applyPatch.d.ts.map +1 -0
- package/dist/tools/applyPatch.js +115 -0
- package/dist/tools/applyPatch.js.map +1 -0
- package/dist/tools/codeInterpreter.cjs +95 -0
- package/dist/tools/codeInterpreter.cjs.map +1 -0
- package/dist/tools/codeInterpreter.d.cts +125 -0
- package/dist/tools/codeInterpreter.d.cts.map +1 -0
- package/dist/tools/codeInterpreter.d.ts +125 -0
- package/dist/tools/codeInterpreter.d.ts.map +1 -0
- package/dist/tools/codeInterpreter.js +94 -0
- package/dist/tools/codeInterpreter.js.map +1 -0
- package/dist/tools/computerUse.cjs +240 -0
- package/dist/tools/computerUse.cjs.map +1 -0
- package/dist/tools/computerUse.d.cts +234 -0
- package/dist/tools/computerUse.d.cts.map +1 -0
- package/dist/tools/computerUse.d.ts +234 -0
- package/dist/tools/computerUse.d.ts.map +1 -0
- package/dist/tools/computerUse.js +239 -0
- package/dist/tools/computerUse.js.map +1 -0
- package/dist/tools/custom.d.cts +1 -1
- package/dist/tools/custom.d.cts.map +1 -0
- package/dist/tools/custom.d.ts.map +1 -0
- package/dist/tools/dalle.d.cts +1 -2
- package/dist/tools/dalle.d.cts.map +1 -0
- package/dist/tools/dalle.d.ts +1 -2
- package/dist/tools/dalle.d.ts.map +1 -0
- package/dist/tools/fileSearch.cjs +137 -0
- package/dist/tools/fileSearch.cjs.map +1 -0
- package/dist/tools/fileSearch.d.cts +224 -0
- package/dist/tools/fileSearch.d.cts.map +1 -0
- package/dist/tools/fileSearch.d.ts +224 -0
- package/dist/tools/fileSearch.d.ts.map +1 -0
- package/dist/tools/fileSearch.js +136 -0
- package/dist/tools/fileSearch.js.map +1 -0
- package/dist/tools/imageGeneration.cjs +128 -0
- package/dist/tools/imageGeneration.cjs.map +1 -0
- package/dist/tools/imageGeneration.d.cts +199 -0
- package/dist/tools/imageGeneration.d.cts.map +1 -0
- package/dist/tools/imageGeneration.d.ts +199 -0
- package/dist/tools/imageGeneration.d.ts.map +1 -0
- package/dist/tools/imageGeneration.js +127 -0
- package/dist/tools/imageGeneration.js.map +1 -0
- package/dist/tools/index.cjs +26 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.d.cts +27 -0
- package/dist/tools/index.d.cts.map +1 -0
- package/dist/tools/index.d.ts +27 -1
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +26 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/localShell.cjs +145 -0
- package/dist/tools/localShell.cjs.map +1 -0
- package/dist/tools/localShell.d.cts +167 -0
- package/dist/tools/localShell.d.cts.map +1 -0
- package/dist/tools/localShell.d.ts +167 -0
- package/dist/tools/localShell.d.ts.map +1 -0
- package/dist/tools/localShell.js +144 -0
- package/dist/tools/localShell.js.map +1 -0
- package/dist/tools/mcp.cjs +53 -0
- package/dist/tools/mcp.cjs.map +1 -0
- package/dist/tools/mcp.d.cts +177 -0
- package/dist/tools/mcp.d.cts.map +1 -0
- package/dist/tools/mcp.d.ts +177 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mcp.js +52 -0
- package/dist/tools/mcp.js.map +1 -0
- package/dist/tools/shell.cjs +163 -0
- package/dist/tools/shell.cjs.map +1 -0
- package/dist/tools/shell.d.cts +221 -0
- package/dist/tools/shell.d.cts.map +1 -0
- package/dist/tools/shell.d.ts +221 -0
- package/dist/tools/shell.d.ts.map +1 -0
- package/dist/tools/shell.js +162 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/tools/webSearch.cjs +73 -0
- package/dist/tools/webSearch.cjs.map +1 -0
- package/dist/tools/webSearch.d.cts +130 -0
- package/dist/tools/webSearch.d.cts.map +1 -0
- package/dist/tools/webSearch.d.ts +130 -0
- package/dist/tools/webSearch.d.ts.map +1 -0
- package/dist/tools/webSearch.js +72 -0
- package/dist/tools/webSearch.js.map +1 -0
- package/dist/types.d.cts +2 -4
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +1 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/azure.d.cts +1 -5
- package/dist/utils/azure.d.cts.map +1 -0
- package/dist/utils/azure.d.ts +1 -5
- package/dist/utils/azure.d.ts.map +1 -0
- package/dist/utils/client.d.cts.map +1 -0
- package/dist/utils/client.d.ts.map +1 -0
- package/dist/utils/misc.cjs +6 -0
- package/dist/utils/misc.cjs.map +1 -1
- package/dist/utils/misc.d.cts +1 -1
- package/dist/utils/misc.d.cts.map +1 -0
- package/dist/utils/misc.d.ts +1 -1
- package/dist/utils/misc.d.ts.map +1 -0
- package/dist/utils/misc.js +6 -1
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/prompts.d.cts +0 -1
- package/dist/utils/prompts.d.cts.map +1 -0
- package/dist/utils/prompts.d.ts +0 -1
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/tools.cjs +39 -1
- package/dist/utils/tools.cjs.map +1 -1
- package/dist/utils/tools.d.cts.map +1 -0
- package/dist/utils/tools.d.ts.map +1 -0
- package/dist/utils/tools.js +37 -2
- package/dist/utils/tools.js.map +1 -1
- package/package.json +8 -6
- package/dist/langchain-core/dist/callbacks/base.d.ts +0 -1
- package/dist/langchain-core/dist/callbacks/manager.d.ts +0 -2
- package/dist/langchain-core/dist/documents/transformers.d.ts +0 -2
- package/dist/langchain-core/dist/language_models/base.d.ts +0 -7
- package/dist/langchain-core/dist/language_models/chat_models.d.cts +0 -13
- package/dist/langchain-core/dist/language_models/chat_models.d.ts +0 -23
- package/dist/langchain-core/dist/messages/index.d.ts +0 -1
- package/dist/langchain-core/dist/messages/transformers.d.ts +0 -3
- package/dist/langchain-core/dist/runnables/base.d.ts +0 -7
- package/dist/langchain-core/dist/runnables/config.d.ts +0 -2
- package/dist/langchain-core/dist/runnables/graph.d.ts +0 -1
- package/dist/langchain-core/dist/runnables/types.d.ts +0 -2
- package/dist/langchain-core/dist/tools/index.d.ts +0 -8
- package/dist/langchain-core/dist/tools/types.d.ts +0 -7
- package/dist/langchain-core/dist/tracers/base.d.ts +0 -2
- package/dist/langchain-core/dist/tracers/event_stream.d.ts +0 -2
- package/dist/langchain-core/dist/tracers/log_stream.d.ts +0 -3
- package/dist/langchain-core/dist/types/_internal.d.cts +0 -11
- package/dist/langchain-core/dist/types/_internal.d.ts +0 -11
- package/dist/langchain-core/dist/utils/json_schema.d.ts +0 -1
- package/dist/langchain-core/dist/utils/stream.d.cts +0 -26
- package/dist/langchain-core/dist/utils/stream.d.ts +0 -26
- package/dist/langchain-core/dist/utils/types/index.d.ts +0 -1
- package/dist/langchain-core/dist/utils/types/zod.d.ts +0 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/tools/fileSearch.ts
|
|
3
|
+
/**
|
|
4
|
+
* Converts ranking options to the API format.
|
|
5
|
+
*/
|
|
6
|
+
function convertRankingOptions(options) {
|
|
7
|
+
if (!options) return void 0;
|
|
8
|
+
return {
|
|
9
|
+
ranker: options.ranker,
|
|
10
|
+
score_threshold: options.scoreThreshold,
|
|
11
|
+
hybrid_search: options.hybridSearch ? {
|
|
12
|
+
embedding_weight: options.hybridSearch.embeddingWeight,
|
|
13
|
+
text_weight: options.hybridSearch.textWeight
|
|
14
|
+
} : void 0
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a File Search tool that allows models to search your files
|
|
19
|
+
* for relevant information using semantic and keyword search.
|
|
20
|
+
*
|
|
21
|
+
* File Search enables models to retrieve information from a knowledge base
|
|
22
|
+
* of previously uploaded files stored in vector stores. This is a hosted tool
|
|
23
|
+
* managed by OpenAI - you don't need to implement the search execution yourself.
|
|
24
|
+
*
|
|
25
|
+
* **Prerequisites**: Before using File Search, you must:
|
|
26
|
+
* 1. Upload files to the File API with `purpose: "assistants"`
|
|
27
|
+
* 2. Create a vector store
|
|
28
|
+
* 3. Add files to the vector store
|
|
29
|
+
*
|
|
30
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-file-search | OpenAI File Search Documentation}
|
|
31
|
+
*
|
|
32
|
+
* @param options - Configuration options for the File Search tool
|
|
33
|
+
* @returns A File Search tool definition to be passed to the OpenAI Responses API
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
38
|
+
*
|
|
39
|
+
* const model = new ChatOpenAI({ model: "gpt-4.1" });
|
|
40
|
+
*
|
|
41
|
+
* // Basic usage with a vector store
|
|
42
|
+
* const response = await model.invoke(
|
|
43
|
+
* "What is deep research by OpenAI?",
|
|
44
|
+
* {
|
|
45
|
+
* tools: [tools.fileSearch({
|
|
46
|
+
* vectorStoreIds: ["vs_abc123"]
|
|
47
|
+
* })]
|
|
48
|
+
* }
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* // Limit the number of results for lower latency
|
|
52
|
+
* const response = await model.invoke(
|
|
53
|
+
* "Find information about pricing",
|
|
54
|
+
* {
|
|
55
|
+
* tools: [tools.fileSearch({
|
|
56
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
57
|
+
* maxNumResults: 5
|
|
58
|
+
* })]
|
|
59
|
+
* }
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // With metadata filtering
|
|
63
|
+
* const response = await model.invoke(
|
|
64
|
+
* "Find recent blog posts about AI",
|
|
65
|
+
* {
|
|
66
|
+
* tools: [tools.fileSearch({
|
|
67
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
68
|
+
* filters: {
|
|
69
|
+
* type: "eq",
|
|
70
|
+
* key: "category",
|
|
71
|
+
* value: "blog"
|
|
72
|
+
* }
|
|
73
|
+
* })]
|
|
74
|
+
* }
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* // With compound filters (AND/OR)
|
|
78
|
+
* const response = await model.invoke(
|
|
79
|
+
* "Find technical docs from 2024",
|
|
80
|
+
* {
|
|
81
|
+
* tools: [tools.fileSearch({
|
|
82
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
83
|
+
* filters: {
|
|
84
|
+
* type: "and",
|
|
85
|
+
* filters: [
|
|
86
|
+
* { type: "eq", key: "category", value: "technical" },
|
|
87
|
+
* { type: "gte", key: "year", value: 2024 }
|
|
88
|
+
* ]
|
|
89
|
+
* }
|
|
90
|
+
* })]
|
|
91
|
+
* }
|
|
92
|
+
* );
|
|
93
|
+
*
|
|
94
|
+
* // With ranking options for more relevant results
|
|
95
|
+
* const response = await model.invoke(
|
|
96
|
+
* "Find the most relevant information",
|
|
97
|
+
* {
|
|
98
|
+
* tools: [tools.fileSearch({
|
|
99
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
100
|
+
* rankingOptions: {
|
|
101
|
+
* scoreThreshold: 0.8,
|
|
102
|
+
* ranker: "auto"
|
|
103
|
+
* }
|
|
104
|
+
* })]
|
|
105
|
+
* }
|
|
106
|
+
* );
|
|
107
|
+
*
|
|
108
|
+
* // Search multiple vector stores
|
|
109
|
+
* const response = await model.invoke(
|
|
110
|
+
* "Search across all knowledge bases",
|
|
111
|
+
* {
|
|
112
|
+
* tools: [tools.fileSearch({
|
|
113
|
+
* vectorStoreIds: ["vs_abc123", "vs_def456"]
|
|
114
|
+
* })]
|
|
115
|
+
* }
|
|
116
|
+
* );
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* - Vector stores must be created and populated before using this tool
|
|
121
|
+
* - The tool returns file citations in the response annotations
|
|
122
|
+
* - Use `include: ["file_search_call.results"]` in the API call to get search results
|
|
123
|
+
* - Supported file types include PDF, DOCX, TXT, MD, and many code file formats
|
|
124
|
+
*/
|
|
125
|
+
function fileSearch(options) {
|
|
126
|
+
return {
|
|
127
|
+
type: "file_search",
|
|
128
|
+
vector_store_ids: options.vectorStoreIds,
|
|
129
|
+
max_num_results: options.maxNumResults,
|
|
130
|
+
filters: options.filters,
|
|
131
|
+
ranking_options: convertRankingOptions(options.rankingOptions)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
exports.fileSearch = fileSearch;
|
|
137
|
+
//# sourceMappingURL=fileSearch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSearch.cjs","names":["options: FileSearchRankingOptions | undefined","options: FileSearchOptions"],"sources":["../../src/tools/fileSearch.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Comparison operators for file attribute filtering.\n */\nexport type FileSearchComparisonType =\n | \"eq\"\n | \"ne\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\";\n\n/**\n * A filter used to compare a specified attribute key to a given value.\n */\nexport interface FileSearchComparisonFilter {\n /**\n * The comparison operator to use.\n * - `eq`: equals\n * - `ne`: not equal\n * - `gt`: greater than\n * - `gte`: greater than or equal\n * - `lt`: less than\n * - `lte`: less than or equal\n */\n type: FileSearchComparisonType;\n /**\n * The attribute key to compare against.\n */\n key: string;\n /**\n * The value to compare against the attribute key.\n * Supports string, number, boolean, or array of strings/numbers.\n */\n value: string | number | boolean | Array<string | number>;\n}\n\n/**\n * Combine multiple filters using `and` or `or`.\n */\nexport interface FileSearchCompoundFilter {\n /**\n * Type of operation: `and` or `or`.\n */\n type: \"and\" | \"or\";\n /**\n * Array of filters to combine.\n */\n filters: Array<FileSearchComparisonFilter | FileSearchCompoundFilter>;\n}\n\n/**\n * Filter type for file search - can be a comparison or compound filter.\n */\nexport type FileSearchFilter =\n | FileSearchComparisonFilter\n | FileSearchCompoundFilter;\n\n/**\n * Weights for hybrid search balancing semantic and keyword matches.\n */\nexport interface FileSearchHybridSearchWeights {\n /**\n * The weight of semantic embedding matches (0-1).\n */\n embeddingWeight: number;\n /**\n * The weight of keyword/text matches (0-1).\n */\n textWeight: number;\n}\n\n/**\n * Ranking options for file search results.\n */\nexport interface FileSearchRankingOptions {\n /**\n * The ranker to use for the file search.\n * - `auto`: Automatically select the best ranker\n * - `default-2024-11-15`: Default ranker as of November 2024\n */\n ranker?: \"auto\" | \"default-2024-11-15\";\n /**\n * The score threshold for results (0-1).\n * Numbers closer to 1 return only the most relevant results but may return fewer.\n */\n scoreThreshold?: number;\n /**\n * Weights that control how reciprocal rank fusion balances semantic\n * embedding matches versus sparse keyword matches when hybrid search is enabled.\n */\n hybridSearch?: FileSearchHybridSearchWeights;\n}\n\n/**\n * Options for the File Search tool.\n */\nexport interface FileSearchOptions {\n /**\n * The IDs of the vector stores to search.\n * You must have previously created vector stores and uploaded files to them.\n */\n vectorStoreIds: string[];\n /**\n * The maximum number of results to return.\n * Must be between 1 and 50 inclusive.\n */\n maxNumResults?: number;\n /**\n * A filter to apply based on file attributes/metadata.\n * Use this to narrow down search results to specific categories or file types.\n */\n filters?: FileSearchFilter;\n /**\n * Ranking options to customize how results are scored and ordered.\n */\n rankingOptions?: FileSearchRankingOptions;\n}\n\n/**\n * OpenAI File Search tool type for the Responses API.\n */\nexport type FileSearchTool = OpenAIClient.Responses.FileSearchTool;\n\n/**\n * Converts ranking options to the API format.\n */\nfunction convertRankingOptions(\n options: FileSearchRankingOptions | undefined\n): OpenAIClient.Responses.FileSearchTool.RankingOptions | undefined {\n if (!options) return undefined;\n return {\n ranker: options.ranker,\n score_threshold: options.scoreThreshold,\n hybrid_search: options.hybridSearch\n ? {\n embedding_weight: options.hybridSearch.embeddingWeight,\n text_weight: options.hybridSearch.textWeight,\n }\n : undefined,\n };\n}\n\n/**\n * Creates a File Search tool that allows models to search your files\n * for relevant information using semantic and keyword search.\n *\n * File Search enables models to retrieve information from a knowledge base\n * of previously uploaded files stored in vector stores. This is a hosted tool\n * managed by OpenAI - you don't need to implement the search execution yourself.\n *\n * **Prerequisites**: Before using File Search, you must:\n * 1. Upload files to the File API with `purpose: \"assistants\"`\n * 2. Create a vector store\n * 3. Add files to the vector store\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-file-search | OpenAI File Search Documentation}\n *\n * @param options - Configuration options for the File Search tool\n * @returns A File Search tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with a vector store\n * const response = await model.invoke(\n * \"What is deep research by OpenAI?\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"]\n * })]\n * }\n * );\n *\n * // Limit the number of results for lower latency\n * const response = await model.invoke(\n * \"Find information about pricing\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * maxNumResults: 5\n * })]\n * }\n * );\n *\n * // With metadata filtering\n * const response = await model.invoke(\n * \"Find recent blog posts about AI\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"eq\",\n * key: \"category\",\n * value: \"blog\"\n * }\n * })]\n * }\n * );\n *\n * // With compound filters (AND/OR)\n * const response = await model.invoke(\n * \"Find technical docs from 2024\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"and\",\n * filters: [\n * { type: \"eq\", key: \"category\", value: \"technical\" },\n * { type: \"gte\", key: \"year\", value: 2024 }\n * ]\n * }\n * })]\n * }\n * );\n *\n * // With ranking options for more relevant results\n * const response = await model.invoke(\n * \"Find the most relevant information\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * rankingOptions: {\n * scoreThreshold: 0.8,\n * ranker: \"auto\"\n * }\n * })]\n * }\n * );\n *\n * // Search multiple vector stores\n * const response = await model.invoke(\n * \"Search across all knowledge bases\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\", \"vs_def456\"]\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Vector stores must be created and populated before using this tool\n * - The tool returns file citations in the response annotations\n * - Use `include: [\"file_search_call.results\"]` in the API call to get search results\n * - Supported file types include PDF, DOCX, TXT, MD, and many code file formats\n */\nexport function fileSearch(options: FileSearchOptions): ServerTool {\n return {\n type: \"file_search\",\n vector_store_ids: options.vectorStoreIds,\n max_num_results: options.maxNumResults,\n filters: options.filters as FileSearchTool[\"filters\"],\n ranking_options: convertRankingOptions(options.rankingOptions),\n } satisfies FileSearchTool;\n}\n"],"mappings":";;;;;AAiIA,SAAS,sBACPA,SACkE;AAClE,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO;EACL,QAAQ,QAAQ;EAChB,iBAAiB,QAAQ;EACzB,eAAe,QAAQ,eACnB;GACE,kBAAkB,QAAQ,aAAa;GACvC,aAAa,QAAQ,aAAa;EACnC,IACD;CACL;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8GD,SAAgB,WAAWC,SAAwC;AACjE,QAAO;EACL,MAAM;EACN,kBAAkB,QAAQ;EAC1B,iBAAiB,QAAQ;EACzB,SAAS,QAAQ;EACjB,iBAAiB,sBAAsB,QAAQ,eAAe;CAC/D;AACF"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { OpenAI as OpenAI$1 } from "openai";
|
|
2
|
+
import { ServerTool } from "@langchain/core/tools";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/fileSearch.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Comparison operators for file attribute filtering.
|
|
8
|
+
*/
|
|
9
|
+
type FileSearchComparisonType = "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
|
|
10
|
+
/**
|
|
11
|
+
* A filter used to compare a specified attribute key to a given value.
|
|
12
|
+
*/
|
|
13
|
+
interface FileSearchComparisonFilter {
|
|
14
|
+
/**
|
|
15
|
+
* The comparison operator to use.
|
|
16
|
+
* - `eq`: equals
|
|
17
|
+
* - `ne`: not equal
|
|
18
|
+
* - `gt`: greater than
|
|
19
|
+
* - `gte`: greater than or equal
|
|
20
|
+
* - `lt`: less than
|
|
21
|
+
* - `lte`: less than or equal
|
|
22
|
+
*/
|
|
23
|
+
type: FileSearchComparisonType;
|
|
24
|
+
/**
|
|
25
|
+
* The attribute key to compare against.
|
|
26
|
+
*/
|
|
27
|
+
key: string;
|
|
28
|
+
/**
|
|
29
|
+
* The value to compare against the attribute key.
|
|
30
|
+
* Supports string, number, boolean, or array of strings/numbers.
|
|
31
|
+
*/
|
|
32
|
+
value: string | number | boolean | Array<string | number>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Combine multiple filters using `and` or `or`.
|
|
36
|
+
*/
|
|
37
|
+
interface FileSearchCompoundFilter {
|
|
38
|
+
/**
|
|
39
|
+
* Type of operation: `and` or `or`.
|
|
40
|
+
*/
|
|
41
|
+
type: "and" | "or";
|
|
42
|
+
/**
|
|
43
|
+
* Array of filters to combine.
|
|
44
|
+
*/
|
|
45
|
+
filters: Array<FileSearchComparisonFilter | FileSearchCompoundFilter>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Filter type for file search - can be a comparison or compound filter.
|
|
49
|
+
*/
|
|
50
|
+
type FileSearchFilter = FileSearchComparisonFilter | FileSearchCompoundFilter;
|
|
51
|
+
/**
|
|
52
|
+
* Weights for hybrid search balancing semantic and keyword matches.
|
|
53
|
+
*/
|
|
54
|
+
interface FileSearchHybridSearchWeights {
|
|
55
|
+
/**
|
|
56
|
+
* The weight of semantic embedding matches (0-1).
|
|
57
|
+
*/
|
|
58
|
+
embeddingWeight: number;
|
|
59
|
+
/**
|
|
60
|
+
* The weight of keyword/text matches (0-1).
|
|
61
|
+
*/
|
|
62
|
+
textWeight: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Ranking options for file search results.
|
|
66
|
+
*/
|
|
67
|
+
interface FileSearchRankingOptions {
|
|
68
|
+
/**
|
|
69
|
+
* The ranker to use for the file search.
|
|
70
|
+
* - `auto`: Automatically select the best ranker
|
|
71
|
+
* - `default-2024-11-15`: Default ranker as of November 2024
|
|
72
|
+
*/
|
|
73
|
+
ranker?: "auto" | "default-2024-11-15";
|
|
74
|
+
/**
|
|
75
|
+
* The score threshold for results (0-1).
|
|
76
|
+
* Numbers closer to 1 return only the most relevant results but may return fewer.
|
|
77
|
+
*/
|
|
78
|
+
scoreThreshold?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Weights that control how reciprocal rank fusion balances semantic
|
|
81
|
+
* embedding matches versus sparse keyword matches when hybrid search is enabled.
|
|
82
|
+
*/
|
|
83
|
+
hybridSearch?: FileSearchHybridSearchWeights;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Options for the File Search tool.
|
|
87
|
+
*/
|
|
88
|
+
interface FileSearchOptions {
|
|
89
|
+
/**
|
|
90
|
+
* The IDs of the vector stores to search.
|
|
91
|
+
* You must have previously created vector stores and uploaded files to them.
|
|
92
|
+
*/
|
|
93
|
+
vectorStoreIds: string[];
|
|
94
|
+
/**
|
|
95
|
+
* The maximum number of results to return.
|
|
96
|
+
* Must be between 1 and 50 inclusive.
|
|
97
|
+
*/
|
|
98
|
+
maxNumResults?: number;
|
|
99
|
+
/**
|
|
100
|
+
* A filter to apply based on file attributes/metadata.
|
|
101
|
+
* Use this to narrow down search results to specific categories or file types.
|
|
102
|
+
*/
|
|
103
|
+
filters?: FileSearchFilter;
|
|
104
|
+
/**
|
|
105
|
+
* Ranking options to customize how results are scored and ordered.
|
|
106
|
+
*/
|
|
107
|
+
rankingOptions?: FileSearchRankingOptions;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* OpenAI File Search tool type for the Responses API.
|
|
111
|
+
*/
|
|
112
|
+
type FileSearchTool = OpenAI$1.Responses.FileSearchTool;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a File Search tool that allows models to search your files
|
|
115
|
+
* for relevant information using semantic and keyword search.
|
|
116
|
+
*
|
|
117
|
+
* File Search enables models to retrieve information from a knowledge base
|
|
118
|
+
* of previously uploaded files stored in vector stores. This is a hosted tool
|
|
119
|
+
* managed by OpenAI - you don't need to implement the search execution yourself.
|
|
120
|
+
*
|
|
121
|
+
* **Prerequisites**: Before using File Search, you must:
|
|
122
|
+
* 1. Upload files to the File API with `purpose: "assistants"`
|
|
123
|
+
* 2. Create a vector store
|
|
124
|
+
* 3. Add files to the vector store
|
|
125
|
+
*
|
|
126
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-file-search | OpenAI File Search Documentation}
|
|
127
|
+
*
|
|
128
|
+
* @param options - Configuration options for the File Search tool
|
|
129
|
+
* @returns A File Search tool definition to be passed to the OpenAI Responses API
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
134
|
+
*
|
|
135
|
+
* const model = new ChatOpenAI({ model: "gpt-4.1" });
|
|
136
|
+
*
|
|
137
|
+
* // Basic usage with a vector store
|
|
138
|
+
* const response = await model.invoke(
|
|
139
|
+
* "What is deep research by OpenAI?",
|
|
140
|
+
* {
|
|
141
|
+
* tools: [tools.fileSearch({
|
|
142
|
+
* vectorStoreIds: ["vs_abc123"]
|
|
143
|
+
* })]
|
|
144
|
+
* }
|
|
145
|
+
* );
|
|
146
|
+
*
|
|
147
|
+
* // Limit the number of results for lower latency
|
|
148
|
+
* const response = await model.invoke(
|
|
149
|
+
* "Find information about pricing",
|
|
150
|
+
* {
|
|
151
|
+
* tools: [tools.fileSearch({
|
|
152
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
153
|
+
* maxNumResults: 5
|
|
154
|
+
* })]
|
|
155
|
+
* }
|
|
156
|
+
* );
|
|
157
|
+
*
|
|
158
|
+
* // With metadata filtering
|
|
159
|
+
* const response = await model.invoke(
|
|
160
|
+
* "Find recent blog posts about AI",
|
|
161
|
+
* {
|
|
162
|
+
* tools: [tools.fileSearch({
|
|
163
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
164
|
+
* filters: {
|
|
165
|
+
* type: "eq",
|
|
166
|
+
* key: "category",
|
|
167
|
+
* value: "blog"
|
|
168
|
+
* }
|
|
169
|
+
* })]
|
|
170
|
+
* }
|
|
171
|
+
* );
|
|
172
|
+
*
|
|
173
|
+
* // With compound filters (AND/OR)
|
|
174
|
+
* const response = await model.invoke(
|
|
175
|
+
* "Find technical docs from 2024",
|
|
176
|
+
* {
|
|
177
|
+
* tools: [tools.fileSearch({
|
|
178
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
179
|
+
* filters: {
|
|
180
|
+
* type: "and",
|
|
181
|
+
* filters: [
|
|
182
|
+
* { type: "eq", key: "category", value: "technical" },
|
|
183
|
+
* { type: "gte", key: "year", value: 2024 }
|
|
184
|
+
* ]
|
|
185
|
+
* }
|
|
186
|
+
* })]
|
|
187
|
+
* }
|
|
188
|
+
* );
|
|
189
|
+
*
|
|
190
|
+
* // With ranking options for more relevant results
|
|
191
|
+
* const response = await model.invoke(
|
|
192
|
+
* "Find the most relevant information",
|
|
193
|
+
* {
|
|
194
|
+
* tools: [tools.fileSearch({
|
|
195
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
196
|
+
* rankingOptions: {
|
|
197
|
+
* scoreThreshold: 0.8,
|
|
198
|
+
* ranker: "auto"
|
|
199
|
+
* }
|
|
200
|
+
* })]
|
|
201
|
+
* }
|
|
202
|
+
* );
|
|
203
|
+
*
|
|
204
|
+
* // Search multiple vector stores
|
|
205
|
+
* const response = await model.invoke(
|
|
206
|
+
* "Search across all knowledge bases",
|
|
207
|
+
* {
|
|
208
|
+
* tools: [tools.fileSearch({
|
|
209
|
+
* vectorStoreIds: ["vs_abc123", "vs_def456"]
|
|
210
|
+
* })]
|
|
211
|
+
* }
|
|
212
|
+
* );
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* @remarks
|
|
216
|
+
* - Vector stores must be created and populated before using this tool
|
|
217
|
+
* - The tool returns file citations in the response annotations
|
|
218
|
+
* - Use `include: ["file_search_call.results"]` in the API call to get search results
|
|
219
|
+
* - Supported file types include PDF, DOCX, TXT, MD, and many code file formats
|
|
220
|
+
*/
|
|
221
|
+
declare function fileSearch(options: FileSearchOptions): ServerTool;
|
|
222
|
+
//#endregion
|
|
223
|
+
export { FileSearchComparisonFilter, FileSearchComparisonType, FileSearchCompoundFilter, FileSearchFilter, FileSearchHybridSearchWeights, FileSearchOptions, FileSearchRankingOptions, FileSearchTool, fileSearch };
|
|
224
|
+
//# sourceMappingURL=fileSearch.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSearch.d.cts","names":["OpenAI","OpenAIClient","ServerTool","FileSearchComparisonType","FileSearchComparisonFilter","Array","FileSearchCompoundFilter","FileSearchFilter","FileSearchHybridSearchWeights","FileSearchRankingOptions","FileSearchOptions","FileSearchTool","Responses","fileSearch"],"sources":["../../src/tools/fileSearch.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * Comparison operators for file attribute filtering.\n */\nexport type FileSearchComparisonType = \"eq\" | \"ne\" | \"gt\" | \"gte\" | \"lt\" | \"lte\";\n/**\n * A filter used to compare a specified attribute key to a given value.\n */\nexport interface FileSearchComparisonFilter {\n /**\n * The comparison operator to use.\n * - `eq`: equals\n * - `ne`: not equal\n * - `gt`: greater than\n * - `gte`: greater than or equal\n * - `lt`: less than\n * - `lte`: less than or equal\n */\n type: FileSearchComparisonType;\n /**\n * The attribute key to compare against.\n */\n key: string;\n /**\n * The value to compare against the attribute key.\n * Supports string, number, boolean, or array of strings/numbers.\n */\n value: string | number | boolean | Array<string | number>;\n}\n/**\n * Combine multiple filters using `and` or `or`.\n */\nexport interface FileSearchCompoundFilter {\n /**\n * Type of operation: `and` or `or`.\n */\n type: \"and\" | \"or\";\n /**\n * Array of filters to combine.\n */\n filters: Array<FileSearchComparisonFilter | FileSearchCompoundFilter>;\n}\n/**\n * Filter type for file search - can be a comparison or compound filter.\n */\nexport type FileSearchFilter = FileSearchComparisonFilter | FileSearchCompoundFilter;\n/**\n * Weights for hybrid search balancing semantic and keyword matches.\n */\nexport interface FileSearchHybridSearchWeights {\n /**\n * The weight of semantic embedding matches (0-1).\n */\n embeddingWeight: number;\n /**\n * The weight of keyword/text matches (0-1).\n */\n textWeight: number;\n}\n/**\n * Ranking options for file search results.\n */\nexport interface FileSearchRankingOptions {\n /**\n * The ranker to use for the file search.\n * - `auto`: Automatically select the best ranker\n * - `default-2024-11-15`: Default ranker as of November 2024\n */\n ranker?: \"auto\" | \"default-2024-11-15\";\n /**\n * The score threshold for results (0-1).\n * Numbers closer to 1 return only the most relevant results but may return fewer.\n */\n scoreThreshold?: number;\n /**\n * Weights that control how reciprocal rank fusion balances semantic\n * embedding matches versus sparse keyword matches when hybrid search is enabled.\n */\n hybridSearch?: FileSearchHybridSearchWeights;\n}\n/**\n * Options for the File Search tool.\n */\nexport interface FileSearchOptions {\n /**\n * The IDs of the vector stores to search.\n * You must have previously created vector stores and uploaded files to them.\n */\n vectorStoreIds: string[];\n /**\n * The maximum number of results to return.\n * Must be between 1 and 50 inclusive.\n */\n maxNumResults?: number;\n /**\n * A filter to apply based on file attributes/metadata.\n * Use this to narrow down search results to specific categories or file types.\n */\n filters?: FileSearchFilter;\n /**\n * Ranking options to customize how results are scored and ordered.\n */\n rankingOptions?: FileSearchRankingOptions;\n}\n/**\n * OpenAI File Search tool type for the Responses API.\n */\nexport type FileSearchTool = OpenAIClient.Responses.FileSearchTool;\n/**\n * Creates a File Search tool that allows models to search your files\n * for relevant information using semantic and keyword search.\n *\n * File Search enables models to retrieve information from a knowledge base\n * of previously uploaded files stored in vector stores. This is a hosted tool\n * managed by OpenAI - you don't need to implement the search execution yourself.\n *\n * **Prerequisites**: Before using File Search, you must:\n * 1. Upload files to the File API with `purpose: \"assistants\"`\n * 2. Create a vector store\n * 3. Add files to the vector store\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-file-search | OpenAI File Search Documentation}\n *\n * @param options - Configuration options for the File Search tool\n * @returns A File Search tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with a vector store\n * const response = await model.invoke(\n * \"What is deep research by OpenAI?\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"]\n * })]\n * }\n * );\n *\n * // Limit the number of results for lower latency\n * const response = await model.invoke(\n * \"Find information about pricing\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * maxNumResults: 5\n * })]\n * }\n * );\n *\n * // With metadata filtering\n * const response = await model.invoke(\n * \"Find recent blog posts about AI\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"eq\",\n * key: \"category\",\n * value: \"blog\"\n * }\n * })]\n * }\n * );\n *\n * // With compound filters (AND/OR)\n * const response = await model.invoke(\n * \"Find technical docs from 2024\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"and\",\n * filters: [\n * { type: \"eq\", key: \"category\", value: \"technical\" },\n * { type: \"gte\", key: \"year\", value: 2024 }\n * ]\n * }\n * })]\n * }\n * );\n *\n * // With ranking options for more relevant results\n * const response = await model.invoke(\n * \"Find the most relevant information\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * rankingOptions: {\n * scoreThreshold: 0.8,\n * ranker: \"auto\"\n * }\n * })]\n * }\n * );\n *\n * // Search multiple vector stores\n * const response = await model.invoke(\n * \"Search across all knowledge bases\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\", \"vs_def456\"]\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Vector stores must be created and populated before using this tool\n * - The tool returns file citations in the response annotations\n * - Use `include: [\"file_search_call.results\"]` in the API call to get search results\n * - Supported file types include PDF, DOCX, TXT, MD, and many code file formats\n */\nexport declare function fileSearch(options: FileSearchOptions): ServerTool;\n//# sourceMappingURL=fileSearch.d.ts.map"],"mappings":";;;;;;;AAKA;AAIiBI,KAJLD,wBAAAA,GAI+B,IAAA,GAUjCA,IAAAA,GAAAA,IAAAA,GAAAA,KAAAA,GAAAA,IAS6BE,GAAAA,KAAK;AAK5C;;;AAQaA,UAhCID,0BAAAA,CAgCJC;EAAK;AAKlB;AAIA;AAaA;AAqBA;AAwBA;AA6GA;;;QAtMUF;;;;;;;;;qCAS6BE;;;;;UAKtBC,wBAAAA;;;;;;;;WAQJD,MAAMD,6BAA6BE;;;;;KAKpCC,gBAAAA,GAAmBH,6BAA6BE;;;;UAI3CE,6BAAAA;;;;;;;;;;;;;UAaAC,wBAAAA;;;;;;;;;;;;;;;;iBAgBED;;;;;UAKFE,iBAAAA;;;;;;;;;;;;;;;YAeHH;;;;mBAIOE;;;;;KAKTE,cAAAA,GAAiBV,QAAAA,CAAaW,SAAAA,CAAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6G5BE,UAAAA,UAAoBH,oBAAoBR"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { OpenAI as OpenAI$1 } from "openai";
|
|
2
|
+
import { ServerTool } from "@langchain/core/tools";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/fileSearch.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Comparison operators for file attribute filtering.
|
|
8
|
+
*/
|
|
9
|
+
type FileSearchComparisonType = "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
|
|
10
|
+
/**
|
|
11
|
+
* A filter used to compare a specified attribute key to a given value.
|
|
12
|
+
*/
|
|
13
|
+
interface FileSearchComparisonFilter {
|
|
14
|
+
/**
|
|
15
|
+
* The comparison operator to use.
|
|
16
|
+
* - `eq`: equals
|
|
17
|
+
* - `ne`: not equal
|
|
18
|
+
* - `gt`: greater than
|
|
19
|
+
* - `gte`: greater than or equal
|
|
20
|
+
* - `lt`: less than
|
|
21
|
+
* - `lte`: less than or equal
|
|
22
|
+
*/
|
|
23
|
+
type: FileSearchComparisonType;
|
|
24
|
+
/**
|
|
25
|
+
* The attribute key to compare against.
|
|
26
|
+
*/
|
|
27
|
+
key: string;
|
|
28
|
+
/**
|
|
29
|
+
* The value to compare against the attribute key.
|
|
30
|
+
* Supports string, number, boolean, or array of strings/numbers.
|
|
31
|
+
*/
|
|
32
|
+
value: string | number | boolean | Array<string | number>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Combine multiple filters using `and` or `or`.
|
|
36
|
+
*/
|
|
37
|
+
interface FileSearchCompoundFilter {
|
|
38
|
+
/**
|
|
39
|
+
* Type of operation: `and` or `or`.
|
|
40
|
+
*/
|
|
41
|
+
type: "and" | "or";
|
|
42
|
+
/**
|
|
43
|
+
* Array of filters to combine.
|
|
44
|
+
*/
|
|
45
|
+
filters: Array<FileSearchComparisonFilter | FileSearchCompoundFilter>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Filter type for file search - can be a comparison or compound filter.
|
|
49
|
+
*/
|
|
50
|
+
type FileSearchFilter = FileSearchComparisonFilter | FileSearchCompoundFilter;
|
|
51
|
+
/**
|
|
52
|
+
* Weights for hybrid search balancing semantic and keyword matches.
|
|
53
|
+
*/
|
|
54
|
+
interface FileSearchHybridSearchWeights {
|
|
55
|
+
/**
|
|
56
|
+
* The weight of semantic embedding matches (0-1).
|
|
57
|
+
*/
|
|
58
|
+
embeddingWeight: number;
|
|
59
|
+
/**
|
|
60
|
+
* The weight of keyword/text matches (0-1).
|
|
61
|
+
*/
|
|
62
|
+
textWeight: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Ranking options for file search results.
|
|
66
|
+
*/
|
|
67
|
+
interface FileSearchRankingOptions {
|
|
68
|
+
/**
|
|
69
|
+
* The ranker to use for the file search.
|
|
70
|
+
* - `auto`: Automatically select the best ranker
|
|
71
|
+
* - `default-2024-11-15`: Default ranker as of November 2024
|
|
72
|
+
*/
|
|
73
|
+
ranker?: "auto" | "default-2024-11-15";
|
|
74
|
+
/**
|
|
75
|
+
* The score threshold for results (0-1).
|
|
76
|
+
* Numbers closer to 1 return only the most relevant results but may return fewer.
|
|
77
|
+
*/
|
|
78
|
+
scoreThreshold?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Weights that control how reciprocal rank fusion balances semantic
|
|
81
|
+
* embedding matches versus sparse keyword matches when hybrid search is enabled.
|
|
82
|
+
*/
|
|
83
|
+
hybridSearch?: FileSearchHybridSearchWeights;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Options for the File Search tool.
|
|
87
|
+
*/
|
|
88
|
+
interface FileSearchOptions {
|
|
89
|
+
/**
|
|
90
|
+
* The IDs of the vector stores to search.
|
|
91
|
+
* You must have previously created vector stores and uploaded files to them.
|
|
92
|
+
*/
|
|
93
|
+
vectorStoreIds: string[];
|
|
94
|
+
/**
|
|
95
|
+
* The maximum number of results to return.
|
|
96
|
+
* Must be between 1 and 50 inclusive.
|
|
97
|
+
*/
|
|
98
|
+
maxNumResults?: number;
|
|
99
|
+
/**
|
|
100
|
+
* A filter to apply based on file attributes/metadata.
|
|
101
|
+
* Use this to narrow down search results to specific categories or file types.
|
|
102
|
+
*/
|
|
103
|
+
filters?: FileSearchFilter;
|
|
104
|
+
/**
|
|
105
|
+
* Ranking options to customize how results are scored and ordered.
|
|
106
|
+
*/
|
|
107
|
+
rankingOptions?: FileSearchRankingOptions;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* OpenAI File Search tool type for the Responses API.
|
|
111
|
+
*/
|
|
112
|
+
type FileSearchTool = OpenAI$1.Responses.FileSearchTool;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a File Search tool that allows models to search your files
|
|
115
|
+
* for relevant information using semantic and keyword search.
|
|
116
|
+
*
|
|
117
|
+
* File Search enables models to retrieve information from a knowledge base
|
|
118
|
+
* of previously uploaded files stored in vector stores. This is a hosted tool
|
|
119
|
+
* managed by OpenAI - you don't need to implement the search execution yourself.
|
|
120
|
+
*
|
|
121
|
+
* **Prerequisites**: Before using File Search, you must:
|
|
122
|
+
* 1. Upload files to the File API with `purpose: "assistants"`
|
|
123
|
+
* 2. Create a vector store
|
|
124
|
+
* 3. Add files to the vector store
|
|
125
|
+
*
|
|
126
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-file-search | OpenAI File Search Documentation}
|
|
127
|
+
*
|
|
128
|
+
* @param options - Configuration options for the File Search tool
|
|
129
|
+
* @returns A File Search tool definition to be passed to the OpenAI Responses API
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
134
|
+
*
|
|
135
|
+
* const model = new ChatOpenAI({ model: "gpt-4.1" });
|
|
136
|
+
*
|
|
137
|
+
* // Basic usage with a vector store
|
|
138
|
+
* const response = await model.invoke(
|
|
139
|
+
* "What is deep research by OpenAI?",
|
|
140
|
+
* {
|
|
141
|
+
* tools: [tools.fileSearch({
|
|
142
|
+
* vectorStoreIds: ["vs_abc123"]
|
|
143
|
+
* })]
|
|
144
|
+
* }
|
|
145
|
+
* );
|
|
146
|
+
*
|
|
147
|
+
* // Limit the number of results for lower latency
|
|
148
|
+
* const response = await model.invoke(
|
|
149
|
+
* "Find information about pricing",
|
|
150
|
+
* {
|
|
151
|
+
* tools: [tools.fileSearch({
|
|
152
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
153
|
+
* maxNumResults: 5
|
|
154
|
+
* })]
|
|
155
|
+
* }
|
|
156
|
+
* );
|
|
157
|
+
*
|
|
158
|
+
* // With metadata filtering
|
|
159
|
+
* const response = await model.invoke(
|
|
160
|
+
* "Find recent blog posts about AI",
|
|
161
|
+
* {
|
|
162
|
+
* tools: [tools.fileSearch({
|
|
163
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
164
|
+
* filters: {
|
|
165
|
+
* type: "eq",
|
|
166
|
+
* key: "category",
|
|
167
|
+
* value: "blog"
|
|
168
|
+
* }
|
|
169
|
+
* })]
|
|
170
|
+
* }
|
|
171
|
+
* );
|
|
172
|
+
*
|
|
173
|
+
* // With compound filters (AND/OR)
|
|
174
|
+
* const response = await model.invoke(
|
|
175
|
+
* "Find technical docs from 2024",
|
|
176
|
+
* {
|
|
177
|
+
* tools: [tools.fileSearch({
|
|
178
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
179
|
+
* filters: {
|
|
180
|
+
* type: "and",
|
|
181
|
+
* filters: [
|
|
182
|
+
* { type: "eq", key: "category", value: "technical" },
|
|
183
|
+
* { type: "gte", key: "year", value: 2024 }
|
|
184
|
+
* ]
|
|
185
|
+
* }
|
|
186
|
+
* })]
|
|
187
|
+
* }
|
|
188
|
+
* );
|
|
189
|
+
*
|
|
190
|
+
* // With ranking options for more relevant results
|
|
191
|
+
* const response = await model.invoke(
|
|
192
|
+
* "Find the most relevant information",
|
|
193
|
+
* {
|
|
194
|
+
* tools: [tools.fileSearch({
|
|
195
|
+
* vectorStoreIds: ["vs_abc123"],
|
|
196
|
+
* rankingOptions: {
|
|
197
|
+
* scoreThreshold: 0.8,
|
|
198
|
+
* ranker: "auto"
|
|
199
|
+
* }
|
|
200
|
+
* })]
|
|
201
|
+
* }
|
|
202
|
+
* );
|
|
203
|
+
*
|
|
204
|
+
* // Search multiple vector stores
|
|
205
|
+
* const response = await model.invoke(
|
|
206
|
+
* "Search across all knowledge bases",
|
|
207
|
+
* {
|
|
208
|
+
* tools: [tools.fileSearch({
|
|
209
|
+
* vectorStoreIds: ["vs_abc123", "vs_def456"]
|
|
210
|
+
* })]
|
|
211
|
+
* }
|
|
212
|
+
* );
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* @remarks
|
|
216
|
+
* - Vector stores must be created and populated before using this tool
|
|
217
|
+
* - The tool returns file citations in the response annotations
|
|
218
|
+
* - Use `include: ["file_search_call.results"]` in the API call to get search results
|
|
219
|
+
* - Supported file types include PDF, DOCX, TXT, MD, and many code file formats
|
|
220
|
+
*/
|
|
221
|
+
declare function fileSearch(options: FileSearchOptions): ServerTool;
|
|
222
|
+
//#endregion
|
|
223
|
+
export { FileSearchComparisonFilter, FileSearchComparisonType, FileSearchCompoundFilter, FileSearchFilter, FileSearchHybridSearchWeights, FileSearchOptions, FileSearchRankingOptions, FileSearchTool, fileSearch };
|
|
224
|
+
//# sourceMappingURL=fileSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSearch.d.ts","names":["OpenAI","OpenAIClient","ServerTool","FileSearchComparisonType","FileSearchComparisonFilter","Array","FileSearchCompoundFilter","FileSearchFilter","FileSearchHybridSearchWeights","FileSearchRankingOptions","FileSearchOptions","FileSearchTool","Responses","fileSearch"],"sources":["../../src/tools/fileSearch.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * Comparison operators for file attribute filtering.\n */\nexport type FileSearchComparisonType = \"eq\" | \"ne\" | \"gt\" | \"gte\" | \"lt\" | \"lte\";\n/**\n * A filter used to compare a specified attribute key to a given value.\n */\nexport interface FileSearchComparisonFilter {\n /**\n * The comparison operator to use.\n * - `eq`: equals\n * - `ne`: not equal\n * - `gt`: greater than\n * - `gte`: greater than or equal\n * - `lt`: less than\n * - `lte`: less than or equal\n */\n type: FileSearchComparisonType;\n /**\n * The attribute key to compare against.\n */\n key: string;\n /**\n * The value to compare against the attribute key.\n * Supports string, number, boolean, or array of strings/numbers.\n */\n value: string | number | boolean | Array<string | number>;\n}\n/**\n * Combine multiple filters using `and` or `or`.\n */\nexport interface FileSearchCompoundFilter {\n /**\n * Type of operation: `and` or `or`.\n */\n type: \"and\" | \"or\";\n /**\n * Array of filters to combine.\n */\n filters: Array<FileSearchComparisonFilter | FileSearchCompoundFilter>;\n}\n/**\n * Filter type for file search - can be a comparison or compound filter.\n */\nexport type FileSearchFilter = FileSearchComparisonFilter | FileSearchCompoundFilter;\n/**\n * Weights for hybrid search balancing semantic and keyword matches.\n */\nexport interface FileSearchHybridSearchWeights {\n /**\n * The weight of semantic embedding matches (0-1).\n */\n embeddingWeight: number;\n /**\n * The weight of keyword/text matches (0-1).\n */\n textWeight: number;\n}\n/**\n * Ranking options for file search results.\n */\nexport interface FileSearchRankingOptions {\n /**\n * The ranker to use for the file search.\n * - `auto`: Automatically select the best ranker\n * - `default-2024-11-15`: Default ranker as of November 2024\n */\n ranker?: \"auto\" | \"default-2024-11-15\";\n /**\n * The score threshold for results (0-1).\n * Numbers closer to 1 return only the most relevant results but may return fewer.\n */\n scoreThreshold?: number;\n /**\n * Weights that control how reciprocal rank fusion balances semantic\n * embedding matches versus sparse keyword matches when hybrid search is enabled.\n */\n hybridSearch?: FileSearchHybridSearchWeights;\n}\n/**\n * Options for the File Search tool.\n */\nexport interface FileSearchOptions {\n /**\n * The IDs of the vector stores to search.\n * You must have previously created vector stores and uploaded files to them.\n */\n vectorStoreIds: string[];\n /**\n * The maximum number of results to return.\n * Must be between 1 and 50 inclusive.\n */\n maxNumResults?: number;\n /**\n * A filter to apply based on file attributes/metadata.\n * Use this to narrow down search results to specific categories or file types.\n */\n filters?: FileSearchFilter;\n /**\n * Ranking options to customize how results are scored and ordered.\n */\n rankingOptions?: FileSearchRankingOptions;\n}\n/**\n * OpenAI File Search tool type for the Responses API.\n */\nexport type FileSearchTool = OpenAIClient.Responses.FileSearchTool;\n/**\n * Creates a File Search tool that allows models to search your files\n * for relevant information using semantic and keyword search.\n *\n * File Search enables models to retrieve information from a knowledge base\n * of previously uploaded files stored in vector stores. This is a hosted tool\n * managed by OpenAI - you don't need to implement the search execution yourself.\n *\n * **Prerequisites**: Before using File Search, you must:\n * 1. Upload files to the File API with `purpose: \"assistants\"`\n * 2. Create a vector store\n * 3. Add files to the vector store\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-file-search | OpenAI File Search Documentation}\n *\n * @param options - Configuration options for the File Search tool\n * @returns A File Search tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-4.1\" });\n *\n * // Basic usage with a vector store\n * const response = await model.invoke(\n * \"What is deep research by OpenAI?\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"]\n * })]\n * }\n * );\n *\n * // Limit the number of results for lower latency\n * const response = await model.invoke(\n * \"Find information about pricing\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * maxNumResults: 5\n * })]\n * }\n * );\n *\n * // With metadata filtering\n * const response = await model.invoke(\n * \"Find recent blog posts about AI\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"eq\",\n * key: \"category\",\n * value: \"blog\"\n * }\n * })]\n * }\n * );\n *\n * // With compound filters (AND/OR)\n * const response = await model.invoke(\n * \"Find technical docs from 2024\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * filters: {\n * type: \"and\",\n * filters: [\n * { type: \"eq\", key: \"category\", value: \"technical\" },\n * { type: \"gte\", key: \"year\", value: 2024 }\n * ]\n * }\n * })]\n * }\n * );\n *\n * // With ranking options for more relevant results\n * const response = await model.invoke(\n * \"Find the most relevant information\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\"],\n * rankingOptions: {\n * scoreThreshold: 0.8,\n * ranker: \"auto\"\n * }\n * })]\n * }\n * );\n *\n * // Search multiple vector stores\n * const response = await model.invoke(\n * \"Search across all knowledge bases\",\n * {\n * tools: [tools.fileSearch({\n * vectorStoreIds: [\"vs_abc123\", \"vs_def456\"]\n * })]\n * }\n * );\n * ```\n *\n * @remarks\n * - Vector stores must be created and populated before using this tool\n * - The tool returns file citations in the response annotations\n * - Use `include: [\"file_search_call.results\"]` in the API call to get search results\n * - Supported file types include PDF, DOCX, TXT, MD, and many code file formats\n */\nexport declare function fileSearch(options: FileSearchOptions): ServerTool;\n//# sourceMappingURL=fileSearch.d.ts.map"],"mappings":";;;;;;;AAKA;AAIiBI,KAJLD,wBAAAA,GAI+B,IAAA,GAUjCA,IAAAA,GAAAA,IAAAA,GAAAA,KAAAA,GAAAA,IAS6BE,GAAAA,KAAK;AAK5C;;;AAQaA,UAhCID,0BAAAA,CAgCJC;EAAK;AAKlB;AAIA;AAaA;AAqBA;AAwBA;AA6GA;;;QAtMUF;;;;;;;;;qCAS6BE;;;;;UAKtBC,wBAAAA;;;;;;;;WAQJD,MAAMD,6BAA6BE;;;;;KAKpCC,gBAAAA,GAAmBH,6BAA6BE;;;;UAI3CE,6BAAAA;;;;;;;;;;;;;UAaAC,wBAAAA;;;;;;;;;;;;;;;;iBAgBED;;;;;UAKFE,iBAAAA;;;;;;;;;;;;;;;YAeHH;;;;mBAIOE;;;;;KAKTE,cAAAA,GAAiBV,QAAAA,CAAaW,SAAAA,CAAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6G5BE,UAAAA,UAAoBH,oBAAoBR"}
|