@celljs/ai-anthropic 3.8.0 → 4.0.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/esm/common/api/anthropic-api.d.ts +15 -0
- package/esm/common/api/anthropic-api.js +93 -0
- package/esm/common/api/anthropic-api.js.map +1 -0
- package/esm/common/api/anthropic-model.d.ts +33 -0
- package/esm/common/api/anthropic-model.js +36 -0
- package/esm/common/api/anthropic-model.js.map +1 -0
- package/esm/common/api/api-protocol.d.ts +40 -0
- package/esm/common/api/api-protocol.js +3 -0
- package/esm/common/api/api-protocol.js.map +1 -0
- package/esm/common/api/chat-request.d.ts +149 -0
- package/esm/common/api/chat-request.js +184 -0
- package/esm/common/api/chat-request.js.map +1 -0
- package/esm/common/api/chat-response.d.ts +71 -0
- package/esm/common/api/chat-response.js +120 -0
- package/esm/common/api/chat-response.js.map +1 -0
- package/esm/common/api/content-block.d.ts +99 -0
- package/esm/common/api/content-block.js +127 -0
- package/esm/common/api/content-block.js.map +1 -0
- package/esm/common/api/event.d.ts +187 -0
- package/esm/common/api/event.js +344 -0
- package/esm/common/api/event.js.map +1 -0
- package/esm/common/api/index.d.ts +9 -0
- package/esm/common/api/index.js +10 -0
- package/esm/common/api/index.js.map +1 -0
- package/esm/common/api/message.d.ts +40 -0
- package/esm/common/api/message.js +54 -0
- package/esm/common/api/message.js.map +1 -0
- package/esm/common/api/usage.d.ts +14 -0
- package/esm/common/api/usage.js +28 -0
- package/esm/common/api/usage.js.map +1 -0
- package/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +3 -0
- package/esm/common/index.js.map +1 -0
- package/esm/common/model/anthropic-chat-model.d.ts +19 -0
- package/esm/common/model/anthropic-chat-model.js +169 -0
- package/esm/common/model/anthropic-chat-model.js.map +1 -0
- package/esm/common/model/anthropic-chat-options.d.ts +54 -0
- package/esm/common/model/anthropic-chat-options.js +170 -0
- package/esm/common/model/anthropic-chat-options.js.map +1 -0
- package/esm/common/model/index.d.ts +2 -0
- package/esm/common/model/index.js +3 -0
- package/esm/common/model/index.js.map +1 -0
- package/esm/common/module.d.ts +3 -0
- package/esm/common/module.js +4 -0
- package/esm/common/module.js.map +1 -0
- package/esm/common/test/mock-anthropic-api.d.ts +9 -0
- package/esm/common/test/mock-anthropic-api.js +61 -0
- package/esm/common/test/mock-anthropic-api.js.map +1 -0
- package/esm/common/test/test-container.d.ts +2 -0
- package/esm/common/test/test-container.js +11 -0
- package/esm/common/test/test-container.js.map +1 -0
- package/esm/common/utils/index.d.ts +1 -0
- package/esm/common/utils/index.js +2 -0
- package/esm/common/utils/index.js.map +1 -0
- package/esm/common/utils/stream-util.d.ts +8 -0
- package/esm/common/utils/stream-util.js +110 -0
- package/esm/common/utils/stream-util.js.map +1 -0
- package/esm/package.json +3 -0
- package/package.json +49 -6
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { AssistantMessage, ChatGenerationMetadata, ChatModel, ChatResponse, ChatResponseMetadata, Generation, MessageType, Usage, UserMessage } from '@celljs/ai-core';
|
|
11
|
+
import { Autowired, Component, IllegalArgumentError, Logger } from '@celljs/core';
|
|
12
|
+
import { AnthropicAPI, AnthropicMessage, ChatRequest, ContentBlock, ContentBlockType, Role, Source, Tool } from '../api/index.js';
|
|
13
|
+
import { AnthropicChatOptions } from './anthropic-chat-options.js';
|
|
14
|
+
import { map } from 'rxjs/operators/index.js';
|
|
15
|
+
let AnthropicChatModel = class AnthropicChatModel {
|
|
16
|
+
getContentBlockTypeByMedia(media) {
|
|
17
|
+
if (media.mimeType.toString().startsWith('image')) {
|
|
18
|
+
return ContentBlockType.IMAGE;
|
|
19
|
+
}
|
|
20
|
+
else if (media.mimeType.toString().startsWith('pdf')) {
|
|
21
|
+
return ContentBlockType.DOCUMENT;
|
|
22
|
+
}
|
|
23
|
+
throw new IllegalArgumentError(`Unsupported media type: ${media.mimeType.toString()}. Supported types are: images (image/*) and PDF documents (application/pdf)`);
|
|
24
|
+
}
|
|
25
|
+
fromMediaData(mediaData) {
|
|
26
|
+
if (mediaData instanceof Uint8Array) {
|
|
27
|
+
return btoa(String.fromCharCode(...mediaData));
|
|
28
|
+
}
|
|
29
|
+
else if (typeof mediaData === 'string') {
|
|
30
|
+
return mediaData;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new IllegalArgumentError(`Unsupported media data type: ${typeof mediaData}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
resolveFunctionCallbacks(functions) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
getFunctionTools(functions) {
|
|
40
|
+
return this.resolveFunctionCallbacks(functions).map(func => new Tool(func.name, func.description, JSON.parse(func.inputTypeSchema)));
|
|
41
|
+
}
|
|
42
|
+
createRequest(prompt, stream) {
|
|
43
|
+
const userMessages = prompt.instructions
|
|
44
|
+
.filter(message => message.messageType !== MessageType.SYSTEM)
|
|
45
|
+
.map(message => {
|
|
46
|
+
if (message.messageType === MessageType.USER) {
|
|
47
|
+
const contents = [new ContentBlock(ContentBlockType.TEXT, undefined, message.content)];
|
|
48
|
+
if (message instanceof UserMessage) {
|
|
49
|
+
if (message.media.length > 0) {
|
|
50
|
+
const mediaContent = message.media.map(media => {
|
|
51
|
+
const contentBlockType = this.getContentBlockTypeByMedia(media);
|
|
52
|
+
const source = new Source('base64', media.mimeType.toString(), this.fromMediaData(media.data));
|
|
53
|
+
return new ContentBlock(contentBlockType, source);
|
|
54
|
+
});
|
|
55
|
+
contents.push(...mediaContent);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return new AnthropicMessage(contents, message.messageType === MessageType.USER ? Role.USER : Role.ASSISTANT);
|
|
59
|
+
}
|
|
60
|
+
else if (message.messageType === MessageType.ASSISTANT) {
|
|
61
|
+
const assistantMessage = message;
|
|
62
|
+
const contentBlocks = [];
|
|
63
|
+
if (message.content) {
|
|
64
|
+
contentBlocks.push(new ContentBlock(ContentBlockType.TEXT, undefined, message.content));
|
|
65
|
+
}
|
|
66
|
+
if (assistantMessage.toolCalls.length > 0) {
|
|
67
|
+
for (const toolCall of assistantMessage.toolCalls) {
|
|
68
|
+
contentBlocks.push(new ContentBlock(ContentBlockType.TOOL_USE, undefined, undefined, undefined, toolCall.id, toolCall.name, JSON.parse(toolCall.arguments)));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return new AnthropicMessage(contentBlocks, Role.ASSISTANT);
|
|
72
|
+
}
|
|
73
|
+
else if (message.messageType === MessageType.TOOL) {
|
|
74
|
+
const toolResponses = message.responses.map(toolResponse => new ContentBlock(ContentBlockType.TOOL_RESULT, undefined, undefined, undefined, toolResponse.id, toolResponse.responseData));
|
|
75
|
+
return new AnthropicMessage(toolResponses, Role.USER);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new IllegalArgumentError(`Unsupported message type: ${message.messageType}`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const systemPrompt = prompt.instructions
|
|
82
|
+
.filter(m => m.messageType === MessageType.SYSTEM)
|
|
83
|
+
.map(m => m.content)
|
|
84
|
+
.join('\n');
|
|
85
|
+
let request = new ChatRequest(this.defaultOptions.model, userMessages, systemPrompt, this.defaultOptions.maxTokens, this.defaultOptions.temperature, stream);
|
|
86
|
+
// Runtime options
|
|
87
|
+
let runtimeOptions = AnthropicChatOptions.builder().build();
|
|
88
|
+
if (prompt.options) {
|
|
89
|
+
runtimeOptions = Object.assign(runtimeOptions, prompt.options);
|
|
90
|
+
}
|
|
91
|
+
request = Object.assign(request, runtimeOptions);
|
|
92
|
+
const functionsForThisRequest = new Set();
|
|
93
|
+
if (this.defaultOptions.functions.size > 0) {
|
|
94
|
+
this.defaultOptions.functions.forEach(func => functionsForThisRequest.add(func));
|
|
95
|
+
}
|
|
96
|
+
if (functionsForThisRequest.size > 0) {
|
|
97
|
+
const tools = this.getFunctionTools(functionsForThisRequest);
|
|
98
|
+
request.tools = tools;
|
|
99
|
+
}
|
|
100
|
+
return request;
|
|
101
|
+
}
|
|
102
|
+
from(response) {
|
|
103
|
+
return ChatResponseMetadata.builder()
|
|
104
|
+
.id(response.id)
|
|
105
|
+
.model(response.model)
|
|
106
|
+
.usage(Usage.from(response.usage.inputTokens, response.usage.outputTokens))
|
|
107
|
+
.keyValue('stop-reason', response.stopReason)
|
|
108
|
+
.keyValue('stop-sequence', response.stopSequence)
|
|
109
|
+
.keyValue('type', response.type)
|
|
110
|
+
.build();
|
|
111
|
+
}
|
|
112
|
+
toChatResponse(response) {
|
|
113
|
+
if (response === undefined) {
|
|
114
|
+
this.logger.warn('Null chat completion returned');
|
|
115
|
+
return ChatResponse.from([]);
|
|
116
|
+
}
|
|
117
|
+
const generations = response.content
|
|
118
|
+
.filter(content => content.type !== ContentBlockType.TOOL_USE)
|
|
119
|
+
.map(content => Generation.from(new AssistantMessage(content.text), ChatGenerationMetadata.from(response.stopReason)));
|
|
120
|
+
const allGenerations = [...generations];
|
|
121
|
+
if (response.stopReason && generations.length === 0) {
|
|
122
|
+
const generation = Generation.from(new AssistantMessage(), ChatGenerationMetadata.from(response.stopReason));
|
|
123
|
+
allGenerations.push(generation);
|
|
124
|
+
}
|
|
125
|
+
const toolToUseList = response.content.filter(c => c.type === ContentBlockType.TOOL_USE);
|
|
126
|
+
if (toolToUseList.length > 0) {
|
|
127
|
+
const toolCalls = [];
|
|
128
|
+
for (const toolToUse of toolToUseList) {
|
|
129
|
+
toolCalls.push({
|
|
130
|
+
id: toolToUse.id,
|
|
131
|
+
type: 'function',
|
|
132
|
+
name: toolToUse.name,
|
|
133
|
+
arguments: JSON.stringify(toolToUse.input)
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const assistantMessage = new AssistantMessage('', [], {}, toolCalls);
|
|
137
|
+
const toolCallGeneration = Generation.from(assistantMessage, ChatGenerationMetadata.from(response.stopReason));
|
|
138
|
+
allGenerations.push(toolCallGeneration);
|
|
139
|
+
}
|
|
140
|
+
return ChatResponse.from(allGenerations, this.from(response));
|
|
141
|
+
}
|
|
142
|
+
async call(prompt) {
|
|
143
|
+
const request = this.createRequest(prompt, false);
|
|
144
|
+
const chatResponse = await this.chatApi.chat(request);
|
|
145
|
+
return this.toChatResponse(chatResponse.body);
|
|
146
|
+
}
|
|
147
|
+
async stream(prompt) {
|
|
148
|
+
const request = this.createRequest(prompt, true);
|
|
149
|
+
const chatResponse = await this.chatApi.streamingChat(request);
|
|
150
|
+
return chatResponse.pipe(map(chunk => this.toChatResponse(chunk.body)));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
__decorate([
|
|
154
|
+
Autowired(AnthropicChatOptions),
|
|
155
|
+
__metadata("design:type", AnthropicChatOptions)
|
|
156
|
+
], AnthropicChatModel.prototype, "defaultOptions", void 0);
|
|
157
|
+
__decorate([
|
|
158
|
+
Autowired(AnthropicAPI),
|
|
159
|
+
__metadata("design:type", Object)
|
|
160
|
+
], AnthropicChatModel.prototype, "chatApi", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
Autowired(Logger),
|
|
163
|
+
__metadata("design:type", Object)
|
|
164
|
+
], AnthropicChatModel.prototype, "logger", void 0);
|
|
165
|
+
AnthropicChatModel = __decorate([
|
|
166
|
+
Component(ChatModel)
|
|
167
|
+
], AnthropicChatModel);
|
|
168
|
+
export { AnthropicChatModel };
|
|
169
|
+
//# sourceMappingURL=anthropic-chat-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-chat-model.js","sourceRoot":"","sources":["../../../src/common/model/anthropic-chat-model.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACH,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,YAAY,EACZ,oBAAoB,EAEpB,UAAU,EAEV,WAAW,EAIX,KAAK,EACL,WAAW,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,EAAE,YAAY,EAA0C,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACjK,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAG9B,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAUjB,0BAA0B,CAAC,KAAY;QAC7C,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAChD,OAAO,gBAAgB,CAAC,KAAK,CAAC;QAClC,CAAC;aAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,OAAO,gBAAgB,CAAC,QAAQ,CAAC;QACrC,CAAC;QACD,MAAM,IAAI,oBAAoB,CAAC,2BAA2B,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,6EAA6E,CAAC,CAAC;IACtK,CAAC;IAES,aAAa,CAAC,SAAc;QAClC,IAAI,SAAS,YAAY,UAA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B,SAAS,CAAC,SAAS,CAAC;GACR,kBAAkB,CAsK9B"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { FunctionCallback, FunctionCallingOptions } from '@celljs/ai-core';
|
|
2
|
+
import { Metadata } from '../api/chat-request.js';
|
|
3
|
+
/**
|
|
4
|
+
* The options to be used when sending a chat request to the Anthropic API.
|
|
5
|
+
*/
|
|
6
|
+
export declare class AnthropicChatOptions implements FunctionCallingOptions {
|
|
7
|
+
model: string;
|
|
8
|
+
maxTokens: number;
|
|
9
|
+
metadata: Metadata;
|
|
10
|
+
stopSequences: string[];
|
|
11
|
+
temperature: number;
|
|
12
|
+
topP: number;
|
|
13
|
+
topK: number;
|
|
14
|
+
/**
|
|
15
|
+
* Tool Function Callbacks to register with the ChatModel. For Prompt
|
|
16
|
+
* Options the functionCallbacks are automatically enabled for the duration of the
|
|
17
|
+
* prompt execution. For Default Options the functionCallbacks are registered but
|
|
18
|
+
* disabled by default. Use the enableFunctions to set the functions from the registry
|
|
19
|
+
* to be used by the ChatModel chat completion requests.
|
|
20
|
+
*/
|
|
21
|
+
functionCallbacks: FunctionCallback[];
|
|
22
|
+
/**
|
|
23
|
+
* List of functions, identified by their names, to configure for function calling in
|
|
24
|
+
* the chat completion requests. Functions with those names must exist in the
|
|
25
|
+
* functionCallbacks registry. The {@link #functionCallbacks} from the PromptOptions
|
|
26
|
+
* are automatically enabled for the duration of the prompt execution
|
|
27
|
+
*
|
|
28
|
+
* Note that function enabled with the default options are enabled for all chat
|
|
29
|
+
* completion requests. This could impact the token count and the billing. If the
|
|
30
|
+
* functions is set in a prompt options, then the enabled functions are only active
|
|
31
|
+
* for the duration of this prompt execution
|
|
32
|
+
*/
|
|
33
|
+
functions: Set<string>;
|
|
34
|
+
proxyToolCalls: boolean;
|
|
35
|
+
toolContext: Record<string, any>;
|
|
36
|
+
static builder(): AnthropicChatOptionsBuilder;
|
|
37
|
+
static fromOptions(fromOptions: AnthropicChatOptions): AnthropicChatOptions;
|
|
38
|
+
}
|
|
39
|
+
export declare class AnthropicChatOptionsBuilder {
|
|
40
|
+
private options;
|
|
41
|
+
model(model: string): AnthropicChatOptionsBuilder;
|
|
42
|
+
maxTokens(maxTokens: number): AnthropicChatOptionsBuilder;
|
|
43
|
+
metadata(metadata: Metadata): AnthropicChatOptionsBuilder;
|
|
44
|
+
stopSequences(stopSequences: string[]): AnthropicChatOptionsBuilder;
|
|
45
|
+
temperature(temperature: number): AnthropicChatOptionsBuilder;
|
|
46
|
+
topP(topP: number): AnthropicChatOptionsBuilder;
|
|
47
|
+
topK(topK: number): AnthropicChatOptionsBuilder;
|
|
48
|
+
functionCallbacks(functionCallbacks: FunctionCallback[]): AnthropicChatOptionsBuilder;
|
|
49
|
+
functions(functions: Set<string>): AnthropicChatOptionsBuilder;
|
|
50
|
+
function(functionName: string): AnthropicChatOptionsBuilder;
|
|
51
|
+
proxyToolCalls(proxyToolCalls: boolean): AnthropicChatOptionsBuilder;
|
|
52
|
+
toolContext(toolContext: Record<string, any>): AnthropicChatOptionsBuilder;
|
|
53
|
+
build(): AnthropicChatOptions;
|
|
54
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var AnthropicChatOptions_1;
|
|
11
|
+
import { Exclude, Expose } from 'class-transformer';
|
|
12
|
+
import { Metadata } from '../api/chat-request.js';
|
|
13
|
+
import { Constant } from '@celljs/core';
|
|
14
|
+
/**
|
|
15
|
+
* The options to be used when sending a chat request to the Anthropic API.
|
|
16
|
+
*/
|
|
17
|
+
let AnthropicChatOptions = AnthropicChatOptions_1 = class AnthropicChatOptions {
|
|
18
|
+
constructor() {
|
|
19
|
+
/**
|
|
20
|
+
* Tool Function Callbacks to register with the ChatModel. For Prompt
|
|
21
|
+
* Options the functionCallbacks are automatically enabled for the duration of the
|
|
22
|
+
* prompt execution. For Default Options the functionCallbacks are registered but
|
|
23
|
+
* disabled by default. Use the enableFunctions to set the functions from the registry
|
|
24
|
+
* to be used by the ChatModel chat completion requests.
|
|
25
|
+
*/
|
|
26
|
+
this.functionCallbacks = [];
|
|
27
|
+
/**
|
|
28
|
+
* List of functions, identified by their names, to configure for function calling in
|
|
29
|
+
* the chat completion requests. Functions with those names must exist in the
|
|
30
|
+
* functionCallbacks registry. The {@link #functionCallbacks} from the PromptOptions
|
|
31
|
+
* are automatically enabled for the duration of the prompt execution
|
|
32
|
+
*
|
|
33
|
+
* Note that function enabled with the default options are enabled for all chat
|
|
34
|
+
* completion requests. This could impact the token count and the billing. If the
|
|
35
|
+
* functions is set in a prompt options, then the enabled functions are only active
|
|
36
|
+
* for the duration of this prompt execution
|
|
37
|
+
*/
|
|
38
|
+
this.functions = new Set();
|
|
39
|
+
this.proxyToolCalls = false;
|
|
40
|
+
this.toolContext = {};
|
|
41
|
+
}
|
|
42
|
+
static builder() {
|
|
43
|
+
return new AnthropicChatOptionsBuilder();
|
|
44
|
+
}
|
|
45
|
+
static fromOptions(fromOptions) {
|
|
46
|
+
return AnthropicChatOptions_1.builder()
|
|
47
|
+
.model(fromOptions.model)
|
|
48
|
+
.maxTokens(fromOptions.maxTokens)
|
|
49
|
+
.metadata(fromOptions.metadata)
|
|
50
|
+
.stopSequences(fromOptions.stopSequences)
|
|
51
|
+
.temperature(fromOptions.temperature)
|
|
52
|
+
.topP(fromOptions.topP)
|
|
53
|
+
.topK(fromOptions.topK)
|
|
54
|
+
.functionCallbacks(fromOptions.functionCallbacks)
|
|
55
|
+
.functions(fromOptions.functions)
|
|
56
|
+
.proxyToolCalls(fromOptions.proxyToolCalls)
|
|
57
|
+
.toolContext(fromOptions.toolContext)
|
|
58
|
+
.build();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
__decorate([
|
|
62
|
+
Expose(),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], AnthropicChatOptions.prototype, "model", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
Expose({ name: 'max_tokens' }),
|
|
67
|
+
__metadata("design:type", Number)
|
|
68
|
+
], AnthropicChatOptions.prototype, "maxTokens", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
Expose(),
|
|
71
|
+
__metadata("design:type", Metadata)
|
|
72
|
+
], AnthropicChatOptions.prototype, "metadata", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
Expose({ name: 'stop_sequences' }),
|
|
75
|
+
__metadata("design:type", Array)
|
|
76
|
+
], AnthropicChatOptions.prototype, "stopSequences", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
Expose({ name: 'temperature' }),
|
|
79
|
+
__metadata("design:type", Number)
|
|
80
|
+
], AnthropicChatOptions.prototype, "temperature", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
Expose({ name: 'top_p' }),
|
|
83
|
+
__metadata("design:type", Number)
|
|
84
|
+
], AnthropicChatOptions.prototype, "topP", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
Expose({ name: 'top_k' }),
|
|
87
|
+
__metadata("design:type", Number)
|
|
88
|
+
], AnthropicChatOptions.prototype, "topK", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
Exclude(),
|
|
91
|
+
__metadata("design:type", Array)
|
|
92
|
+
], AnthropicChatOptions.prototype, "functionCallbacks", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
Exclude(),
|
|
95
|
+
__metadata("design:type", Set)
|
|
96
|
+
], AnthropicChatOptions.prototype, "functions", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
Exclude(),
|
|
99
|
+
__metadata("design:type", Object)
|
|
100
|
+
], AnthropicChatOptions.prototype, "proxyToolCalls", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
Exclude(),
|
|
103
|
+
__metadata("design:type", Object)
|
|
104
|
+
], AnthropicChatOptions.prototype, "toolContext", void 0);
|
|
105
|
+
AnthropicChatOptions = AnthropicChatOptions_1 = __decorate([
|
|
106
|
+
Constant(AnthropicChatOptions, new AnthropicChatOptions())
|
|
107
|
+
], AnthropicChatOptions);
|
|
108
|
+
export { AnthropicChatOptions };
|
|
109
|
+
export class AnthropicChatOptionsBuilder {
|
|
110
|
+
constructor() {
|
|
111
|
+
this.options = new AnthropicChatOptions();
|
|
112
|
+
}
|
|
113
|
+
model(model) {
|
|
114
|
+
this.options.model = model;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
maxTokens(maxTokens) {
|
|
118
|
+
this.options.maxTokens = maxTokens;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
metadata(metadata) {
|
|
122
|
+
this.options.metadata = metadata;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
stopSequences(stopSequences) {
|
|
126
|
+
this.options.stopSequences = stopSequences;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
temperature(temperature) {
|
|
130
|
+
this.options.temperature = temperature;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
topP(topP) {
|
|
134
|
+
this.options.topP = topP;
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
topK(topK) {
|
|
138
|
+
this.options.topK = topK;
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
functionCallbacks(functionCallbacks) {
|
|
142
|
+
this.options.functionCallbacks = functionCallbacks;
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
functions(functions) {
|
|
146
|
+
this.options.functions = functions;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
function(functionName) {
|
|
150
|
+
this.options.functions.add(functionName);
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
proxyToolCalls(proxyToolCalls) {
|
|
154
|
+
this.options.proxyToolCalls = proxyToolCalls;
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
toolContext(toolContext) {
|
|
158
|
+
if (this.options.toolContext === undefined) {
|
|
159
|
+
this.options.toolContext = toolContext;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.options.toolContext = { ...this.options.toolContext, ...toolContext };
|
|
163
|
+
}
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
build() {
|
|
167
|
+
return this.options;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=anthropic-chat-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-chat-options.js","sourceRoot":"","sources":["../../../src/common/model/anthropic-chat-options.ts"],"names":[],"mappings":";;;;;;;;;;AACA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC;;GAEG;AAEI,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAA1B;QAuBH;;;;;;WAMG;QAEH,sBAAiB,GAAuB,EAAE,CAAC;QAE3C;;;;;;;;;;WAUG;QAEH,cAAS,GAAgB,IAAI,GAAG,EAAU,CAAC;QAE3C,mBAAc,GAAG,KAAK,CAAC;QAGvB,gBAAW,GAAwB,EAAE,CAAC;IAqB1C,CAAC;IAnBG,MAAM,CAAC,OAAO;QACV,OAAO,IAAI,2BAA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CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,cAAc,CAAC,cAAuB;QAClC,IAAI,CAAC,OAAO,CAAC,cAAc,GAAG,cAAc,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,WAAW,CAAC,WAAgC;QACxC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;QAC3C,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,WAAW,EAAE,CAAC;QAC/E,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/common/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,CAAC;AAEjB,eAAe,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { ResponseEntity } from '@celljs/http';
|
|
3
|
+
import { AnthropicAPI } from '../api/api-protocol.js';
|
|
4
|
+
import { ChatRequest } from '../api/chat-request.js';
|
|
5
|
+
import { ChatResponse } from '../api/chat-response.js';
|
|
6
|
+
export declare class MockAnthropicAPI implements AnthropicAPI {
|
|
7
|
+
chat(chatRequest: ChatRequest): Promise<ResponseEntity<ChatResponse>>;
|
|
8
|
+
streamingChat(chatRequest: ChatRequest): Promise<Observable<ResponseEntity<ChatResponse>>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Component } from '@celljs/core';
|
|
8
|
+
import { from } from 'rxjs';
|
|
9
|
+
import { AnthropicAPI } from '../api/api-protocol.js';
|
|
10
|
+
import { ChatResponse } from '../api/chat-response.js';
|
|
11
|
+
import { ContentBlockType } from '../api/content-block.js';
|
|
12
|
+
import { Role } from '../api/message.js';
|
|
13
|
+
let MockAnthropicAPI = class MockAnthropicAPI {
|
|
14
|
+
async chat(chatRequest) {
|
|
15
|
+
if (chatRequest.stream) {
|
|
16
|
+
throw new Error('Request must set the stream property to false.');
|
|
17
|
+
}
|
|
18
|
+
const response = new ChatResponse('msg_123', 'message', Role.ASSISTANT, [
|
|
19
|
+
{
|
|
20
|
+
type: ContentBlockType.TEXT,
|
|
21
|
+
text: 'How can I assist you today?'
|
|
22
|
+
}
|
|
23
|
+
], chatRequest.model, 'end_turn', undefined, {
|
|
24
|
+
inputTokens: 10,
|
|
25
|
+
outputTokens: 20
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
status: 200,
|
|
29
|
+
headers: {
|
|
30
|
+
'x-request-id': 'mock-req-123'
|
|
31
|
+
},
|
|
32
|
+
body: response
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async streamingChat(chatRequest) {
|
|
36
|
+
if (!chatRequest.stream) {
|
|
37
|
+
throw new Error('Request must set the stream property to true.');
|
|
38
|
+
}
|
|
39
|
+
const response = new ChatResponse('msg_123', 'message', Role.ASSISTANT, [
|
|
40
|
+
{
|
|
41
|
+
type: ContentBlockType.TEXT,
|
|
42
|
+
text: 'How can I assist you today?'
|
|
43
|
+
}
|
|
44
|
+
], chatRequest.model, 'end_turn', undefined, {
|
|
45
|
+
inputTokens: 10,
|
|
46
|
+
outputTokens: 20
|
|
47
|
+
});
|
|
48
|
+
return from([{
|
|
49
|
+
status: 200,
|
|
50
|
+
headers: {
|
|
51
|
+
'x-request-id': 'mock-req-123'
|
|
52
|
+
},
|
|
53
|
+
body: response
|
|
54
|
+
}]);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
MockAnthropicAPI = __decorate([
|
|
58
|
+
Component(AnthropicAPI)
|
|
59
|
+
], MockAnthropicAPI);
|
|
60
|
+
export { MockAnthropicAPI };
|
|
61
|
+
//# sourceMappingURL=mock-anthropic-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-anthropic-api.js","sourceRoot":"","sources":["../../../src/common/test/mock-anthropic-api.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAc,IAAI,EAAE,MAAM,MAAM,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAG/B,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACzB,KAAK,CAAC,IAAI,CAAC,WAAwB;QAC/B,IAAI,WAAW,CAAC,MAA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lib/common/test/test-module';
|
|
2
|
+
import httpModule from '@celljs/http/lib/common/module';
|
|
3
|
+
import { autoBind, ContainerFactory, ContainerProvider } from '@celljs/core';
|
|
4
|
+
import '../index.js';
|
|
5
|
+
const ollamaTestModule = autoBind();
|
|
6
|
+
export const createContainer = () => {
|
|
7
|
+
const container = ContainerFactory.create(coreTestModule, httpModule, ollamaTestModule);
|
|
8
|
+
ContainerProvider.set(container);
|
|
9
|
+
return container;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=test-container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../../src/common/test/test-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,UAAU,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,UAAU,CAAC;AAElB,MAAM,gBAAgB,GAAG,QAAQ,EAAE,CAAC;AAEpC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE;IAChC,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACxF,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACjC,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stream-util.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChatResponse } from '../api/chat-response.js';
|
|
2
|
+
import { AnthropicEvent } from '../api/event.js';
|
|
3
|
+
export declare abstract class StreamUtil {
|
|
4
|
+
static isToolUseStart(event: AnthropicEvent): boolean;
|
|
5
|
+
static isToolUseFinish(event: AnthropicEvent): boolean;
|
|
6
|
+
static mergeToolUseEvents(previousEvent: AnthropicEvent, event: AnthropicEvent): AnthropicEvent;
|
|
7
|
+
static eventToChatResponse(event: AnthropicEvent): ChatResponse;
|
|
8
|
+
}
|