4
4
import * as Channel from "effect/Channel"
5
5
import * as Context from "effect/Context"
6
6
import * as Effect from "effect/Effect"
7
+ import * as Layer from "effect/Layer"
7
8
import type { ParseError } from "effect/ParseResult"
8
9
import * as Ref from "effect/Ref"
9
10
import * as Schema from "effect/Schema"
10
11
import * as Stream from "effect/Stream"
11
- import type { NoExcessProperties } from "effect/Types"
12
12
import type { AiError } from "./AiError.js"
13
13
import * as AiInput from "./AiInput.js"
14
14
import * as AiLanguageModel from "./AiLanguageModel.js"
15
15
import * as AiResponse from "./AiResponse.js"
16
+ import type * as AiTool from "./AiTool.js"
16
17
17
18
/**
18
19
* @since 1.0.0
@@ -56,9 +57,9 @@ export declare namespace AiChat {
56
57
*
57
58
* Both input and output messages will be added to the chat history.
58
59
*/
59
- readonly generateText : <
60
- Options extends NoExcessProperties < Omit < AiLanguageModel . GenerateTextOptions < any > , "system" > , Options >
61
- > ( options : Options ) => Effect . Effect <
60
+ readonly generateText : < Tools extends AiTool . Any , Options > (
61
+ options : Options & Omit < AiLanguageModel . GenerateTextOptions < Tools > , "system" >
62
+ ) => Effect . Effect <
62
63
AiLanguageModel . ExtractSuccess < Options > ,
63
64
AiLanguageModel . ExtractError < Options > ,
64
65
AiLanguageModel . ExtractContext < Options >
@@ -73,9 +74,9 @@ export declare namespace AiChat {
73
74
*
74
75
* Both input and output messages will be added to the chat history.
75
76
*/
76
- readonly streamText : <
77
- Options extends NoExcessProperties < Omit < AiLanguageModel . GenerateTextOptions < any > , "system" > , Options >
78
- > ( options : Options ) => Stream . Stream <
77
+ readonly streamText : < Tools extends AiTool . Any , Options > (
78
+ options : Options & Omit < AiLanguageModel . GenerateTextOptions < Tools > , "system" >
79
+ ) => Stream . Stream <
79
80
AiLanguageModel . ExtractSuccess < Options > ,
80
81
AiLanguageModel . ExtractError < Options > ,
81
82
AiLanguageModel . ExtractContext < Options >
@@ -103,7 +104,7 @@ export declare namespace AiChat {
103
104
104
105
/**
105
106
* @since 1.0.0
106
- * @category constructors
107
+ * @category Constructors
107
108
*/
108
109
export const fromPrompt = Effect . fnUntraced ( function * ( options : {
109
110
readonly prompt : AiInput . Raw
@@ -139,7 +140,7 @@ export const fromPrompt = Effect.fnUntraced(function*(options: {
139
140
)
140
141
} ) ,
141
142
semaphore . withPermits ( 1 ) ,
142
- Effect . withSpan ( "AiChat.send " , { captureStackTrace : false } )
143
+ Effect . withSpan ( "AiChat.generateText " , { captureStackTrace : false } )
143
144
)
144
145
} ,
145
146
streamText ( options ) {
@@ -167,7 +168,7 @@ export const fromPrompt = Effect.fnUntraced(function*(options: {
167
168
semaphore . release ( 1 )
168
169
)
169
170
) )
170
- } ) . pipe ( Stream . withSpan ( "AiChat.stream " , {
171
+ } ) . pipe ( Stream . withSpan ( "AiChat.streamText " , {
171
172
captureStackTrace : false
172
173
} ) ) as any
173
174
} ,
@@ -190,7 +191,7 @@ export const fromPrompt = Effect.fnUntraced(function*(options: {
190
191
)
191
192
} ) ,
192
193
semaphore . withPermits ( 1 ) ,
193
- Effect . withSpan ( "AiChat.structured " , {
194
+ Effect . withSpan ( "AiChat.generateObject " , {
194
195
attributes : {
195
196
toolCallId : "toolCallId" in options
196
197
? options . toolCallId
@@ -207,15 +208,15 @@ export const fromPrompt = Effect.fnUntraced(function*(options: {
207
208
208
209
/**
209
210
* @since 1.0.0
210
- * @category constructors
211
+ * @category Constructors
211
212
*/
212
213
export const empty : Effect . Effect < AiChat . Service , never , AiLanguageModel . AiLanguageModel > = fromPrompt ( { prompt : [ ] } )
213
214
214
215
const decodeUnknown = Schema . decodeUnknown ( AiInput . AiInput )
215
216
216
217
/**
217
218
* @since 1.0.0
218
- * @category constructors
219
+ * @category Constructors
219
220
*/
220
221
export const fromExport = ( data : unknown ) : Effect . Effect < AiChat . Service , ParseError , AiLanguageModel . AiLanguageModel > =>
221
222
Effect . flatMap ( decodeUnknown ( data ) , ( prompt ) => fromPrompt ( { prompt } ) )
@@ -224,7 +225,7 @@ const decodeJson = Schema.decode(AiInput.FromJson)
224
225
225
226
/**
226
227
* @since 1.0.0
227
- * @category constructors
228
+ * @category Constructors
228
229
*/
229
230
export const fromJson = ( data : string ) : Effect . Effect < AiChat . Service , ParseError , AiLanguageModel . AiLanguageModel > =>
230
231
Effect . flatMap ( decodeJson ( data ) , ( prompt ) => fromPrompt ( { prompt } ) )
0 commit comments