@effect/ai-openai 4.0.0-beta.9 → 4.0.0-beta.90
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/dist/Generated.d.ts +66675 -37672
- package/dist/Generated.d.ts.map +1 -1
- package/dist/Generated.js +1 -1
- package/dist/Generated.js.map +1 -1
- package/dist/OpenAiClient.d.ts +170 -29
- package/dist/OpenAiClient.d.ts.map +1 -1
- package/dist/OpenAiClient.js +321 -46
- package/dist/OpenAiClient.js.map +1 -1
- package/dist/OpenAiClientGenerated.d.ts +91 -0
- package/dist/OpenAiClientGenerated.d.ts.map +1 -0
- package/dist/OpenAiClientGenerated.js +84 -0
- package/dist/OpenAiClientGenerated.js.map +1 -0
- package/dist/OpenAiConfig.d.ts +88 -10
- package/dist/OpenAiConfig.d.ts.map +1 -1
- package/dist/OpenAiConfig.js +42 -7
- package/dist/OpenAiConfig.js.map +1 -1
- package/dist/OpenAiEmbeddingModel.d.ts +188 -0
- package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
- package/dist/OpenAiEmbeddingModel.js +194 -0
- package/dist/OpenAiEmbeddingModel.js.map +1 -0
- package/dist/OpenAiError.d.ts +168 -35
- package/dist/OpenAiError.d.ts.map +1 -1
- package/dist/OpenAiError.js +1 -1
- package/dist/OpenAiLanguageModel.d.ts +357 -63
- package/dist/OpenAiLanguageModel.d.ts.map +1 -1
- package/dist/OpenAiLanguageModel.js +390 -168
- package/dist/OpenAiLanguageModel.js.map +1 -1
- package/dist/OpenAiSchema.d.ts +2325 -0
- package/dist/OpenAiSchema.d.ts.map +1 -0
- package/dist/OpenAiSchema.js +811 -0
- package/dist/OpenAiSchema.js.map +1 -0
- package/dist/OpenAiTelemetry.d.ts +63 -22
- package/dist/OpenAiTelemetry.d.ts.map +1 -1
- package/dist/OpenAiTelemetry.js +20 -10
- package/dist/OpenAiTelemetry.js.map +1 -1
- package/dist/OpenAiTool.d.ts +157 -67
- package/dist/OpenAiTool.d.ts.map +1 -1
- package/dist/OpenAiTool.js +125 -39
- package/dist/OpenAiTool.js.map +1 -1
- package/dist/index.d.ts +19 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -33
- package/dist/index.js.map +1 -1
- package/dist/internal/errors.js +4 -4
- package/dist/internal/errors.js.map +1 -1
- package/dist/internal/utilities.js +0 -4
- package/dist/internal/utilities.js.map +1 -1
- package/package.json +3 -3
- package/src/Generated.ts +9720 -4890
- package/src/OpenAiClient.ts +499 -98
- package/src/OpenAiClientGenerated.ts +202 -0
- package/src/OpenAiConfig.ts +89 -11
- package/src/OpenAiEmbeddingModel.ts +332 -0
- package/src/OpenAiError.ts +170 -35
- package/src/OpenAiLanguageModel.ts +776 -169
- package/src/OpenAiSchema.ts +1286 -0
- package/src/OpenAiTelemetry.ts +69 -28
- package/src/OpenAiTool.ts +126 -40
- package/src/index.ts +22 -33
- package/src/internal/errors.ts +6 -4
- package/src/internal/utilities.ts +0 -6
package/src/OpenAiTelemetry.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OpenAI telemetry attributes
|
|
2
|
+
* The `OpenAiTelemetry` module defines OpenAI-specific telemetry attributes
|
|
3
|
+
* and a helper for adding them to a tracing span. It keeps the standard GenAI
|
|
4
|
+
* telemetry attributes and adds request and response metadata, such as response
|
|
5
|
+
* format, service tier, and system fingerprint, under the `gen_ai.openai.*`
|
|
6
|
+
* OpenTelemetry namespaces.
|
|
3
7
|
*
|
|
4
|
-
*
|
|
5
|
-
* semantic conventions, extending the base GenAI attributes with OpenAI-specific
|
|
6
|
-
* request and response metadata.
|
|
7
|
-
*
|
|
8
|
-
* @since 1.0.0
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
import { dual } from "effect/Function"
|
|
11
11
|
import * as String from "effect/String"
|
|
@@ -17,10 +17,14 @@ import * as Telemetry from "effect/unstable/ai/Telemetry"
|
|
|
17
17
|
* The attributes used to describe telemetry in the context of Generative
|
|
18
18
|
* Artificial Intelligence (GenAI) Models requests and responses.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* **Details**
|
|
21
|
+
*
|
|
22
|
+
* These attributes follow the OpenTelemetry generative AI semantic
|
|
23
|
+
* conventions:
|
|
24
|
+
* https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/
|
|
21
25
|
*
|
|
22
|
-
* @since 1.0.0
|
|
23
26
|
* @category models
|
|
27
|
+
* @since 4.0.0
|
|
24
28
|
*/
|
|
25
29
|
export type OpenAiTelemetryAttributes = Simplify<
|
|
26
30
|
& Telemetry.GenAITelemetryAttributes
|
|
@@ -30,10 +34,10 @@ export type OpenAiTelemetryAttributes = Simplify<
|
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
36
|
* All telemetry attributes which are part of the GenAI specification,
|
|
33
|
-
* including the
|
|
37
|
+
* including the OpenAI-specific attributes.
|
|
34
38
|
*
|
|
35
|
-
* @since 1.0.0
|
|
36
39
|
* @category models
|
|
40
|
+
* @since 4.0.0
|
|
37
41
|
*/
|
|
38
42
|
export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes
|
|
39
43
|
|
|
@@ -41,8 +45,8 @@ export type AllAttributes = Telemetry.AllAttributes & RequestAttributes & Respon
|
|
|
41
45
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
42
46
|
* namespaced by `gen_ai.openai.request`.
|
|
43
47
|
*
|
|
44
|
-
* @since 1.0.0
|
|
45
48
|
* @category models
|
|
49
|
+
* @since 4.0.0
|
|
46
50
|
*/
|
|
47
51
|
export interface RequestAttributes {
|
|
48
52
|
/**
|
|
@@ -59,8 +63,8 @@ export interface RequestAttributes {
|
|
|
59
63
|
* Telemetry attributes which are part of the GenAI specification and are
|
|
60
64
|
* namespaced by `gen_ai.openai.response`.
|
|
61
65
|
*
|
|
62
|
-
* @since 1.0.0
|
|
63
66
|
* @category models
|
|
67
|
+
* @since 4.0.0
|
|
64
68
|
*/
|
|
65
69
|
export interface ResponseAttributes {
|
|
66
70
|
/**
|
|
@@ -78,11 +82,13 @@ export interface ResponseAttributes {
|
|
|
78
82
|
* The `gen_ai.openai.request.response_format` attribute has the following
|
|
79
83
|
* list of well-known values.
|
|
80
84
|
*
|
|
85
|
+
* **Details**
|
|
86
|
+
*
|
|
81
87
|
* If one of them applies, then the respective value **MUST** be used;
|
|
82
88
|
* otherwise, a custom value **MAY** be used.
|
|
83
89
|
*
|
|
84
|
-
* @since 1.0.0
|
|
85
90
|
* @category models
|
|
91
|
+
* @since 4.0.0
|
|
86
92
|
*/
|
|
87
93
|
export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
|
|
88
94
|
|
|
@@ -90,17 +96,22 @@ export type WellKnownResponseFormat = "json_object" | "json_schema" | "text"
|
|
|
90
96
|
* The `gen_ai.openai.request.service_tier` attribute has the following
|
|
91
97
|
* list of well-known values.
|
|
92
98
|
*
|
|
99
|
+
* **Details**
|
|
100
|
+
*
|
|
93
101
|
* If one of them applies, then the respective value **MUST** be used;
|
|
94
102
|
* otherwise, a custom value **MAY** be used.
|
|
95
103
|
*
|
|
96
|
-
* @since 1.0.0
|
|
97
104
|
* @category models
|
|
105
|
+
* @since 4.0.0
|
|
98
106
|
*/
|
|
99
107
|
export type WellKnownServiceTier = "auto" | "default"
|
|
100
108
|
|
|
101
109
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
110
|
+
* Options accepted by `addGenAIAnnotations`, combining standard GenAI
|
|
111
|
+
* telemetry attributes with optional OpenAI request and response attributes.
|
|
112
|
+
*
|
|
113
|
+
* @category options
|
|
114
|
+
* @since 4.0.0
|
|
104
115
|
*/
|
|
105
116
|
export type OpenAiTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
|
|
106
117
|
openai?: {
|
|
@@ -117,33 +128,63 @@ const addOpenAiResponseAttributes = Telemetry.addSpanAttributes("gen_ai.openai.r
|
|
|
117
128
|
>
|
|
118
129
|
|
|
119
130
|
/**
|
|
120
|
-
* Applies the specified
|
|
131
|
+
* Applies the specified OpenAI GenAI telemetry attributes to the provided
|
|
121
132
|
* `Span`.
|
|
122
133
|
*
|
|
123
|
-
* **
|
|
134
|
+
* **When to use**
|
|
135
|
+
*
|
|
136
|
+
* Use to annotate an existing OpenTelemetry span with standard GenAI attributes
|
|
137
|
+
* plus OpenAI-specific request and response metadata.
|
|
138
|
+
*
|
|
139
|
+
* **Gotchas**
|
|
140
|
+
*
|
|
141
|
+
* Mutates the supplied `Span` in place.
|
|
142
|
+
*
|
|
143
|
+
* @see {@link OpenAiTelemetryAttributeOptions} for the accepted telemetry attributes
|
|
144
|
+
* @see {@link Telemetry.addGenAIAnnotations} for the provider-neutral annotation helper
|
|
124
145
|
*
|
|
125
|
-
* @
|
|
126
|
-
* @since
|
|
146
|
+
* @category tracing
|
|
147
|
+
* @since 4.0.0
|
|
127
148
|
*/
|
|
128
149
|
export const addGenAIAnnotations: {
|
|
129
150
|
/**
|
|
130
|
-
* Applies the specified
|
|
151
|
+
* Applies the specified OpenAI GenAI telemetry attributes to the provided
|
|
131
152
|
* `Span`.
|
|
132
153
|
*
|
|
133
|
-
* **
|
|
154
|
+
* **When to use**
|
|
134
155
|
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
156
|
+
* Use to annotate an existing OpenTelemetry span with standard GenAI attributes
|
|
157
|
+
* plus OpenAI-specific request and response metadata.
|
|
158
|
+
*
|
|
159
|
+
* **Gotchas**
|
|
160
|
+
*
|
|
161
|
+
* Mutates the supplied `Span` in place.
|
|
162
|
+
*
|
|
163
|
+
* @see {@link OpenAiTelemetryAttributeOptions} for the accepted telemetry attributes
|
|
164
|
+
* @see {@link Telemetry.addGenAIAnnotations} for the provider-neutral annotation helper
|
|
165
|
+
*
|
|
166
|
+
* @category tracing
|
|
167
|
+
* @since 4.0.0
|
|
137
168
|
*/
|
|
138
169
|
(options: OpenAiTelemetryAttributeOptions): (span: Span) => void
|
|
139
170
|
/**
|
|
140
|
-
* Applies the specified
|
|
171
|
+
* Applies the specified OpenAI GenAI telemetry attributes to the provided
|
|
141
172
|
* `Span`.
|
|
142
173
|
*
|
|
143
|
-
* **
|
|
174
|
+
* **When to use**
|
|
175
|
+
*
|
|
176
|
+
* Use to annotate an existing OpenTelemetry span with standard GenAI attributes
|
|
177
|
+
* plus OpenAI-specific request and response metadata.
|
|
178
|
+
*
|
|
179
|
+
* **Gotchas**
|
|
180
|
+
*
|
|
181
|
+
* Mutates the supplied `Span` in place.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link OpenAiTelemetryAttributeOptions} for the accepted telemetry attributes
|
|
184
|
+
* @see {@link Telemetry.addGenAIAnnotations} for the provider-neutral annotation helper
|
|
144
185
|
*
|
|
145
|
-
* @
|
|
146
|
-
* @since
|
|
186
|
+
* @category tracing
|
|
187
|
+
* @since 4.0.0
|
|
147
188
|
*/
|
|
148
189
|
(span: Span, options: OpenAiTelemetryAttributeOptions): void
|
|
149
190
|
} = dual(2, (span: Span, options: OpenAiTelemetryAttributeOptions) => {
|
package/src/OpenAiTool.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OpenAI provider
|
|
2
|
+
* The `OpenAiTool` module defines OpenAI provider tools for Effect AI language
|
|
3
|
+
* model requests. It exposes typed descriptors for tools such as Apply Patch,
|
|
4
|
+
* Code Interpreter, File Search, Image Generation, MCP, Web Search, and
|
|
5
|
+
* shell-like local tools, including their provider names, configuration
|
|
6
|
+
* arguments, call parameters, success schemas, and handler requirements.
|
|
3
7
|
*
|
|
4
|
-
*
|
|
5
|
-
* code interpreter, file search, and web search functionality.
|
|
6
|
-
*
|
|
7
|
-
* @since 1.0.0
|
|
8
|
+
* @since 4.0.0
|
|
8
9
|
*/
|
|
9
10
|
import * as Schema from "effect/Schema"
|
|
10
11
|
import * as Tool from "effect/unstable/ai/Tool"
|
|
@@ -13,8 +14,8 @@ import * as Generated from "./Generated.ts"
|
|
|
13
14
|
/**
|
|
14
15
|
* Union of all OpenAI provider-defined tools.
|
|
15
16
|
*
|
|
16
|
-
* @since 1.0.0
|
|
17
17
|
* @category models
|
|
18
|
+
* @since 4.0.0
|
|
18
19
|
*/
|
|
19
20
|
export type OpenAiTool =
|
|
20
21
|
| ReturnType<typeof ApplyPatch>
|
|
@@ -28,14 +29,18 @@ export type OpenAiTool =
|
|
|
28
29
|
| ReturnType<typeof WebSearchPreview>
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* OpenAI Apply Patch tool
|
|
32
|
+
* Defines the OpenAI Apply Patch tool that allows the model to apply diffs by creating,
|
|
33
|
+
* deleting, or updating files. This local tool runs in your environment and
|
|
34
|
+
* requires a handler to execute file operations.
|
|
35
|
+
*
|
|
36
|
+
* **When to use**
|
|
32
37
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
38
|
+
* Use when you want an OpenAI model to request structured file edits as create,
|
|
39
|
+
* delete, or update operations that your application executes through a local
|
|
40
|
+
* handler.
|
|
36
41
|
*
|
|
37
|
-
* @since 1.0.0
|
|
38
42
|
* @category tools
|
|
43
|
+
* @since 4.0.0
|
|
39
44
|
*/
|
|
40
45
|
export const ApplyPatch = Tool.providerDefined({
|
|
41
46
|
id: "openai.apply_patch",
|
|
@@ -53,12 +58,21 @@ export const ApplyPatch = Tool.providerDefined({
|
|
|
53
58
|
})
|
|
54
59
|
|
|
55
60
|
/**
|
|
56
|
-
* OpenAI Code Interpreter tool
|
|
61
|
+
* Defines the OpenAI Code Interpreter tool that allows the model to execute Python code in
|
|
62
|
+
* a sandboxed environment.
|
|
63
|
+
*
|
|
64
|
+
* **When to use**
|
|
65
|
+
*
|
|
66
|
+
* Use to enable OpenAI-hosted Python execution for a model response.
|
|
57
67
|
*
|
|
58
|
-
*
|
|
68
|
+
* **Details**
|
|
69
|
+
*
|
|
70
|
+
* The tool is configured with a `container` argument. Successful tool calls
|
|
71
|
+
* expose `outputs`, which may contain logs or generated images, or `null` when
|
|
72
|
+
* no outputs are available.
|
|
59
73
|
*
|
|
60
|
-
* @since 1.0.0
|
|
61
74
|
* @category tools
|
|
75
|
+
* @since 4.0.0
|
|
62
76
|
*/
|
|
63
77
|
export const CodeInterpreter = Tool.providerDefined({
|
|
64
78
|
id: "openai.code_interpreter",
|
|
@@ -77,12 +91,22 @@ export const CodeInterpreter = Tool.providerDefined({
|
|
|
77
91
|
})
|
|
78
92
|
|
|
79
93
|
/**
|
|
80
|
-
* OpenAI File Search tool
|
|
94
|
+
* Defines the OpenAI File Search tool that enables the model to search through uploaded
|
|
95
|
+
* files and vector stores.
|
|
96
|
+
*
|
|
97
|
+
* **When to use**
|
|
98
|
+
*
|
|
99
|
+
* Use to let an OpenAI model search uploaded files through one or more vector
|
|
100
|
+
* stores.
|
|
101
|
+
*
|
|
102
|
+
* **Details**
|
|
81
103
|
*
|
|
82
|
-
*
|
|
104
|
+
* The tool requires `vector_store_ids` and accepts optional `filters`,
|
|
105
|
+
* `max_num_results`, and `ranking_options`. Successful tool calls expose the
|
|
106
|
+
* search `status`, generated `queries`, and optional `results`.
|
|
83
107
|
*
|
|
84
|
-
* @since 1.0.0
|
|
85
108
|
* @category tools
|
|
109
|
+
* @since 4.0.0
|
|
86
110
|
*/
|
|
87
111
|
export const FileSearch = Tool.providerDefined({
|
|
88
112
|
id: "openai.file_search",
|
|
@@ -102,12 +126,23 @@ export const FileSearch = Tool.providerDefined({
|
|
|
102
126
|
})
|
|
103
127
|
|
|
104
128
|
/**
|
|
105
|
-
* OpenAI Image Generation tool
|
|
129
|
+
* Defines the OpenAI Image Generation tool that enables the model to generate images using
|
|
130
|
+
* the GPT image models.
|
|
106
131
|
*
|
|
107
|
-
*
|
|
132
|
+
* **When to use**
|
|
133
|
+
*
|
|
134
|
+
* Use to enable OpenAI provider-defined image generation through a language
|
|
135
|
+
* model response.
|
|
136
|
+
*
|
|
137
|
+
* **Details**
|
|
138
|
+
*
|
|
139
|
+
* The tool configures the `image_generation` provider tool, including model,
|
|
140
|
+
* size, quality, output format, moderation, background, input-image options,
|
|
141
|
+
* and partial image settings. Successful tool calls expose `result` as base64
|
|
142
|
+
* image data or `null`.
|
|
108
143
|
*
|
|
109
|
-
* @since 1.0.0
|
|
110
144
|
* @category tools
|
|
145
|
+
* @since 4.0.0
|
|
111
146
|
*/
|
|
112
147
|
export const ImageGeneration = Tool.providerDefined({
|
|
113
148
|
id: "openai.image_generation",
|
|
@@ -131,13 +166,23 @@ export const ImageGeneration = Tool.providerDefined({
|
|
|
131
166
|
})
|
|
132
167
|
|
|
133
168
|
/**
|
|
134
|
-
* OpenAI Local Shell tool
|
|
169
|
+
* Defines the OpenAI Local Shell tool that enables the model to run a command with a local
|
|
170
|
+
* shell. This local tool runs in your environment and requires a handler to
|
|
171
|
+
* execute commands.
|
|
172
|
+
*
|
|
173
|
+
* **When to use**
|
|
135
174
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
175
|
+
* Use to let an OpenAI model request local shell commands that your application
|
|
176
|
+
* executes through a handler.
|
|
177
|
+
*
|
|
178
|
+
* **Details**
|
|
179
|
+
*
|
|
180
|
+
* The tool exposes a provider-defined `local_shell` call. It is marked as
|
|
181
|
+
* handler-required, so applications must provide the command execution policy
|
|
182
|
+
* and implementation.
|
|
138
183
|
*
|
|
139
|
-
* @since 1.0.0
|
|
140
184
|
* @category tools
|
|
185
|
+
* @since 4.0.0
|
|
141
186
|
*/
|
|
142
187
|
export const LocalShell = Tool.providerDefined({
|
|
143
188
|
id: "openai.local_shell",
|
|
@@ -153,13 +198,27 @@ export const LocalShell = Tool.providerDefined({
|
|
|
153
198
|
})
|
|
154
199
|
|
|
155
200
|
/**
|
|
156
|
-
* OpenAI MCP tool
|
|
201
|
+
* Defines the OpenAI MCP tool that gives the model access to additional tools via remote
|
|
202
|
+
* Model Context Protocol (MCP) servers.
|
|
203
|
+
*
|
|
204
|
+
* **When to use**
|
|
157
205
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
206
|
+
* Use to let an OpenAI model call tools exposed by a remote MCP server.
|
|
207
|
+
*
|
|
208
|
+
* **Details**
|
|
209
|
+
*
|
|
210
|
+
* The tool accepts MCP server configuration such as allowed tools,
|
|
211
|
+
* authorization, connector id, approval requirements, server metadata, and
|
|
212
|
+
* server URL. Tool call results include the called tool name, arguments, output,
|
|
213
|
+
* error, and server label.
|
|
214
|
+
*
|
|
215
|
+
* **Gotchas**
|
|
216
|
+
*
|
|
217
|
+
* This schema leaves both `server_url` and `connector_id` optional, but OpenAI
|
|
218
|
+
* may require a server URL or connector id for a usable MCP tool configuration.
|
|
160
219
|
*
|
|
161
|
-
* @since 1.0.0
|
|
162
220
|
* @category tools
|
|
221
|
+
* @since 4.0.0
|
|
163
222
|
*/
|
|
164
223
|
export const Mcp = Tool.providerDefined({
|
|
165
224
|
id: "openai.mcp",
|
|
@@ -174,6 +233,7 @@ export const Mcp = Tool.providerDefined({
|
|
|
174
233
|
server_label: Generated.MCPTool.fields.server_label,
|
|
175
234
|
server_url: Generated.MCPTool.fields.server_url
|
|
176
235
|
}),
|
|
236
|
+
parameters: Schema.Unknown,
|
|
177
237
|
success: Schema.Struct({
|
|
178
238
|
type: Generated.MCPToolCall.fields.type,
|
|
179
239
|
name: Generated.MCPToolCall.fields.name,
|
|
@@ -185,14 +245,21 @@ export const Mcp = Tool.providerDefined({
|
|
|
185
245
|
})
|
|
186
246
|
|
|
187
247
|
/**
|
|
188
|
-
* OpenAI
|
|
248
|
+
* Defines the OpenAI shell tool for model-requested command execution.
|
|
189
249
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
250
|
+
* **When to use**
|
|
251
|
+
*
|
|
252
|
+
* Use to let an OpenAI model request shell commands that your application
|
|
253
|
+
* executes through a handler.
|
|
254
|
+
*
|
|
255
|
+
* **Details**
|
|
256
|
+
*
|
|
257
|
+
* The tool exposes a provider-defined `shell` call. It is marked as
|
|
258
|
+
* handler-required, so applications must provide the command execution policy
|
|
259
|
+
* and implementation.
|
|
193
260
|
*
|
|
194
|
-
* @since 1.0.0
|
|
195
261
|
* @category tools
|
|
262
|
+
* @since 4.0.0
|
|
196
263
|
*/
|
|
197
264
|
export const Shell = Tool.providerDefined({
|
|
198
265
|
id: "openai.shell",
|
|
@@ -203,17 +270,27 @@ export const Shell = Tool.providerDefined({
|
|
|
203
270
|
action: Generated.FunctionShellCall.fields.action
|
|
204
271
|
}),
|
|
205
272
|
success: Schema.Struct({
|
|
206
|
-
output: Generated.
|
|
273
|
+
output: Generated.FunctionShellCallOutput.fields.output
|
|
207
274
|
})
|
|
208
275
|
})
|
|
209
276
|
|
|
210
277
|
/**
|
|
211
|
-
* OpenAI Web Search tool
|
|
278
|
+
* Defines the OpenAI Web Search tool that enables the model to search the web for
|
|
279
|
+
* information.
|
|
280
|
+
*
|
|
281
|
+
* **When to use**
|
|
212
282
|
*
|
|
213
|
-
*
|
|
283
|
+
* Use to enable OpenAI provider-defined web search for a model response.
|
|
284
|
+
*
|
|
285
|
+
* **Details**
|
|
286
|
+
*
|
|
287
|
+
* The tool accepts optional filters, user location, and search context size.
|
|
288
|
+
* Successful calls expose the performed search action and status.
|
|
289
|
+
*
|
|
290
|
+
* @see {@link WebSearchPreview} for the preview web search provider tool
|
|
214
291
|
*
|
|
215
|
-
* @since 1.0.0
|
|
216
292
|
* @category tools
|
|
293
|
+
* @since 4.0.0
|
|
217
294
|
*/
|
|
218
295
|
export const WebSearch = Tool.providerDefined({
|
|
219
296
|
id: "openai.web_search",
|
|
@@ -234,12 +311,21 @@ export const WebSearch = Tool.providerDefined({
|
|
|
234
311
|
})
|
|
235
312
|
|
|
236
313
|
/**
|
|
237
|
-
* OpenAI Web Search
|
|
314
|
+
* Defines the OpenAI preview Web Search tool for model responses.
|
|
315
|
+
*
|
|
316
|
+
* **When to use**
|
|
317
|
+
*
|
|
318
|
+
* Use to enable the preview OpenAI web search provider tool.
|
|
319
|
+
*
|
|
320
|
+
* **Details**
|
|
321
|
+
*
|
|
322
|
+
* The preview tool accepts optional user location and search context size, then
|
|
323
|
+
* exposes the performed search action and status in successful calls.
|
|
238
324
|
*
|
|
239
|
-
*
|
|
325
|
+
* @see {@link WebSearch} for the stable web search provider tool
|
|
240
326
|
*
|
|
241
|
-
* @since 1.0.0
|
|
242
327
|
* @category tools
|
|
328
|
+
* @since 4.0.0
|
|
243
329
|
*/
|
|
244
330
|
export const WebSearchPreview = Tool.providerDefined({
|
|
245
331
|
id: "openai.web_search_preview",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
@@ -10,57 +10,46 @@
|
|
|
10
10
|
export * as Generated from "./Generated.ts"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* Provides a type-safe, Effect-based client for OpenAI operations including
|
|
16
|
-
* completions, embeddings, and streaming responses.
|
|
17
|
-
*
|
|
18
|
-
* @since 1.0.0
|
|
13
|
+
* @since 4.0.0
|
|
19
14
|
*/
|
|
20
15
|
export * as OpenAiClient from "./OpenAiClient.ts"
|
|
21
16
|
|
|
22
17
|
/**
|
|
23
|
-
* @since
|
|
18
|
+
* @since 4.0.0
|
|
19
|
+
*/
|
|
20
|
+
export * as OpenAiClientGenerated from "./OpenAiClientGenerated.ts"
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @since 4.0.0
|
|
24
24
|
*/
|
|
25
25
|
export * as OpenAiConfig from "./OpenAiConfig.ts"
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @since
|
|
28
|
+
* @since 4.0.0
|
|
29
|
+
*/
|
|
30
|
+
export * as OpenAiEmbeddingModel from "./OpenAiEmbeddingModel.ts"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @since 4.0.0
|
|
34
34
|
*/
|
|
35
35
|
export * as OpenAiError from "./OpenAiError.ts"
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* Provides a LanguageModel implementation for OpenAI's responses API,
|
|
41
|
-
* supporting text generation, structured output, tool calling, and streaming.
|
|
42
|
-
*
|
|
43
|
-
* @since 1.0.0
|
|
38
|
+
* @since 4.0.0
|
|
44
39
|
*/
|
|
45
40
|
export * as OpenAiLanguageModel from "./OpenAiLanguageModel.ts"
|
|
46
41
|
|
|
47
42
|
/**
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
* @since 1.0.0
|
|
43
|
+
* @since 4.0.0
|
|
44
|
+
*/
|
|
45
|
+
export * as OpenAiSchema from "./OpenAiSchema.ts"
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @since 4.0.0
|
|
55
49
|
*/
|
|
56
50
|
export * as OpenAiTelemetry from "./OpenAiTelemetry.ts"
|
|
57
51
|
|
|
58
52
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* Provides tools that are natively supported by OpenAI's API, including
|
|
62
|
-
* code interpreter, file search, and web search functionality.
|
|
63
|
-
*
|
|
64
|
-
* @since 1.0.0
|
|
53
|
+
* @since 4.0.0
|
|
65
54
|
*/
|
|
66
55
|
export * as OpenAiTool from "./OpenAiTool.ts"
|
package/src/internal/errors.ts
CHANGED
|
@@ -161,12 +161,14 @@ export const parseRateLimitHeaders = (headers: Record<string, string>) => {
|
|
|
161
161
|
let retryAfter: Duration.Duration | undefined
|
|
162
162
|
if (Predicate.isNotUndefined(retryAfterRaw)) {
|
|
163
163
|
const parsed = Number.parse(retryAfterRaw)
|
|
164
|
-
if (
|
|
165
|
-
retryAfter = Duration.seconds(parsed)
|
|
164
|
+
if (Option.isSome(parsed)) {
|
|
165
|
+
retryAfter = Duration.seconds(parsed.value)
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
const remainingRaw = headers["x-ratelimit-remaining-requests"]
|
|
169
|
-
const remaining = Predicate.isNotUndefined(remainingRaw)
|
|
169
|
+
const remaining = Predicate.isNotUndefined(remainingRaw)
|
|
170
|
+
? Option.getOrNull(Number.parse(remainingRaw))
|
|
171
|
+
: null
|
|
170
172
|
return {
|
|
171
173
|
retryAfter,
|
|
172
174
|
limit: headers["x-ratelimit-limit-requests"] ?? null,
|
|
@@ -187,7 +189,7 @@ export const buildHttpRequestDetails = (
|
|
|
187
189
|
method: request.method,
|
|
188
190
|
url: request.url,
|
|
189
191
|
urlParams: Array.from(request.urlParams),
|
|
190
|
-
hash: request.hash,
|
|
192
|
+
hash: Option.getOrUndefined(request.hash),
|
|
191
193
|
headers: Redactable.redact(request.headers) as Record<string, string>
|
|
192
194
|
})
|
|
193
195
|
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type * as Response from "effect/unstable/ai/Response"
|
|
2
2
|
|
|
3
|
-
/** @internal */
|
|
4
|
-
export const ProviderOptionsKey = "@effect/ai-openai/OpenAiLanguageModel/ProviderOptions"
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
export const ProviderMetadataKey = "@effect/ai-openai/OpenAiLanguageModel/ProviderMetadata"
|
|
8
|
-
|
|
9
3
|
const finishReasonMap: Record<string, Response.FinishReason> = {
|
|
10
4
|
content_filter: "content-filter",
|
|
11
5
|
function_call: "tool-calls",
|