@effect/ai 0.26.0 → 0.27.0
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/Chat/package.json +6 -0
- package/EmbeddingModel/package.json +6 -0
- package/IdGenerator/package.json +6 -0
- package/LanguageModel/package.json +6 -0
- package/Model/package.json +6 -0
- package/Prompt/package.json +6 -0
- package/Response/package.json +6 -0
- package/Telemetry/package.json +6 -0
- package/Tool/package.json +6 -0
- package/Toolkit/package.json +6 -0
- package/dist/cjs/AiError.js +575 -11
- package/dist/cjs/AiError.js.map +1 -1
- package/dist/cjs/Chat.js +302 -0
- package/dist/cjs/Chat.js.map +1 -0
- package/dist/cjs/EmbeddingModel.js +184 -0
- package/dist/cjs/EmbeddingModel.js.map +1 -0
- package/dist/cjs/IdGenerator.js +255 -0
- package/dist/cjs/IdGenerator.js.map +1 -0
- package/dist/cjs/LanguageModel.js +584 -0
- package/dist/cjs/LanguageModel.js.map +1 -0
- package/dist/cjs/McpServer.js +12 -4
- package/dist/cjs/McpServer.js.map +1 -1
- package/dist/cjs/Model.js +118 -0
- package/dist/cjs/Model.js.map +1 -0
- package/dist/cjs/Prompt.js +649 -0
- package/dist/cjs/Prompt.js.map +1 -0
- package/dist/cjs/Response.js +635 -0
- package/dist/cjs/Response.js.map +1 -0
- package/dist/cjs/Telemetry.js +176 -0
- package/dist/cjs/Telemetry.js.map +1 -0
- package/dist/cjs/Tokenizer.js +87 -8
- package/dist/cjs/Tokenizer.js.map +1 -1
- package/dist/cjs/Tool.js +556 -0
- package/dist/cjs/Tool.js.map +1 -0
- package/dist/cjs/Toolkit.js +279 -0
- package/dist/cjs/Toolkit.js.map +1 -0
- package/dist/cjs/index.js +21 -19
- package/dist/dts/AiError.d.ts +577 -9
- package/dist/dts/AiError.d.ts.map +1 -1
- package/dist/dts/Chat.d.ts +356 -0
- package/dist/dts/Chat.d.ts.map +1 -0
- package/dist/dts/EmbeddingModel.d.ts +153 -0
- package/dist/dts/EmbeddingModel.d.ts.map +1 -0
- package/dist/dts/IdGenerator.d.ts +272 -0
- package/dist/dts/IdGenerator.d.ts.map +1 -0
- package/dist/dts/LanguageModel.d.ts +458 -0
- package/dist/dts/LanguageModel.d.ts.map +1 -0
- package/dist/dts/McpSchema.d.ts +25 -25
- package/dist/dts/McpServer.d.ts +6 -4
- package/dist/dts/McpServer.d.ts.map +1 -1
- package/dist/dts/Model.d.ts +124 -0
- package/dist/dts/Model.d.ts.map +1 -0
- package/dist/dts/Prompt.d.ts +1119 -0
- package/dist/dts/Prompt.d.ts.map +1 -0
- package/dist/dts/Response.d.ts +1519 -0
- package/dist/dts/Response.d.ts.map +1 -0
- package/dist/dts/Telemetry.d.ts +520 -0
- package/dist/dts/Telemetry.d.ts.map +1 -0
- package/dist/dts/Tokenizer.d.ts +131 -13
- package/dist/dts/Tokenizer.d.ts.map +1 -1
- package/dist/dts/Tool.d.ts +876 -0
- package/dist/dts/Tool.d.ts.map +1 -0
- package/dist/dts/Toolkit.d.ts +310 -0
- package/dist/dts/Toolkit.d.ts.map +1 -0
- package/dist/dts/index.d.ts +498 -13
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/AiError.js +570 -10
- package/dist/esm/AiError.js.map +1 -1
- package/dist/esm/Chat.js +291 -0
- package/dist/esm/Chat.js.map +1 -0
- package/dist/esm/EmbeddingModel.js +173 -0
- package/dist/esm/EmbeddingModel.js.map +1 -0
- package/dist/esm/IdGenerator.js +245 -0
- package/dist/esm/IdGenerator.js.map +1 -0
- package/dist/esm/LanguageModel.js +572 -0
- package/dist/esm/LanguageModel.js.map +1 -0
- package/dist/esm/McpServer.js +12 -4
- package/dist/esm/McpServer.js.map +1 -1
- package/dist/esm/Model.js +108 -0
- package/dist/esm/Model.js.map +1 -0
- package/dist/esm/Prompt.js +633 -0
- package/dist/esm/Prompt.js.map +1 -0
- package/dist/esm/Response.js +619 -0
- package/dist/esm/Response.js.map +1 -0
- package/dist/esm/Telemetry.js +166 -0
- package/dist/esm/Telemetry.js.map +1 -0
- package/dist/esm/Tokenizer.js +87 -8
- package/dist/esm/Tokenizer.js.map +1 -1
- package/dist/esm/Tool.js +534 -0
- package/dist/esm/Tool.js.map +1 -0
- package/dist/esm/Toolkit.js +269 -0
- package/dist/esm/Toolkit.js.map +1 -0
- package/dist/esm/index.js +498 -13
- package/dist/esm/index.js.map +1 -1
- package/package.json +76 -68
- package/src/AiError.ts +739 -9
- package/src/Chat.ts +546 -0
- package/src/EmbeddingModel.ts +311 -0
- package/src/IdGenerator.ts +320 -0
- package/src/LanguageModel.ts +1074 -0
- package/src/McpServer.ts +337 -194
- package/src/Model.ts +155 -0
- package/src/Prompt.ts +1616 -0
- package/src/Response.ts +2131 -0
- package/src/Telemetry.ts +655 -0
- package/src/Tokenizer.ts +145 -24
- package/src/Tool.ts +1267 -0
- package/src/Toolkit.ts +516 -0
- package/src/index.ts +499 -13
- package/AiChat/package.json +0 -6
- package/AiEmbeddingModel/package.json +0 -6
- package/AiInput/package.json +0 -6
- package/AiLanguageModel/package.json +0 -6
- package/AiModel/package.json +0 -6
- package/AiResponse/package.json +0 -6
- package/AiTelemetry/package.json +0 -6
- package/AiTool/package.json +0 -6
- package/AiToolkit/package.json +0 -6
- package/dist/cjs/AiChat.js +0 -122
- package/dist/cjs/AiChat.js.map +0 -1
- package/dist/cjs/AiEmbeddingModel.js +0 -109
- package/dist/cjs/AiEmbeddingModel.js.map +0 -1
- package/dist/cjs/AiInput.js +0 -458
- package/dist/cjs/AiInput.js.map +0 -1
- package/dist/cjs/AiLanguageModel.js +0 -351
- package/dist/cjs/AiLanguageModel.js.map +0 -1
- package/dist/cjs/AiModel.js +0 -37
- package/dist/cjs/AiModel.js.map +0 -1
- package/dist/cjs/AiResponse.js +0 -681
- package/dist/cjs/AiResponse.js.map +0 -1
- package/dist/cjs/AiTelemetry.js +0 -58
- package/dist/cjs/AiTelemetry.js.map +0 -1
- package/dist/cjs/AiTool.js +0 -150
- package/dist/cjs/AiTool.js.map +0 -1
- package/dist/cjs/AiToolkit.js +0 -157
- package/dist/cjs/AiToolkit.js.map +0 -1
- package/dist/cjs/internal/common.js +0 -21
- package/dist/cjs/internal/common.js.map +0 -1
- package/dist/dts/AiChat.d.ts +0 -101
- package/dist/dts/AiChat.d.ts.map +0 -1
- package/dist/dts/AiEmbeddingModel.d.ts +0 -65
- package/dist/dts/AiEmbeddingModel.d.ts.map +0 -1
- package/dist/dts/AiInput.d.ts +0 -590
- package/dist/dts/AiInput.d.ts.map +0 -1
- package/dist/dts/AiLanguageModel.d.ts +0 -302
- package/dist/dts/AiLanguageModel.d.ts.map +0 -1
- package/dist/dts/AiModel.d.ts +0 -25
- package/dist/dts/AiModel.d.ts.map +0 -1
- package/dist/dts/AiResponse.d.ts +0 -863
- package/dist/dts/AiResponse.d.ts.map +0 -1
- package/dist/dts/AiTelemetry.d.ts +0 -242
- package/dist/dts/AiTelemetry.d.ts.map +0 -1
- package/dist/dts/AiTool.d.ts +0 -334
- package/dist/dts/AiTool.d.ts.map +0 -1
- package/dist/dts/AiToolkit.d.ts +0 -96
- package/dist/dts/AiToolkit.d.ts.map +0 -1
- package/dist/dts/internal/common.d.ts +0 -2
- package/dist/dts/internal/common.d.ts.map +0 -1
- package/dist/esm/AiChat.js +0 -111
- package/dist/esm/AiChat.js.map +0 -1
- package/dist/esm/AiEmbeddingModel.js +0 -98
- package/dist/esm/AiEmbeddingModel.js.map +0 -1
- package/dist/esm/AiInput.js +0 -433
- package/dist/esm/AiInput.js.map +0 -1
- package/dist/esm/AiLanguageModel.js +0 -340
- package/dist/esm/AiLanguageModel.js.map +0 -1
- package/dist/esm/AiModel.js +0 -29
- package/dist/esm/AiModel.js.map +0 -1
- package/dist/esm/AiResponse.js +0 -657
- package/dist/esm/AiResponse.js.map +0 -1
- package/dist/esm/AiTelemetry.js +0 -48
- package/dist/esm/AiTelemetry.js.map +0 -1
- package/dist/esm/AiTool.js +0 -134
- package/dist/esm/AiTool.js.map +0 -1
- package/dist/esm/AiToolkit.js +0 -147
- package/dist/esm/AiToolkit.js.map +0 -1
- package/dist/esm/internal/common.js +0 -14
- package/dist/esm/internal/common.js.map +0 -1
- package/src/AiChat.ts +0 -251
- package/src/AiEmbeddingModel.ts +0 -169
- package/src/AiInput.ts +0 -602
- package/src/AiLanguageModel.ts +0 -685
- package/src/AiModel.ts +0 -53
- package/src/AiResponse.ts +0 -986
- package/src/AiTelemetry.ts +0 -333
- package/src/AiTool.ts +0 -579
- package/src/AiToolkit.ts +0 -265
- package/src/internal/common.ts +0 -12
package/dist/esm/AiTelemetry.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 1.0.0
|
|
3
|
-
*/
|
|
4
|
-
import * as Context from "effect/Context";
|
|
5
|
-
import { dual } from "effect/Function";
|
|
6
|
-
import * as Predicate from "effect/Predicate";
|
|
7
|
-
import * as String from "effect/String";
|
|
8
|
-
/**
|
|
9
|
-
* @since 1.0.0
|
|
10
|
-
* @category Utilities
|
|
11
|
-
*/
|
|
12
|
-
export const addSpanAttributes = (keyPrefix, transformKey) => (span, attributes) => {
|
|
13
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
14
|
-
if (Predicate.isNotNullable(value)) {
|
|
15
|
-
span.attribute(`${keyPrefix}.${transformKey(key)}`, value);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const addSpanBaseAttributes = /*#__PURE__*/addSpanAttributes("gen_ai", String.camelToSnake);
|
|
20
|
-
const addSpanOperationAttributes = /*#__PURE__*/addSpanAttributes("gen_ai.operation", String.camelToSnake);
|
|
21
|
-
const addSpanRequestAttributes = /*#__PURE__*/addSpanAttributes("gen_ai.request", String.camelToSnake);
|
|
22
|
-
const addSpanResponseAttributes = /*#__PURE__*/addSpanAttributes("gen_ai.response", String.camelToSnake);
|
|
23
|
-
const addSpanTokenAttributes = /*#__PURE__*/addSpanAttributes("gen_ai.token", String.camelToSnake);
|
|
24
|
-
const addSpanUsageAttributes = /*#__PURE__*/addSpanAttributes("gen_ai.usage", String.camelToSnake);
|
|
25
|
-
/**
|
|
26
|
-
* Applies the specified GenAI telemetry attributes to the provided `Span`.
|
|
27
|
-
*
|
|
28
|
-
* **NOTE**: This method will mutate the `Span` **in-place**.
|
|
29
|
-
*
|
|
30
|
-
* @since 1.0.0
|
|
31
|
-
* @since Utilities
|
|
32
|
-
*/
|
|
33
|
-
export const addGenAIAnnotations = /*#__PURE__*/dual(2, (span, options) => {
|
|
34
|
-
addSpanBaseAttributes(span, {
|
|
35
|
-
system: options.system
|
|
36
|
-
});
|
|
37
|
-
if (Predicate.isNotNullable(options.operation)) addSpanOperationAttributes(span, options.operation);
|
|
38
|
-
if (Predicate.isNotNullable(options.request)) addSpanRequestAttributes(span, options.request);
|
|
39
|
-
if (Predicate.isNotNullable(options.response)) addSpanResponseAttributes(span, options.response);
|
|
40
|
-
if (Predicate.isNotNullable(options.token)) addSpanTokenAttributes(span, options.token);
|
|
41
|
-
if (Predicate.isNotNullable(options.usage)) addSpanUsageAttributes(span, options.usage);
|
|
42
|
-
});
|
|
43
|
-
/**
|
|
44
|
-
* @since 1.0.0
|
|
45
|
-
* @category Context
|
|
46
|
-
*/
|
|
47
|
-
export class CurrentSpanTransformer extends /*#__PURE__*/Context.Tag("@effect/ai/AiTelemetry/CurrentSpanTransformer")() {}
|
|
48
|
-
//# sourceMappingURL=AiTelemetry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AiTelemetry.js","names":["Context","dual","Predicate","String","addSpanAttributes","keyPrefix","transformKey","span","attributes","key","value","Object","entries","isNotNullable","attribute","addSpanBaseAttributes","camelToSnake","addSpanOperationAttributes","addSpanRequestAttributes","addSpanResponseAttributes","addSpanTokenAttributes","addSpanUsageAttributes","addGenAIAnnotations","options","system","operation","request","response","token","usage","CurrentSpanTransformer","Tag"],"sources":["../../src/AiTelemetry.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,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AC;EACvD,IAAItB,SAAS,CAACW,aAAa,CAACU,OAAO,CAACE,SAAS,CAAC,EAAER,0BAA0B,CAACV,IAAI,EAAEgB,OAAO,CAACE,SAAS,CAAC;EACnG,IAAIvB,SAAS,CAACW,aAAa,CAACU,OAAO,CAACG,OAAO,CAAC,EAAER,wBAAwB,CAACX,IAAI,EAAEgB,OAAO,CAACG,OAAO,CAAC;EAC7F,IAAIxB,SAAS,CAACW,aAAa,CAACU,OAAO,CAACI,QAAQ,CAAC,EAAER,yBAAyB,CAACZ,IAAI,EAAEgB,OAAO,CAACI,QAAQ,CAAC;EAChG,IAAIzB,SAAS,CAACW,aAAa,CAACU,OAAO,CAACK,KAAK,CAAC,EAAER,sBAAsB,CAACb,IAAI,EAAEgB,OAAO,CAACK,KAAK,CAAC;EACvF,IAAI1B,SAAS,CAACW,aAAa,CAACU,OAAO,CAACM,KAAK,CAAC,EAAER,sBAAsB,CAACd,IAAI,EAAEgB,OAAO,CAACM,KAAK,CAAC;AACzF,CAAC,CAAC;AAcF;;;;AAIA,OAAM,MAAOC,sBAAuB,sBAAQ9B,OAAO,CAAC+B,GAAG,CAAC,+CAA+C,CAAC,EAGrG","ignoreList":[]}
|
package/dist/esm/AiTool.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 1.0.0
|
|
3
|
-
*/
|
|
4
|
-
import * as Context_ from "effect/Context";
|
|
5
|
-
import { constFalse, constTrue } from "effect/Function";
|
|
6
|
-
import * as Option from "effect/Option";
|
|
7
|
-
import { pipeArguments } from "effect/Pipeable";
|
|
8
|
-
import * as Predicate from "effect/Predicate";
|
|
9
|
-
import * as Schema from "effect/Schema";
|
|
10
|
-
import * as AST from "effect/SchemaAST";
|
|
11
|
-
/**
|
|
12
|
-
* @since 1.0.0
|
|
13
|
-
* @category Type Ids
|
|
14
|
-
*/
|
|
15
|
-
export const TypeId = /*#__PURE__*/Symbol.for("@effect/ai/AiTool");
|
|
16
|
-
/**
|
|
17
|
-
* @since 1.0.0
|
|
18
|
-
* @category Guards
|
|
19
|
-
*/
|
|
20
|
-
export const isAiTool = u => Predicate.hasProperty(u, TypeId);
|
|
21
|
-
const Proto = {
|
|
22
|
-
[TypeId]: TypeId,
|
|
23
|
-
pipe() {
|
|
24
|
-
return pipeArguments(this, arguments);
|
|
25
|
-
},
|
|
26
|
-
addRequirement() {
|
|
27
|
-
return makeProto({
|
|
28
|
-
...this
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
setSuccess(successSchema) {
|
|
32
|
-
return makeProto({
|
|
33
|
-
...this,
|
|
34
|
-
successSchema
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
setFailure(failureSchema) {
|
|
38
|
-
return makeProto({
|
|
39
|
-
...this,
|
|
40
|
-
failureSchema
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
setParameters(parametersSchema) {
|
|
44
|
-
return makeProto({
|
|
45
|
-
...this,
|
|
46
|
-
parametersSchema: Schema.isSchema(parametersSchema) ? parametersSchema : Schema.Struct(parametersSchema)
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
annotate(tag, value) {
|
|
50
|
-
return makeProto({
|
|
51
|
-
...this,
|
|
52
|
-
annotations: Context_.add(this.annotations, tag, value)
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
annotateContext(context) {
|
|
56
|
-
return makeProto({
|
|
57
|
-
...this,
|
|
58
|
-
annotations: Context_.merge(this.annotations, context)
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const makeProto = options => {
|
|
63
|
-
const self = Object.assign(Object.create(Proto), options);
|
|
64
|
-
self.key = `@effect/ai/AiTool/${options.name}`;
|
|
65
|
-
return self;
|
|
66
|
-
};
|
|
67
|
-
const constEmptyStruct = /*#__PURE__*/Schema.Struct({});
|
|
68
|
-
/**
|
|
69
|
-
* Constructs an `AiTool` from a name and, optionally, a specification for the
|
|
70
|
-
* tool call's protocol.
|
|
71
|
-
*
|
|
72
|
-
* @since 1.0.0
|
|
73
|
-
* @category constructors
|
|
74
|
-
*/
|
|
75
|
-
export const make = (name, options) => {
|
|
76
|
-
const successSchema = options?.success ?? Schema.Void;
|
|
77
|
-
const failureSchema = options?.failure ?? Schema.Never;
|
|
78
|
-
return makeProto({
|
|
79
|
-
name,
|
|
80
|
-
description: options?.description,
|
|
81
|
-
parametersSchema: options?.parameters ? Schema.Struct(options?.parameters) : constEmptyStruct,
|
|
82
|
-
successSchema,
|
|
83
|
-
failureSchema,
|
|
84
|
-
annotations: Context_.empty()
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Constructs a new `AiTool` from a `Schema.TaggedRequest`.
|
|
89
|
-
*
|
|
90
|
-
* @since 1.0.0
|
|
91
|
-
* @category constructors
|
|
92
|
-
*/
|
|
93
|
-
export const fromTaggedRequest = schema => makeProto({
|
|
94
|
-
name: schema._tag,
|
|
95
|
-
description: Option.getOrUndefined(AST.getDescriptionAnnotation(schema.ast.to)),
|
|
96
|
-
parametersSchema: schema,
|
|
97
|
-
successSchema: schema.success,
|
|
98
|
-
failureSchema: schema.failure,
|
|
99
|
-
annotations: Context_.empty()
|
|
100
|
-
});
|
|
101
|
-
/**
|
|
102
|
-
* @since 1.0.0
|
|
103
|
-
* @category Annotations
|
|
104
|
-
*/
|
|
105
|
-
export class Title extends /*#__PURE__*/Context_.Tag("@effect/ai/AiTool/Title")() {}
|
|
106
|
-
/**
|
|
107
|
-
* @since 1.0.0
|
|
108
|
-
* @category Annotations
|
|
109
|
-
*/
|
|
110
|
-
export class Readonly extends /*#__PURE__*/Context_.Reference()("@effect/ai/AiTool/Readonly", {
|
|
111
|
-
defaultValue: constFalse
|
|
112
|
-
}) {}
|
|
113
|
-
/**
|
|
114
|
-
* @since 1.0.0
|
|
115
|
-
* @category Annotations
|
|
116
|
-
*/
|
|
117
|
-
export class Destructive extends /*#__PURE__*/Context_.Reference()("@effect/ai/AiTool/Destructive", {
|
|
118
|
-
defaultValue: constTrue
|
|
119
|
-
}) {}
|
|
120
|
-
/**
|
|
121
|
-
* @since 1.0.0
|
|
122
|
-
* @category Annotations
|
|
123
|
-
*/
|
|
124
|
-
export class Idempotent extends /*#__PURE__*/Context_.Reference()("@effect/ai/AiTool/Idempotent", {
|
|
125
|
-
defaultValue: constFalse
|
|
126
|
-
}) {}
|
|
127
|
-
/**
|
|
128
|
-
* @since 1.0.0
|
|
129
|
-
* @category Annotations
|
|
130
|
-
*/
|
|
131
|
-
export class OpenWorld extends /*#__PURE__*/Context_.Reference()("@effect/ai/AiTool/OpenWorld", {
|
|
132
|
-
defaultValue: constTrue
|
|
133
|
-
}) {}
|
|
134
|
-
//# sourceMappingURL=AiTool.js.map
|
package/dist/esm/AiTool.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AiTool.js","names":["Context_","constFalse","constTrue","Option","pipeArguments","Predicate","Schema","AST","TypeId","Symbol","for","isAiTool","u","hasProperty","Proto","pipe","arguments","addRequirement","makeProto","setSuccess","successSchema","setFailure","failureSchema","setParameters","parametersSchema","isSchema","Struct","annotate","tag","value","annotations","add","annotateContext","context","merge","options","self","Object","assign","create","key","name","constEmptyStruct","make","success","Void","failure","Never","description","parameters","empty","fromTaggedRequest","schema","_tag","getOrUndefined","getDescriptionAnnotation","ast","to","Title","Tag","Readonly","Reference","defaultValue","Destructive","Idempotent","OpenWorld"],"sources":["../../src/AiTool.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,QAAQ,MAAM,gBAAgB;AAE1C,SAASC,UAAU,EAAEC,SAAS,QAAQ,iBAAiB;AACvD,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAAwBC,aAAa,QAAQ,iBAAiB;AAC9D,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,GAAG,MAAM,kBAAkB;A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;AAIA,OAAM,MAAOQ,KAAM,sBAAQ1D,QAAQ,CAAC2D,GAAG,CAAC,yBAAyB,CAAC,EAAiB;AAEnF;;;;AAIA,OAAM,MAAOC,QAAS,sBAAQ5D,QAAQ,CAAC6D,SAAS,EAAY,CAAC,4BAA4B,EAAE;EACzFC,YAAY,EAAE7D;CACf,CAAC;AAEF;;;;AAIA,OAAM,MAAO8D,WAAY,sBAAQ/D,QAAQ,CAAC6D,SAAS,EAAe,CAAC,+BAA+B,EAAE;EAClGC,YAAY,EAAE5D;CACf,CAAC;AAEF;;;;AAIA,OAAM,MAAO8D,UAAW,sBAAQhE,QAAQ,CAAC6D,SAAS,EAAc,CAAC,8BAA8B,EAAE;EAC/FC,YAAY,EAAE7D;CACf,CAAC;AAEF;;;;AAIA,OAAM,MAAOgE,SAAU,sBAAQjE,QAAQ,CAAC6D,SAAS,EAAa,CAAC,6BAA6B,EAAE;EAC5FC,YAAY,EAAE5D;CACf,CAAC","ignoreList":[]}
|
package/dist/esm/AiToolkit.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 1.0.0
|
|
3
|
-
*/
|
|
4
|
-
import * as Context from "effect/Context";
|
|
5
|
-
import * as Effect from "effect/Effect";
|
|
6
|
-
import { CommitPrototype } from "effect/Effectable";
|
|
7
|
-
import { identity } from "effect/Function";
|
|
8
|
-
import { BaseProto as InspectableProto } from "effect/Inspectable";
|
|
9
|
-
import * as Layer from "effect/Layer";
|
|
10
|
-
import { pipeArguments } from "effect/Pipeable";
|
|
11
|
-
import * as Predicate from "effect/Predicate";
|
|
12
|
-
import * as Schema from "effect/Schema";
|
|
13
|
-
import { AiError } from "./AiError.js";
|
|
14
|
-
import * as AiTool from "./AiTool.js";
|
|
15
|
-
/**
|
|
16
|
-
* @since 1.0.0
|
|
17
|
-
* @category Type Ids
|
|
18
|
-
*/
|
|
19
|
-
export const TypeId = /*#__PURE__*/Symbol.for("@effect/ai/AiToolkit");
|
|
20
|
-
const Proto = {
|
|
21
|
-
...CommitPrototype,
|
|
22
|
-
...InspectableProto,
|
|
23
|
-
[TypeId]: TypeId,
|
|
24
|
-
toContext(build) {
|
|
25
|
-
return Effect.gen(this, function* () {
|
|
26
|
-
const context = yield* Effect.context();
|
|
27
|
-
const handlers = Effect.isEffect(build) ? yield* build : build;
|
|
28
|
-
const contextMap = new Map();
|
|
29
|
-
for (const [name, handler] of Object.entries(handlers)) {
|
|
30
|
-
const tool = this.tools[name];
|
|
31
|
-
contextMap.set(tool.key, {
|
|
32
|
-
handler,
|
|
33
|
-
context
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return Context.unsafeMake(contextMap);
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
toLayer(build) {
|
|
40
|
-
return Layer.scopedContext(this.toContext(build));
|
|
41
|
-
},
|
|
42
|
-
of: identity,
|
|
43
|
-
commit() {
|
|
44
|
-
return Effect.gen(this, function* () {
|
|
45
|
-
const context = yield* Effect.context();
|
|
46
|
-
const tools = this.tools;
|
|
47
|
-
const schemasCache = new WeakMap();
|
|
48
|
-
const getSchemas = tool => {
|
|
49
|
-
let schemas = schemasCache.get(tool);
|
|
50
|
-
if (Predicate.isUndefined(schemas)) {
|
|
51
|
-
const handler = context.unsafeMap.get(tool.key);
|
|
52
|
-
const encodeSuccess = Schema.encodeUnknown(tool.successSchema);
|
|
53
|
-
const decodeFailure = Schema.decodeUnknown(tool.failureSchema);
|
|
54
|
-
const decodeParameters = Schema.decodeUnknown(tool.parametersSchema);
|
|
55
|
-
schemas = {
|
|
56
|
-
context: handler.context,
|
|
57
|
-
handler: handler.handler,
|
|
58
|
-
encodeSuccess,
|
|
59
|
-
decodeFailure,
|
|
60
|
-
decodeParameters
|
|
61
|
-
};
|
|
62
|
-
schemasCache.set(tool, schemas);
|
|
63
|
-
}
|
|
64
|
-
return schemas;
|
|
65
|
-
};
|
|
66
|
-
const handle = Effect.fn("AiToolkit.handler", {
|
|
67
|
-
captureStackTrace: false
|
|
68
|
-
})(function* (toolName, toolParams) {
|
|
69
|
-
yield* Effect.annotateCurrentSpan({
|
|
70
|
-
tool: toolName,
|
|
71
|
-
parameters: toolParams
|
|
72
|
-
});
|
|
73
|
-
const tool = tools[toolName];
|
|
74
|
-
const schemas = getSchemas(tool);
|
|
75
|
-
const decodedParams = yield* Effect.mapError(schemas.decodeParameters(toolParams), cause => new AiError({
|
|
76
|
-
module: "AiToolkit",
|
|
77
|
-
method: `${toolName}.handle`,
|
|
78
|
-
description: `Failed to decode tool call parameters for tool '${toolName}' from '${toolParams}'`,
|
|
79
|
-
cause
|
|
80
|
-
}));
|
|
81
|
-
const result = yield* schemas.handler(decodedParams).pipe(Effect.mapInputContext(input => Context.merge(schemas.context, input)), Effect.catchAll(error => schemas.decodeFailure(error).pipe(Effect.mapError(cause => new AiError({
|
|
82
|
-
module: "AiToolkit",
|
|
83
|
-
method: `${toolName}.handle`,
|
|
84
|
-
description: `Failed to decode tool call failure for tool '${toolName}'`,
|
|
85
|
-
cause
|
|
86
|
-
})), Effect.flatMap(Effect.fail))));
|
|
87
|
-
const encodedResult = yield* Effect.mapError(schemas.encodeSuccess(result), cause => new AiError({
|
|
88
|
-
module: "AiToolkit",
|
|
89
|
-
method: `${toolName}.handle`,
|
|
90
|
-
description: `Failed to encode tool call result for tool '${toolName}'`,
|
|
91
|
-
cause
|
|
92
|
-
}));
|
|
93
|
-
return {
|
|
94
|
-
result,
|
|
95
|
-
encodedResult
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
return {
|
|
99
|
-
tools: Array.from(Object.values(tools)),
|
|
100
|
-
handle
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
toJSON() {
|
|
105
|
-
return {
|
|
106
|
-
_id: "@effect/ai/AiToolkit",
|
|
107
|
-
tools: Array.from(Object.values(this.tools)).map(tool => tool.name)
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
pipe() {
|
|
111
|
-
return pipeArguments(this, arguments);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const makeProto = tools => Object.assign(function () {}, Proto, {
|
|
115
|
-
tools
|
|
116
|
-
});
|
|
117
|
-
const resolveInput = (...tools) => {
|
|
118
|
-
const output = {};
|
|
119
|
-
for (const tool of tools) {
|
|
120
|
-
const value = Schema.isSchema(tool) ? AiTool.fromTaggedRequest(tool) : tool;
|
|
121
|
-
output[tool.name] = value;
|
|
122
|
-
}
|
|
123
|
-
return output;
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Constructs a new `AiToolkit` from the specified tools.
|
|
127
|
-
*
|
|
128
|
-
* @since 1.0.0
|
|
129
|
-
* @category Constructors
|
|
130
|
-
*/
|
|
131
|
-
export const make = (...tools) => makeProto(resolveInput(...tools));
|
|
132
|
-
/**
|
|
133
|
-
* Merges this toolkit with one or more other toolkits.
|
|
134
|
-
*
|
|
135
|
-
* @since 1.0.0
|
|
136
|
-
* @category Merging
|
|
137
|
-
*/
|
|
138
|
-
export const merge = (...toolkits) => {
|
|
139
|
-
const tools = {};
|
|
140
|
-
for (const toolkit of toolkits) {
|
|
141
|
-
for (const [name, tool] of Object.entries(toolkit.tools)) {
|
|
142
|
-
tools[name] = tool;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return makeProto(tools);
|
|
146
|
-
};
|
|
147
|
-
//# sourceMappingURL=AiToolkit.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AiToolkit.js","names":["Context","Effect","CommitPrototype","identity","BaseProto","InspectableProto","Layer","pipeArguments","Predicate","Schema","AiError","AiTool","TypeId","Symbol","for","Proto","toContext","build","gen","context","handlers","isEffect","contextMap","Map","name","handler","Object","entries","tool","tools","set","key","unsafeMake","toLayer","scopedContext","of","commit","schemasCache","WeakMap","getSchemas","schemas","get","isUndefined","unsafeMap","encodeSuccess","encodeUnknown","successSchema","decodeFailure","decodeUnknown","failureSchema","decodeParameters","parametersSchema","handle","fn","captureStackTrace","toolName","toolParams","annotateCurrentSpan","parameters","decodedParams","mapError","cause","module","method","description","result","pipe","mapInputContext","input","merge","catchAll","error","flatMap","fail","encodedResult","Array","from","values","toJSON","_id","map","arguments","makeProto","assign","resolveInput","output","value","isSchema","fromTaggedRequest","make","toolkits","toolkit"],"sources":["../../src/AiToolkit.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,QAAQ,QAAQ,iBAAiB;AAE1C,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,oBAAoB;AAClE,OAAO,KAAKC,KAAK,MAAM,cAAc;AAGrC,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,SAASC,OAAO,QAAQ,cAAc;AACtC,OAAO,KAAKC,MAAM,MAAM,aAAa;AAErC;;;;AAIA,OAAO,MAAMC,MAAM,gBAAkBC,MAAM,CAACC,GAAG,CAAC,sBAAsB,CAAC;AAqFvE,MAAMC,KAAK,GAAG;EACZ,GAAGb,eAAe;EAClB,GAAGG,gBAAgB;EACnB,CAACO,MAAM,GAAGA,MAAM;EAChBI,SAASA,CAAuBC,KAA0D;IACxF,OAAOhB,MAAM,CAACiB,GAAG,CAAC,IAAI,EAAE,aAAS;MAC/B,MAAMC,OAAO,GAAG,OAAOlB,MAAM,CAACkB,OAAO,EAAS;MAC9C,MAAMC,QAAQ,GAAGnB,MAAM,CAACoB,QAAQ,CAACJ,KAAK,CAAC,GAAG,OAAOA,KAAK,GAAGA,KAAK;MAC9D,MAAMK,UAAU,GAAG,IAAIC,GAAG,EAAmB;MAC7C,KAAK,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACP,QAA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IAAI,CAAC,GAAGjB,MAAM,CAAC6E,iBAAiB,CAAC5D,IAAW,CAAC,GAAGA,IAAY;IAC3FyD,MAAM,CAACzD,IAAI,CAACJ,IAAI,CAAC,GAAG8D,KAAK;EAC3B;EACA,OAAOD,MAAM;AACf,CAAC;AAED;;;;;;AAMA,OAAO,MAAMI,IAAI,GAAGA,CAClB,GAAG5D,KAAY,KACcqD,SAAS,CAACE,YAAY,CAAC,GAAGvD,KAAK,CAAC,CAAC;AAEhE;;;;;;AAMA,OAAO,MAAMwC,KAAK,GAAGA,CACnB,GAAGqB,QAAkB,KACiB;EACtC,MAAM7D,KAAK,GAAG,EAAyB;EACvC,KAAK,MAAM8D,OAAO,IAAID,QAAQ,EAAE;IAC9B,KAAK,MAAM,CAAClE,IAAI,EAAEI,IAAI,CAAC,IAAIF,MAAM,CAACC,OAAO,CAACgE,OAAO,CAAC9D,KAAK,CAAC,EAAE;MACxDA,KAAK,CAACL,IAAI,CAAC,GAAGI,IAAI;IACpB;EACF;EACA,OAAOsD,SAAS,CAACrD,KAAK,CAAQ;AAChC,CAAC","ignoreList":[]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as Schema from "effect/Schema";
|
|
2
|
-
/** @internal */
|
|
3
|
-
export const ToolCallId = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.brand("@effect/ai/ToolCallId"));
|
|
4
|
-
/** @internal */
|
|
5
|
-
export const ProviderMetadata = /*#__PURE__*/Schema.Record({
|
|
6
|
-
key: Schema.String,
|
|
7
|
-
value: Schema.Record({
|
|
8
|
-
key: Schema.String,
|
|
9
|
-
value: Schema.Unknown
|
|
10
|
-
})
|
|
11
|
-
}).annotations({
|
|
12
|
-
identifier: "@effect/ai/ProviderMetadata"
|
|
13
|
-
});
|
|
14
|
-
//# sourceMappingURL=common.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","names":["Schema","ToolCallId","String","pipe","brand","ProviderMetadata","Record","key","value","Unknown","annotations","identifier"],"sources":["../../../src/internal/common.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,eAAe;AAEvC;AACA,OAAO,MAAMC,UAAU,gBAAGD,MAAM,CAACE,MAAM,CAACC,IAAI,cAC1CH,MAAM,CAACI,KAAK,CAAC,uBAAuB,CAAC,CACtC;AAED;AACA,OAAO,MAAMC,gBAAgB,gBAAGL,MAAM,CAACM,MAAM,CAAC;EAC5CC,GAAG,EAAEP,MAAM,CAACE,MAAM;EAClBM,KAAK,EAAER,MAAM,CAACM,MAAM,CAAC;IAAEC,GAAG,EAAEP,MAAM,CAACE,MAAM;IAAEM,KAAK,EAAER,MAAM,CAACS;EAAO,CAAE;CACnE,CAAC,CAACC,WAAW,CAAC;EAAEC,UAAU,EAAE;AAA6B,CAAE,CAAC","ignoreList":[]}
|
package/src/AiChat.ts
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 1.0.0
|
|
3
|
-
*/
|
|
4
|
-
import * as Channel from "effect/Channel"
|
|
5
|
-
import * as Context from "effect/Context"
|
|
6
|
-
import * as Effect from "effect/Effect"
|
|
7
|
-
import type { ParseError } from "effect/ParseResult"
|
|
8
|
-
import * as Ref from "effect/Ref"
|
|
9
|
-
import * as Schema from "effect/Schema"
|
|
10
|
-
import * as Stream from "effect/Stream"
|
|
11
|
-
import type { NoExcessProperties } from "effect/Types"
|
|
12
|
-
import type { AiError } from "./AiError.js"
|
|
13
|
-
import * as AiInput from "./AiInput.js"
|
|
14
|
-
import * as AiLanguageModel from "./AiLanguageModel.js"
|
|
15
|
-
import * as AiResponse from "./AiResponse.js"
|
|
16
|
-
import type * as AiTool from "./AiTool.js"
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @since 1.0.0
|
|
20
|
-
* @category Context
|
|
21
|
-
*/
|
|
22
|
-
export class AiChat extends Context.Tag("@effect/ai/AiChat")<
|
|
23
|
-
AiChat,
|
|
24
|
-
AiChat.Service
|
|
25
|
-
>() {}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @since 1.0.0
|
|
29
|
-
* @category Models
|
|
30
|
-
*/
|
|
31
|
-
export declare namespace AiChat {
|
|
32
|
-
/**
|
|
33
|
-
* @since 1.0.0
|
|
34
|
-
* @category Models
|
|
35
|
-
*/
|
|
36
|
-
export interface Service {
|
|
37
|
-
/**
|
|
38
|
-
* The chat history.
|
|
39
|
-
*/
|
|
40
|
-
readonly history: Ref.Ref<AiInput.AiInput>
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Exports the chat into a structured format.
|
|
44
|
-
*/
|
|
45
|
-
readonly export: Effect.Effect<unknown>
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Exports the chat as a JSON string.
|
|
49
|
-
*/
|
|
50
|
-
readonly exportJson: Effect.Effect<string>
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Generate text using a large language model for the specified `prompt`.
|
|
54
|
-
*
|
|
55
|
-
* If a `toolkit` is specified, the large language model will additionally
|
|
56
|
-
* be able to perform tool calls to augment its response.
|
|
57
|
-
*
|
|
58
|
-
* Both input and output messages will be added to the chat history.
|
|
59
|
-
*/
|
|
60
|
-
readonly generateText: <
|
|
61
|
-
Tools extends AiTool.Any,
|
|
62
|
-
Options extends NoExcessProperties<AiLanguageModel.GenerateTextOptions<any>, Options>
|
|
63
|
-
>(
|
|
64
|
-
options: Options & Omit<AiLanguageModel.GenerateTextOptions<Tools>, "system">
|
|
65
|
-
) => Effect.Effect<
|
|
66
|
-
AiLanguageModel.ExtractSuccess<Options>,
|
|
67
|
-
AiLanguageModel.ExtractError<Options>,
|
|
68
|
-
AiLanguageModel.ExtractContext<Options>
|
|
69
|
-
>
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Generate text using a large language model for the specified `prompt`,
|
|
73
|
-
* streaming output from the model as soon as it is available.
|
|
74
|
-
*
|
|
75
|
-
* If a `toolkit` is specified, the large language model will additionally
|
|
76
|
-
* be able to perform tool calls to augment its response.
|
|
77
|
-
*
|
|
78
|
-
* Both input and output messages will be added to the chat history.
|
|
79
|
-
*/
|
|
80
|
-
readonly streamText: <
|
|
81
|
-
Tools extends AiTool.Any,
|
|
82
|
-
Options extends NoExcessProperties<AiLanguageModel.GenerateTextOptions<any>, Options>
|
|
83
|
-
>(
|
|
84
|
-
options: Options & Omit<AiLanguageModel.GenerateTextOptions<Tools>, "system">
|
|
85
|
-
) => Stream.Stream<
|
|
86
|
-
AiLanguageModel.ExtractSuccess<Options>,
|
|
87
|
-
AiLanguageModel.ExtractError<Options>,
|
|
88
|
-
AiLanguageModel.ExtractContext<Options>
|
|
89
|
-
>
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Generate a structured object for the specified prompt and schema using a
|
|
93
|
-
* large language model.
|
|
94
|
-
*
|
|
95
|
-
* When using a `Schema` that does not have an `identifier` or `_tag`
|
|
96
|
-
* property, you must specify a `toolCallId` to properly associate the
|
|
97
|
-
* output of the model.
|
|
98
|
-
*
|
|
99
|
-
* Both input and output messages will be added to the chat history.
|
|
100
|
-
*/
|
|
101
|
-
readonly generateObject: <A, I extends Record<string, unknown>, R>(
|
|
102
|
-
options: Omit<AiLanguageModel.GenerateObjectOptions<A, I, R>, "system">
|
|
103
|
-
) => Effect.Effect<AiResponse.WithStructuredOutput<A>, AiError, R>
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @since 1.0.0
|
|
109
|
-
* @category Constructors
|
|
110
|
-
*/
|
|
111
|
-
export const fromPrompt = Effect.fnUntraced(function*(options: {
|
|
112
|
-
readonly prompt: AiInput.Raw
|
|
113
|
-
readonly system?: string
|
|
114
|
-
}) {
|
|
115
|
-
const languageModel = yield* AiLanguageModel.AiLanguageModel
|
|
116
|
-
const context = yield* Effect.context<never>()
|
|
117
|
-
const provideContext = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
118
|
-
Effect.mapInputContext(effect, (input) => Context.merge(context, input))
|
|
119
|
-
const provideContextStream = <A, E, R>(stream: Stream.Stream<A, E, R>): Stream.Stream<A, E, R> =>
|
|
120
|
-
Stream.mapInputContext(stream, (input) => Context.merge(context, input))
|
|
121
|
-
const history = yield* Ref.make<AiInput.AiInput>(AiInput.make(options.prompt))
|
|
122
|
-
const semaphore = yield* Effect.makeSemaphore(1)
|
|
123
|
-
const system = options.system
|
|
124
|
-
|
|
125
|
-
return AiChat.of({
|
|
126
|
-
history,
|
|
127
|
-
export: Ref.get(history).pipe(
|
|
128
|
-
Effect.flatMap(Schema.encode(AiInput.AiInput)),
|
|
129
|
-
Effect.orDie
|
|
130
|
-
),
|
|
131
|
-
exportJson: Ref.get(history).pipe(
|
|
132
|
-
Effect.flatMap(Schema.encode(AiInput.FromJson)),
|
|
133
|
-
Effect.orDie
|
|
134
|
-
),
|
|
135
|
-
generateText(options) {
|
|
136
|
-
const newInput = AiInput.make(options.prompt)
|
|
137
|
-
return Ref.get(history).pipe(
|
|
138
|
-
Effect.flatMap((oldInput) => {
|
|
139
|
-
const input = AiInput.concat(oldInput, newInput)
|
|
140
|
-
return languageModel.generateText({
|
|
141
|
-
...options,
|
|
142
|
-
system,
|
|
143
|
-
prompt: input
|
|
144
|
-
}).pipe(
|
|
145
|
-
Effect.tap((response) => {
|
|
146
|
-
const modelInput = AiInput.make(response)
|
|
147
|
-
return Ref.set(history, AiInput.concat(input, modelInput))
|
|
148
|
-
}),
|
|
149
|
-
provideContext
|
|
150
|
-
)
|
|
151
|
-
}),
|
|
152
|
-
semaphore.withPermits(1),
|
|
153
|
-
Effect.withSpan("AiChat.generateText", { captureStackTrace: false })
|
|
154
|
-
)
|
|
155
|
-
},
|
|
156
|
-
streamText(options) {
|
|
157
|
-
return Stream.suspend(() => {
|
|
158
|
-
let combined = AiResponse.empty
|
|
159
|
-
return Stream.fromChannel(Channel.acquireUseRelease(
|
|
160
|
-
semaphore.take(1).pipe(
|
|
161
|
-
Effect.zipRight(Ref.get(history)),
|
|
162
|
-
Effect.map((history) => AiInput.concat(history, AiInput.make(options.prompt)))
|
|
163
|
-
),
|
|
164
|
-
(parts) =>
|
|
165
|
-
languageModel.streamText({
|
|
166
|
-
...options,
|
|
167
|
-
system,
|
|
168
|
-
prompt: parts
|
|
169
|
-
}).pipe(
|
|
170
|
-
Stream.map((chunk) => {
|
|
171
|
-
combined = AiResponse.merge(combined, chunk)
|
|
172
|
-
return chunk
|
|
173
|
-
}),
|
|
174
|
-
Stream.toChannel
|
|
175
|
-
),
|
|
176
|
-
(parts) =>
|
|
177
|
-
Effect.zipRight(
|
|
178
|
-
Ref.set(history, AiInput.concat(parts, AiInput.make(combined))),
|
|
179
|
-
semaphore.release(1)
|
|
180
|
-
)
|
|
181
|
-
))
|
|
182
|
-
}).pipe(
|
|
183
|
-
provideContextStream,
|
|
184
|
-
Stream.withSpan("AiChat.streamText", {
|
|
185
|
-
captureStackTrace: false
|
|
186
|
-
})
|
|
187
|
-
) as any
|
|
188
|
-
},
|
|
189
|
-
generateObject(options) {
|
|
190
|
-
const newInput = AiInput.make(options.prompt)
|
|
191
|
-
return Ref.get(history).pipe(
|
|
192
|
-
Effect.flatMap((oldInput) => {
|
|
193
|
-
const input = AiInput.concat(oldInput, newInput)
|
|
194
|
-
return languageModel.generateObject({
|
|
195
|
-
...options,
|
|
196
|
-
system,
|
|
197
|
-
prompt: input
|
|
198
|
-
} as any).pipe(
|
|
199
|
-
Effect.flatMap((response) => {
|
|
200
|
-
const modelInput = AiInput.make(response)
|
|
201
|
-
return Effect.as(
|
|
202
|
-
Ref.set(history, AiInput.concat(input, modelInput)),
|
|
203
|
-
response
|
|
204
|
-
)
|
|
205
|
-
})
|
|
206
|
-
)
|
|
207
|
-
}),
|
|
208
|
-
provideContext,
|
|
209
|
-
semaphore.withPermits(1),
|
|
210
|
-
Effect.withSpan("AiChat.generateObject", {
|
|
211
|
-
attributes: {
|
|
212
|
-
toolCallId: "toolCallId" in options
|
|
213
|
-
? options.toolCallId
|
|
214
|
-
: "_tag" in options.schema
|
|
215
|
-
? options.schema._tag
|
|
216
|
-
: (options.schema as any).identifier ?? "generateObject"
|
|
217
|
-
},
|
|
218
|
-
captureStackTrace: false
|
|
219
|
-
})
|
|
220
|
-
) as any
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* @since 1.0.0
|
|
227
|
-
* @category Constructors
|
|
228
|
-
*/
|
|
229
|
-
export const empty: Effect.Effect<AiChat.Service, never, AiLanguageModel.AiLanguageModel> = fromPrompt({ prompt: [] })
|
|
230
|
-
|
|
231
|
-
const decodeUnknown = Schema.decodeUnknown(AiInput.AiInput)
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* @since 1.0.0
|
|
235
|
-
* @category Constructors
|
|
236
|
-
*/
|
|
237
|
-
export const fromExport = (data: unknown, options?: {
|
|
238
|
-
readonly system?: string | undefined
|
|
239
|
-
}): Effect.Effect<AiChat.Service, ParseError, AiLanguageModel.AiLanguageModel> =>
|
|
240
|
-
Effect.flatMap(decodeUnknown(data), (prompt) => fromPrompt({ ...options, prompt }))
|
|
241
|
-
|
|
242
|
-
const decodeJson = Schema.decode(AiInput.FromJson)
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @since 1.0.0
|
|
246
|
-
* @category Constructors
|
|
247
|
-
*/
|
|
248
|
-
export const fromJson = (data: string, options?: {
|
|
249
|
-
readonly system?: string | undefined
|
|
250
|
-
}): Effect.Effect<AiChat.Service, ParseError, AiLanguageModel.AiLanguageModel> =>
|
|
251
|
-
Effect.flatMap(decodeJson(data), (prompt) => fromPrompt({ ...options, prompt }))
|