@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,15 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { ResponseEntity, RestOperations } from '@celljs/http';
|
|
3
|
+
import { ChatRequest } from './chat-request.js';
|
|
4
|
+
import { ChatResponse } from './chat-response.js';
|
|
5
|
+
import { AnthropicAPI, AnthropicAPIOptions } from './api-protocol.js';
|
|
6
|
+
export declare class AnthropicAPIImpl implements AnthropicAPI {
|
|
7
|
+
protected readonly restOperations: RestOperations;
|
|
8
|
+
protected readonly options?: AnthropicAPIOptions;
|
|
9
|
+
protected readonly defaultOptions?: AnthropicAPIOptions;
|
|
10
|
+
protected get baseUrl(): string;
|
|
11
|
+
protected get apiKey(): string | undefined;
|
|
12
|
+
protected get anthropicVersion(): string;
|
|
13
|
+
chat(chatRequest: ChatRequest): Promise<ResponseEntity<ChatResponse>>;
|
|
14
|
+
streamingChat(chatRequest: ChatRequest): Promise<Observable<ResponseEntity<ChatResponse>>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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 { Assert, Autowired, Component, Optional, Value } from '@celljs/core';
|
|
11
|
+
import { map, filter, groupBy, concatMap, reduce } from 'rxjs/operators/index.js';
|
|
12
|
+
import { RestOperations } from '@celljs/http';
|
|
13
|
+
import { ChatResponse } from './chat-response.js';
|
|
14
|
+
import { AnthropicAPI, AnthropicAPIOptions } from './api-protocol.js';
|
|
15
|
+
import { instanceToPlain, plainToInstance } from 'class-transformer';
|
|
16
|
+
import { SSEUtil } from '@celljs/ai-core';
|
|
17
|
+
import { EventType, AnthropicStreamEvent, ToolUseAggregationEvent } from './event.js';
|
|
18
|
+
import { StreamUtil } from '../utils/index.js';
|
|
19
|
+
let AnthropicAPIImpl = class AnthropicAPIImpl {
|
|
20
|
+
get baseUrl() {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
var _c, _d;
|
|
23
|
+
return (_d = (_c = (_a = this.options) === null || _a === void 0 ? void 0 : _a.baseUrl) !== null && _c !== void 0 ? _c : (_b = this.defaultOptions) === null || _b === void 0 ? void 0 : _b.baseUrl) !== null && _d !== void 0 ? _d : 'https://api.anthropic.com';
|
|
24
|
+
}
|
|
25
|
+
get apiKey() {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
var _c;
|
|
28
|
+
return (_c = (_a = this.options) === null || _a === void 0 ? void 0 : _a.apiKey) !== null && _c !== void 0 ? _c : (_b = this.defaultOptions) === null || _b === void 0 ? void 0 : _b.apiKey;
|
|
29
|
+
}
|
|
30
|
+
get anthropicVersion() {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
var _c, _d;
|
|
33
|
+
return (_d = (_c = (_a = this.options) === null || _a === void 0 ? void 0 : _a.anthropicVersion) !== null && _c !== void 0 ? _c : (_b = this.defaultOptions) === null || _b === void 0 ? void 0 : _b.anthropicVersion) !== null && _d !== void 0 ? _d : '2023-06-01';
|
|
34
|
+
}
|
|
35
|
+
async chat(chatRequest) {
|
|
36
|
+
Assert.isTrue(!chatRequest.stream, 'Request must set the stream property to false.');
|
|
37
|
+
const { data, status, headers } = await this.restOperations
|
|
38
|
+
.post('/v1/messages', instanceToPlain(chatRequest, { excludeExtraneousValues: true }), { baseURL: this.baseUrl, signal: chatRequest.signal });
|
|
39
|
+
return {
|
|
40
|
+
status,
|
|
41
|
+
headers,
|
|
42
|
+
body: plainToInstance(ChatResponse, data)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async streamingChat(chatRequest) {
|
|
46
|
+
Assert.isTrue(chatRequest.stream, 'Request must set the stream property to true.');
|
|
47
|
+
const { data, status, headers } = await this.restOperations
|
|
48
|
+
.post('/v1/messages', instanceToPlain(chatRequest, { excludeExtraneousValues: true }), {
|
|
49
|
+
baseURL: this.baseUrl,
|
|
50
|
+
headers: {
|
|
51
|
+
'Accept': 'text/event-stream',
|
|
52
|
+
},
|
|
53
|
+
responseType: 'stream',
|
|
54
|
+
signal: chatRequest.signal
|
|
55
|
+
});
|
|
56
|
+
let isInsideTool = false;
|
|
57
|
+
return SSEUtil.toObservable(data)
|
|
58
|
+
.pipe(map(item => plainToInstance(AnthropicStreamEvent, item)), filter(item => item.data.type !== EventType.PING), map(item => {
|
|
59
|
+
if (StreamUtil.isToolUseStart(item.data)) {
|
|
60
|
+
isInsideTool = true;
|
|
61
|
+
}
|
|
62
|
+
return item;
|
|
63
|
+
}), groupBy(item => {
|
|
64
|
+
if (isInsideTool && StreamUtil.isToolUseFinish(item.data)) {
|
|
65
|
+
isInsideTool = false;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return !isInsideTool;
|
|
69
|
+
}), concatMap(group => group.pipe(reduce((acc, curr) => StreamUtil.mergeToolUseEvents(acc, curr.data), new ToolUseAggregationEvent()))), map(event => ({
|
|
70
|
+
status,
|
|
71
|
+
headers,
|
|
72
|
+
body: StreamUtil.eventToChatResponse(event)
|
|
73
|
+
})), filter(response => !!response.body.type));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
__decorate([
|
|
77
|
+
Autowired(RestOperations),
|
|
78
|
+
__metadata("design:type", Function)
|
|
79
|
+
], AnthropicAPIImpl.prototype, "restOperations", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
Value('cell.ai.anthropic.api'),
|
|
82
|
+
__metadata("design:type", Object)
|
|
83
|
+
], AnthropicAPIImpl.prototype, "options", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
Autowired(AnthropicAPIOptions),
|
|
86
|
+
Optional(),
|
|
87
|
+
__metadata("design:type", Object)
|
|
88
|
+
], AnthropicAPIImpl.prototype, "defaultOptions", void 0);
|
|
89
|
+
AnthropicAPIImpl = __decorate([
|
|
90
|
+
Component(AnthropicAPI)
|
|
91
|
+
], AnthropicAPIImpl);
|
|
92
|
+
export { AnthropicAPIImpl };
|
|
93
|
+
//# sourceMappingURL=anthropic-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-api.js","sourceRoot":"","sources":["../../../src/common/api/anthropic-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7E,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAG,MAAM,gBAAgB,CAAC;AAC1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CAAC;gBACrB,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,OAAO,CAAC,YAAY,CAAC;QACzB,CAAC,CAAC,EACF,SAAS,CAAC,KAAK,CAAC,EAAE,CACd,KAAK,CAAC,IAAI,CACN,MAAM,CACF,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,EAC5D,IAAI,uBAAuB,EAAE,CAChC,CACJ,CACJ,EACD,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACV,MAAM;YACN,OAAO;YACP,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC;SAC9C,CAAC,CAAC,EACH,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3C,CAAC;IAEV,CAAC;CACJ,CAAA;AAlFsB;IADlB,SAAS,CAAC,cAAc,CAAC;;wDACwB;AAG/B;IADlB,KAAK,CAAC,uBAAuB,CAAC;;iDACkB;AAI9B;IAFlB,SAAS,CAAC,mBAAmB,CAAC;IAC9B,QAAQ,EAAE;;wDAC6C;AAV/C,gBAAgB;IAD5B,SAAS,CAAC,YAAY,CAAC;GACX,gBAAgB,CAqF5B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class for the Anthropic model.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum AnthropicModel {
|
|
5
|
+
/**
|
|
6
|
+
* The claude-3-5-sonnet-20241022 model.
|
|
7
|
+
*/
|
|
8
|
+
CLAUDE_3_5_SONNET = "claude-3-5-sonnet-latest",
|
|
9
|
+
/**
|
|
10
|
+
* The CLAUDE_3_OPUS
|
|
11
|
+
*/
|
|
12
|
+
CLAUDE_3_OPUS = "claude-3-opus-latest",
|
|
13
|
+
/**
|
|
14
|
+
* The CLAUDE_3_SONNET
|
|
15
|
+
*/
|
|
16
|
+
CLAUDE_3_SONNET = "claude-3-sonnet-20240229",
|
|
17
|
+
/**
|
|
18
|
+
* The CLAUDE 3.5 HAIKU
|
|
19
|
+
*/
|
|
20
|
+
CLAUDE_3_5_HAIKU = "claude-3-5-haiku-latest",
|
|
21
|
+
/**
|
|
22
|
+
* The CLAUDE_3_HAIKU
|
|
23
|
+
*/
|
|
24
|
+
CLAUDE_3_HAIKU = "claude-3-haiku-20240307",
|
|
25
|
+
/**
|
|
26
|
+
* The CLAUDE_2_1
|
|
27
|
+
*/
|
|
28
|
+
CLAUDE_2_1 = "claude-2.1",
|
|
29
|
+
/**
|
|
30
|
+
* The CLAUDE_2_0
|
|
31
|
+
*/
|
|
32
|
+
CLAUDE_2 = "claude-2.0"
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class for the Anthropic model.
|
|
3
|
+
*/
|
|
4
|
+
export var AnthropicModel;
|
|
5
|
+
(function (AnthropicModel) {
|
|
6
|
+
/**
|
|
7
|
+
* The claude-3-5-sonnet-20241022 model.
|
|
8
|
+
*/
|
|
9
|
+
AnthropicModel["CLAUDE_3_5_SONNET"] = "claude-3-5-sonnet-latest";
|
|
10
|
+
/**
|
|
11
|
+
* The CLAUDE_3_OPUS
|
|
12
|
+
*/
|
|
13
|
+
AnthropicModel["CLAUDE_3_OPUS"] = "claude-3-opus-latest";
|
|
14
|
+
/**
|
|
15
|
+
* The CLAUDE_3_SONNET
|
|
16
|
+
*/
|
|
17
|
+
AnthropicModel["CLAUDE_3_SONNET"] = "claude-3-sonnet-20240229";
|
|
18
|
+
/**
|
|
19
|
+
* The CLAUDE 3.5 HAIKU
|
|
20
|
+
*/
|
|
21
|
+
AnthropicModel["CLAUDE_3_5_HAIKU"] = "claude-3-5-haiku-latest";
|
|
22
|
+
/**
|
|
23
|
+
* The CLAUDE_3_HAIKU
|
|
24
|
+
*/
|
|
25
|
+
AnthropicModel["CLAUDE_3_HAIKU"] = "claude-3-haiku-20240307";
|
|
26
|
+
// Legacy models
|
|
27
|
+
/**
|
|
28
|
+
* The CLAUDE_2_1
|
|
29
|
+
*/
|
|
30
|
+
AnthropicModel["CLAUDE_2_1"] = "claude-2.1";
|
|
31
|
+
/**
|
|
32
|
+
* The CLAUDE_2_0
|
|
33
|
+
*/
|
|
34
|
+
AnthropicModel["CLAUDE_2"] = "claude-2.0";
|
|
35
|
+
})(AnthropicModel || (AnthropicModel = {}));
|
|
36
|
+
//# sourceMappingURL=anthropic-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-model.js","sourceRoot":"","sources":["../../../src/common/api/anthropic-model.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,cAsCX;AAtCD,WAAY,cAAc;IAEtB;;OAEG;IACH,gEAA8C,CAAA;IAE9C;;OAEG;IACH,wDAAsC,CAAA;IAEtC;;OAEG;IACH,8DAA4C,CAAA;IAE5C;;OAEG;IACH,8DAA4C,CAAA;IAE5C;;OAEG;IACH,4DAA0C,CAAA;IAE1C,gBAAgB;IAChB;;OAEG;IACH,2CAAyB,CAAA;IAEzB;;OAEG;IACH,yCAAuB,CAAA;AAE3B,CAAC,EAtCW,cAAc,KAAd,cAAc,QAsCzB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { ChatRequest } from './chat-request.js';
|
|
3
|
+
import { ChatResponse } from './chat-response.js';
|
|
4
|
+
import { ResponseEntity } from '@celljs/http';
|
|
5
|
+
export declare const AnthropicAPI: unique symbol;
|
|
6
|
+
export declare const AnthropicAPIOptions: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Anthropic API options.
|
|
9
|
+
*/
|
|
10
|
+
export interface AnthropicAPIOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Base URL of the Anthropic API.
|
|
13
|
+
*/
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* API key to authenticate with the Anthropic API.
|
|
17
|
+
*/
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Version of the Anthropic API.
|
|
21
|
+
*/
|
|
22
|
+
anthropicVersion?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface AnthropicAPI {
|
|
25
|
+
/**
|
|
26
|
+
* Generate the next message in a chat with a provided model.
|
|
27
|
+
* This is a streaming endpoint (controlled by the 'stream' request property), so
|
|
28
|
+
* there will be a series of responses. The final response object will include
|
|
29
|
+
* statistics and additional data from the request.
|
|
30
|
+
* @param chatRequest Chat request.
|
|
31
|
+
* @return Chat response.
|
|
32
|
+
*/
|
|
33
|
+
chat(chatRequest: ChatRequest): Promise<ResponseEntity<ChatResponse>>;
|
|
34
|
+
/**
|
|
35
|
+
* Streaming response for the chat completion request.
|
|
36
|
+
* @param chatRequest Chat request. The request must set the stream property to true.
|
|
37
|
+
* @return Chat response as a {@link Flux} stream.
|
|
38
|
+
*/
|
|
39
|
+
streamingChat(chatRequest: ChatRequest): Promise<Observable<ResponseEntity<ChatResponse>>>;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-protocol.js","sourceRoot":"","sources":["../../../src/common/api/api-protocol.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { AnthropicMessage } from './message.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tool description.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Tool {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the tool.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* A description of the tool.
|
|
12
|
+
*/
|
|
13
|
+
description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The input schema of the tool.
|
|
16
|
+
*/
|
|
17
|
+
inputSchema: Record<string, any>;
|
|
18
|
+
constructor(name: string, description: string, inputSchema: Record<string, any>);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Metadata about the request.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Metadata {
|
|
24
|
+
/**
|
|
25
|
+
* An external identifier for the user who is associated with the
|
|
26
|
+
* request. This should be a uuid, hash value, or other opaque identifier.
|
|
27
|
+
* Anthropic may use this id to help detect abuse. Do not include any identifying
|
|
28
|
+
* information such as name, email address, or phone number.
|
|
29
|
+
*/
|
|
30
|
+
userId: string;
|
|
31
|
+
constructor(userId: string);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Chat completion request object.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ChatRequest {
|
|
37
|
+
/**
|
|
38
|
+
* The model that will complete your prompt. See the list of
|
|
39
|
+
* <a href="https://docs.anthropic.com/claude/docs/models-overview">models</a> for
|
|
40
|
+
* additional details and options.
|
|
41
|
+
*/
|
|
42
|
+
model: string;
|
|
43
|
+
/**
|
|
44
|
+
* Input messages.
|
|
45
|
+
*/
|
|
46
|
+
messages: AnthropicMessage[];
|
|
47
|
+
/**
|
|
48
|
+
* System prompt. A system prompt is a way of providing context and
|
|
49
|
+
* instructions to Claude, such as specifying a particular goal or role. See our
|
|
50
|
+
* <a href="https://docs.anthropic.com/claude/docs/system-prompts">guide</a> to system
|
|
51
|
+
* prompts.
|
|
52
|
+
*/
|
|
53
|
+
system?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The maximum number of tokens to generate before stopping. Note
|
|
56
|
+
* that our models may stop before reaching this maximum. This parameter only
|
|
57
|
+
* specifies the absolute maximum number of tokens to generate. Different models have
|
|
58
|
+
* different maximum values for this parameter.
|
|
59
|
+
*/
|
|
60
|
+
maxTokens: number;
|
|
61
|
+
/**
|
|
62
|
+
* An object describing metadata about the request.
|
|
63
|
+
*/
|
|
64
|
+
metadata?: Metadata;
|
|
65
|
+
/**
|
|
66
|
+
* Custom text sequences that will cause the model to stop
|
|
67
|
+
* generating. Our models will normally stop when they have naturally completed their
|
|
68
|
+
* turn, which will result in a response stop_reason of "end_turn". If you want the
|
|
69
|
+
* model to stop generating when it encounters custom strings of text, you can use the
|
|
70
|
+
* stop_sequences parameter. If the model encounters one of the custom sequences, the
|
|
71
|
+
* response stop_reason value will be "stop_sequence" and the response stop_sequence
|
|
72
|
+
* value will contain the matched stop sequence.
|
|
73
|
+
*/
|
|
74
|
+
stopSequences?: string[];
|
|
75
|
+
/**
|
|
76
|
+
* Whether to incrementally stream the response using server-sent
|
|
77
|
+
* events.
|
|
78
|
+
*/
|
|
79
|
+
stream: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Amount of randomness injected into the response.Defaults to 1.0.
|
|
82
|
+
* Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple
|
|
83
|
+
* choice, and closer to 1.0 for creative and generative tasks. Note that even with
|
|
84
|
+
* temperature of 0.0, the results will not be fully deterministic.
|
|
85
|
+
*/
|
|
86
|
+
temperature?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Use nucleus sampling. In nucleus sampling, we compute the cumulative
|
|
89
|
+
* distribution over all the options for each subsequent token in decreasing
|
|
90
|
+
* probability order and cut it off once it reaches a particular probability specified
|
|
91
|
+
* by top_p. You should either alter temperature or top_p, but not both. Recommended
|
|
92
|
+
* for advanced use cases only. You usually only need to use temperature.
|
|
93
|
+
*/
|
|
94
|
+
topP?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Only sample from the top K options for each subsequent token. Used to
|
|
97
|
+
* remove "long tail" low probability responses. Learn more technical details here.
|
|
98
|
+
* Recommended for advanced use cases only. You usually only need to use temperature.
|
|
99
|
+
*/
|
|
100
|
+
topK?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Definitions of tools that the model may use. If provided the model may
|
|
103
|
+
* return tool_use content blocks that represent the model's use of those tools. You
|
|
104
|
+
* can then run those tools using the tool input generated by the model and then
|
|
105
|
+
* optionally return results back to the model using tool_result content blocks.
|
|
106
|
+
*/
|
|
107
|
+
tools?: Tool[];
|
|
108
|
+
/**
|
|
109
|
+
* An optional signal to abort the request.
|
|
110
|
+
*/
|
|
111
|
+
signal?: AbortSignal;
|
|
112
|
+
constructor(model: string, messages: AnthropicMessage[], system: string | undefined, maxTokens: number, temperature: number | undefined, stream: boolean, metadata?: Metadata, stopSequences?: string[], topP?: number, topK?: number, tools?: Tool[], signal?: AbortSignal);
|
|
113
|
+
/**
|
|
114
|
+
* Builder class for ChatRequest
|
|
115
|
+
*/
|
|
116
|
+
static builder(): ChatRequestBuilder;
|
|
117
|
+
static from(request: ChatRequest): ChatRequestBuilder;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Builder interface for ChatRequest
|
|
121
|
+
*/
|
|
122
|
+
export declare class ChatRequestBuilder {
|
|
123
|
+
private model;
|
|
124
|
+
private messages;
|
|
125
|
+
private system?;
|
|
126
|
+
private maxTokens;
|
|
127
|
+
private metadata?;
|
|
128
|
+
private stopSequences?;
|
|
129
|
+
private stream;
|
|
130
|
+
private temperature?;
|
|
131
|
+
private topP?;
|
|
132
|
+
private topK?;
|
|
133
|
+
private tools?;
|
|
134
|
+
private signal?;
|
|
135
|
+
constructor(request?: ChatRequest);
|
|
136
|
+
withMessages(messages: AnthropicMessage[]): ChatRequestBuilder;
|
|
137
|
+
withStream(stream: boolean): ChatRequestBuilder;
|
|
138
|
+
withModel(model: string): ChatRequestBuilder;
|
|
139
|
+
withSystem(system: string): ChatRequestBuilder;
|
|
140
|
+
withStopSequences(stopSequences: string[]): ChatRequestBuilder;
|
|
141
|
+
withMaxTokens(maxTokens: number): ChatRequestBuilder;
|
|
142
|
+
withTemperature(temperature: number): ChatRequestBuilder;
|
|
143
|
+
withTopP(topP: number): ChatRequestBuilder;
|
|
144
|
+
withTopK(topK: number): ChatRequestBuilder;
|
|
145
|
+
withMetadata(metadata: Metadata): ChatRequestBuilder;
|
|
146
|
+
withTools(tools: Tool[]): ChatRequestBuilder;
|
|
147
|
+
withSignal(signal: AbortSignal): ChatRequestBuilder;
|
|
148
|
+
build(): ChatRequest;
|
|
149
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
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 { Type, Expose, Exclude } from 'class-transformer';
|
|
11
|
+
import { AnthropicMessage } from './message.js';
|
|
12
|
+
/**
|
|
13
|
+
* Tool description.
|
|
14
|
+
*/
|
|
15
|
+
export class Tool {
|
|
16
|
+
constructor(name, description, inputSchema) {
|
|
17
|
+
this.name = name;
|
|
18
|
+
this.description = description;
|
|
19
|
+
this.inputSchema = inputSchema;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Metadata about the request.
|
|
24
|
+
*/
|
|
25
|
+
export class Metadata {
|
|
26
|
+
constructor(userId) {
|
|
27
|
+
this.userId = userId;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
__decorate([
|
|
31
|
+
Expose({ name: 'user_id' }),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], Metadata.prototype, "userId", void 0);
|
|
34
|
+
/**
|
|
35
|
+
* Chat completion request object.
|
|
36
|
+
*/
|
|
37
|
+
export class ChatRequest {
|
|
38
|
+
constructor(model, messages, system, maxTokens, temperature, stream, metadata, stopSequences, topP, topK, tools, signal) {
|
|
39
|
+
this.model = model;
|
|
40
|
+
this.messages = messages;
|
|
41
|
+
this.system = system;
|
|
42
|
+
this.maxTokens = maxTokens;
|
|
43
|
+
this.metadata = metadata;
|
|
44
|
+
this.stopSequences = stopSequences;
|
|
45
|
+
this.stream = stream;
|
|
46
|
+
this.temperature = temperature;
|
|
47
|
+
this.topP = topP;
|
|
48
|
+
this.topK = topK;
|
|
49
|
+
this.tools = tools;
|
|
50
|
+
this.signal = signal;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Builder class for ChatRequest
|
|
54
|
+
*/
|
|
55
|
+
static builder() {
|
|
56
|
+
return new ChatRequestBuilder();
|
|
57
|
+
}
|
|
58
|
+
static from(request) {
|
|
59
|
+
return new ChatRequestBuilder(request);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
__decorate([
|
|
63
|
+
Expose(),
|
|
64
|
+
__metadata("design:type", String)
|
|
65
|
+
], ChatRequest.prototype, "model", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
Type(() => AnthropicMessage),
|
|
68
|
+
Expose(),
|
|
69
|
+
__metadata("design:type", Array)
|
|
70
|
+
], ChatRequest.prototype, "messages", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
Expose(),
|
|
73
|
+
__metadata("design:type", String)
|
|
74
|
+
], ChatRequest.prototype, "system", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
Expose({ name: 'max_tokens' }),
|
|
77
|
+
__metadata("design:type", Number)
|
|
78
|
+
], ChatRequest.prototype, "maxTokens", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
Expose(),
|
|
81
|
+
__metadata("design:type", Metadata)
|
|
82
|
+
], ChatRequest.prototype, "metadata", void 0);
|
|
83
|
+
__decorate([
|
|
84
|
+
Expose({ name: 'stop_sequences' }),
|
|
85
|
+
__metadata("design:type", Array)
|
|
86
|
+
], ChatRequest.prototype, "stopSequences", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
Expose(),
|
|
89
|
+
__metadata("design:type", Boolean)
|
|
90
|
+
], ChatRequest.prototype, "stream", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
Expose(),
|
|
93
|
+
__metadata("design:type", Number)
|
|
94
|
+
], ChatRequest.prototype, "temperature", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
Expose({ name: 'top_p' }),
|
|
97
|
+
__metadata("design:type", Number)
|
|
98
|
+
], ChatRequest.prototype, "topP", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
Expose({ name: 'top_k' }),
|
|
101
|
+
__metadata("design:type", Number)
|
|
102
|
+
], ChatRequest.prototype, "topK", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
Type(() => Tool),
|
|
105
|
+
__metadata("design:type", Array)
|
|
106
|
+
], ChatRequest.prototype, "tools", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
Exclude(),
|
|
109
|
+
__metadata("design:type", AbortSignal)
|
|
110
|
+
], ChatRequest.prototype, "signal", void 0);
|
|
111
|
+
/**
|
|
112
|
+
* Builder interface for ChatRequest
|
|
113
|
+
*/
|
|
114
|
+
export class ChatRequestBuilder {
|
|
115
|
+
constructor(request) {
|
|
116
|
+
this.stream = false;
|
|
117
|
+
if (request) {
|
|
118
|
+
this.model = request.model;
|
|
119
|
+
this.messages = request.messages;
|
|
120
|
+
this.system = request.system;
|
|
121
|
+
this.maxTokens = request.maxTokens;
|
|
122
|
+
this.metadata = request.metadata;
|
|
123
|
+
this.stopSequences = request.stopSequences;
|
|
124
|
+
this.stream = request.stream;
|
|
125
|
+
this.temperature = request.temperature;
|
|
126
|
+
this.topP = request.topP;
|
|
127
|
+
this.topK = request.topK;
|
|
128
|
+
this.tools = request.tools;
|
|
129
|
+
this.signal = request.signal;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
withMessages(messages) {
|
|
133
|
+
this.messages = messages;
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
withStream(stream) {
|
|
137
|
+
this.stream = stream;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
withModel(model) {
|
|
141
|
+
this.model = model;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
withSystem(system) {
|
|
145
|
+
this.system = system;
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
withStopSequences(stopSequences) {
|
|
149
|
+
this.stopSequences = stopSequences;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
withMaxTokens(maxTokens) {
|
|
153
|
+
this.maxTokens = maxTokens;
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
withTemperature(temperature) {
|
|
157
|
+
this.temperature = temperature;
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
withTopP(topP) {
|
|
161
|
+
this.topP = topP;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
withTopK(topK) {
|
|
165
|
+
this.topK = topK;
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
withMetadata(metadata) {
|
|
169
|
+
this.metadata = metadata;
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
withTools(tools) {
|
|
173
|
+
this.tools = tools;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
withSignal(signal) {
|
|
177
|
+
this.signal = signal;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
build() {
|
|
181
|
+
return new ChatRequest(this.model, this.messages, this.system, this.maxTokens, this.temperature, this.stream, this.metadata, this.stopSequences, this.topP, this.topK, this.tools, this.signal);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=chat-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-request.js","sourceRo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,IAAI,GAAG,IAAI,CAAC;QACjB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,QAAQ,CAAC,IAAY;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,YAAY,CAAC,QAAkB;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,SAAS,CAAC,KAAa;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,UAAU,CAAC,MAAmB;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK;QACD,OAAO,IAAI,WAAW,CAClB,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,MAAM,CACd,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Role } from './message.js';
|
|
2
|
+
import { ContentBlock } from './content-block.js';
|
|
3
|
+
import { Usage } from './usage.js';
|
|
4
|
+
/**
|
|
5
|
+
* Chat completion response object.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ChatResponse {
|
|
8
|
+
/**
|
|
9
|
+
* Unique object identifier. The format and length of IDs may change over
|
|
10
|
+
* time.
|
|
11
|
+
*/
|
|
12
|
+
id: string;
|
|
13
|
+
/**
|
|
14
|
+
* Object type. For Messages, this is always "message".
|
|
15
|
+
*/
|
|
16
|
+
type: string;
|
|
17
|
+
/**
|
|
18
|
+
* Conversational role of the generated message. This will always be
|
|
19
|
+
* "assistant".
|
|
20
|
+
*/
|
|
21
|
+
role: Role;
|
|
22
|
+
/**
|
|
23
|
+
* Content generated by the model. This is an array of content blocks.
|
|
24
|
+
*/
|
|
25
|
+
content: ContentBlock[];
|
|
26
|
+
/**
|
|
27
|
+
* The model that handled the request.
|
|
28
|
+
*/
|
|
29
|
+
model: string;
|
|
30
|
+
/**
|
|
31
|
+
* The reason the model stopped generating tokens. This will be one
|
|
32
|
+
* of "end_turn", "max_tokens", "stop_sequence", "tool_use", or "timeout".
|
|
33
|
+
*/
|
|
34
|
+
stopReason: string;
|
|
35
|
+
/**
|
|
36
|
+
* Which custom stop sequence was generated, if any.
|
|
37
|
+
*/
|
|
38
|
+
stopSequence?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Input and output token usage.
|
|
41
|
+
*/
|
|
42
|
+
usage: Usage;
|
|
43
|
+
constructor(id: string, type: string, role: Role, content: ContentBlock[], model: string, stopReason: string, stopSequence: string | undefined, usage: any);
|
|
44
|
+
static builder(): ChatResponseBuilder;
|
|
45
|
+
}
|
|
46
|
+
export declare class ChatResponseBuilder {
|
|
47
|
+
private type;
|
|
48
|
+
private id;
|
|
49
|
+
private role;
|
|
50
|
+
private content;
|
|
51
|
+
private model;
|
|
52
|
+
private stopReason;
|
|
53
|
+
private stopSequence?;
|
|
54
|
+
private usage;
|
|
55
|
+
constructor();
|
|
56
|
+
withType(type: string): ChatResponseBuilder;
|
|
57
|
+
withId(id: string): ChatResponseBuilder;
|
|
58
|
+
withRole(role: Role): ChatResponseBuilder;
|
|
59
|
+
withContent(content: ContentBlock[]): ChatResponseBuilder;
|
|
60
|
+
withModel(model: string): ChatResponseBuilder;
|
|
61
|
+
withStopReason(stopReason: string): ChatResponseBuilder;
|
|
62
|
+
withStopSequence(stopSequence: string): ChatResponseBuilder;
|
|
63
|
+
withUsage(usage: Usage): ChatResponseBuilder;
|
|
64
|
+
withOutputTokens(outputTokens: number): ChatResponseBuilder;
|
|
65
|
+
build(): ChatResponse;
|
|
66
|
+
}
|
|
67
|
+
export declare class ChatResponseBuilderReference {
|
|
68
|
+
private static instance;
|
|
69
|
+
static get(): ChatResponseBuilder;
|
|
70
|
+
static reset(): void;
|
|
71
|
+
}
|