@celljs/ai-anthropic 3.4.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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -0
  3. package/lib/common/api/anthropic-api.d.ts +16 -0
  4. package/lib/common/api/anthropic-api.d.ts.map +1 -0
  5. package/lib/common/api/anthropic-api.js +76 -0
  6. package/lib/common/api/anthropic-api.js.map +1 -0
  7. package/lib/common/api/anthropic-api.spec.d.ts +2 -0
  8. package/lib/common/api/anthropic-api.spec.d.ts.map +1 -0
  9. package/lib/common/api/anthropic-api.spec.js +146 -0
  10. package/lib/common/api/anthropic-api.spec.js.map +1 -0
  11. package/lib/common/api/anthropic-model.d.ts +34 -0
  12. package/lib/common/api/anthropic-model.d.ts.map +1 -0
  13. package/lib/common/api/anthropic-model.js +39 -0
  14. package/lib/common/api/anthropic-model.js.map +1 -0
  15. package/lib/common/api/api-protocol.d.ts +40 -0
  16. package/lib/common/api/api-protocol.d.ts.map +1 -0
  17. package/lib/common/api/api-protocol.js +6 -0
  18. package/lib/common/api/api-protocol.js.map +1 -0
  19. package/lib/common/api/chat-request.d.ts +144 -0
  20. package/lib/common/api/chat-request.d.ts.map +1 -0
  21. package/lib/common/api/chat-request.js +151 -0
  22. package/lib/common/api/chat-request.js.map +1 -0
  23. package/lib/common/api/chat-response.d.ts +72 -0
  24. package/lib/common/api/chat-response.d.ts.map +1 -0
  25. package/lib/common/api/chat-response.js +96 -0
  26. package/lib/common/api/chat-response.js.map +1 -0
  27. package/lib/common/api/content-block.d.ts +100 -0
  28. package/lib/common/api/content-block.d.ts.map +1 -0
  29. package/lib/common/api/content-block.js +84 -0
  30. package/lib/common/api/content-block.js.map +1 -0
  31. package/lib/common/api/event.d.ts +188 -0
  32. package/lib/common/api/event.d.ts.map +1 -0
  33. package/lib/common/api/event.js +249 -0
  34. package/lib/common/api/event.js.map +1 -0
  35. package/lib/common/api/index.d.ts +10 -0
  36. package/lib/common/api/index.d.ts.map +1 -0
  37. package/lib/common/api/index.js +13 -0
  38. package/lib/common/api/index.js.map +1 -0
  39. package/lib/common/api/message.d.ts +41 -0
  40. package/lib/common/api/message.d.ts.map +1 -0
  41. package/lib/common/api/message.js +45 -0
  42. package/lib/common/api/message.js.map +1 -0
  43. package/lib/common/api/usage.d.ts +15 -0
  44. package/lib/common/api/usage.d.ts.map +1 -0
  45. package/lib/common/api/usage.js +24 -0
  46. package/lib/common/api/usage.js.map +1 -0
  47. package/lib/common/index.d.ts +3 -0
  48. package/lib/common/index.d.ts.map +1 -0
  49. package/lib/common/index.js +6 -0
  50. package/lib/common/index.js.map +1 -0
  51. package/lib/common/model/anthropic-chat-model.d.ts +20 -0
  52. package/lib/common/model/anthropic-chat-model.d.ts.map +1 -0
  53. package/lib/common/model/anthropic-chat-model.js +161 -0
  54. package/lib/common/model/anthropic-chat-model.js.map +1 -0
  55. package/lib/common/model/anthropic-chat-model.spec.d.ts +2 -0
  56. package/lib/common/model/anthropic-chat-model.spec.d.ts.map +1 -0
  57. package/lib/common/model/anthropic-chat-model.spec.js +64 -0
  58. package/lib/common/model/anthropic-chat-model.spec.js.map +1 -0
  59. package/lib/common/model/anthropic-chat-options.d.ts +55 -0
  60. package/lib/common/model/anthropic-chat-options.d.ts.map +1 -0
  61. package/lib/common/model/anthropic-chat-options.js +157 -0
  62. package/lib/common/model/anthropic-chat-options.js.map +1 -0
  63. package/lib/common/model/index.d.ts +3 -0
  64. package/lib/common/model/index.d.ts.map +1 -0
  65. package/lib/common/model/index.js +6 -0
  66. package/lib/common/model/index.js.map +1 -0
  67. package/lib/common/module.d.ts +4 -0
  68. package/lib/common/module.d.ts.map +1 -0
  69. package/lib/common/module.js +6 -0
  70. package/lib/common/module.js.map +1 -0
  71. package/lib/common/test/mock-anthropic-api.d.ts +9 -0
  72. package/lib/common/test/mock-anthropic-api.d.ts.map +1 -0
  73. package/lib/common/test/mock-anthropic-api.js +46 -0
  74. package/lib/common/test/mock-anthropic-api.js.map +1 -0
  75. package/lib/common/test/test-container.d.ts +3 -0
  76. package/lib/common/test/test-container.d.ts.map +1 -0
  77. package/lib/common/test/test-container.js +15 -0
  78. package/lib/common/test/test-container.js.map +1 -0
  79. package/lib/common/utils/index.d.ts +2 -0
  80. package/lib/common/utils/index.d.ts.map +1 -0
  81. package/lib/common/utils/index.js +5 -0
  82. package/lib/common/utils/index.js.map +1 -0
  83. package/lib/common/utils/stream-util.d.ts +9 -0
  84. package/lib/common/utils/stream-util.d.ts.map +1 -0
  85. package/lib/common/utils/stream-util.js +114 -0
  86. package/lib/common/utils/stream-util.js.map +1 -0
  87. package/lib/package.spec.d.ts +1 -0
  88. package/lib/package.spec.d.ts.map +1 -0
  89. package/lib/package.spec.js +4 -0
  90. package/lib/package.spec.js.map +1 -0
  91. package/package.json +46 -0
  92. package/src/common/api/anthropic-api.spec.ts +165 -0
  93. package/src/common/api/anthropic-api.ts +90 -0
  94. package/src/common/api/anthropic-model.ts +42 -0
  95. package/src/common/api/api-protocol.ts +45 -0
  96. package/src/common/api/chat-request.ts +280 -0
  97. package/src/common/api/chat-response.ts +161 -0
  98. package/src/common/api/content-block.ts +155 -0
  99. package/src/common/api/event.ts +376 -0
  100. package/src/common/api/index.ts +9 -0
  101. package/src/common/api/message.ts +49 -0
  102. package/src/common/api/usage.ts +24 -0
  103. package/src/common/index.ts +2 -0
  104. package/src/common/model/anthropic-chat-model.spec.ts +67 -0
  105. package/src/common/model/anthropic-chat-model.ts +187 -0
  106. package/src/common/model/anthropic-chat-options.ts +152 -0
  107. package/src/common/model/index.ts +2 -0
  108. package/src/common/module.ts +4 -0
  109. package/src/common/test/mock-anthropic-api.ts +62 -0
  110. package/src/common/test/test-container.ts +12 -0
  111. package/src/common/utils/index.ts +1 -0
  112. package/src/common/utils/stream-util.ts +142 -0
  113. package/src/package.spec.ts +4 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Cellbang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Cell - AI Anthropic Component
2
+
3
+ ## 概览
4
+
5
+ AI Anthropic 模块是一个用于与 Anthropic API 交互的库,提供了生成聊天响应和嵌入向量的功能。通过简单易用的 API 接口,支持消息的创建、请求的发送和响应的处理。是 @celljs/ai-core 模块中所有模型服务接口抽象的一种实现。
6
+
7
+ ## 特性
8
+
9
+ - 生成聊天响应
10
+ - 生成嵌入向量
11
+ - 支持流式响应
12
+ - 支持多种模型参数配置
13
+
14
+ ## 安装
15
+
16
+ 使用 npm 安装 AI Anthropic 模块:
17
+
18
+ ```bash
19
+ npm install @celljs/ai-anthropic
20
+ ```
21
+
22
+ 或者使用 yarn:
23
+
24
+ ```bash
25
+ yarn add @celljs/ai-anthropic
26
+ ```
27
+
28
+ ## 快速开始
29
+
30
+ 以下是一个简单的示例,展示如何使用 AI Anthropic 模块生成聊天响应:
31
+
32
+ ```typescript
33
+ import { AssistantMessage, PromptTemplate } from '@celljs/ai-core';
34
+ import { OllamChatModel, OllamModel, } from '@celljs/ai-anthropic';
35
+ import { Component Autowired } from '@celljs/core';
36
+
37
+ @Component()
38
+ export class AnthropicDemo {
39
+ @Autowired(AnthropicChatModel)
40
+ private anthropicChatModel: AnthropicChatModel;
41
+
42
+ @Autowired(PromptTemplate)
43
+ private promptTemplate: PromptTemplate;
44
+
45
+ /**
46
+ * Chat with Anthropic
47
+ */
48
+ async chat() {
49
+ const prompt = await this.promptTemplate.create(
50
+ 'Hello {name}',
51
+ {
52
+ chatOptions: { model: AnthropicModel.CLAUDE_3_5_SONNET },
53
+ variables: { name: 'Anthropic' }
54
+ }
55
+ );
56
+ const response = await this.anthropicChatModel.call(prompt);
57
+ console.log(response.result.output);
58
+ }
59
+
60
+ /**
61
+ * Stream chat response
62
+ */
63
+ async stream() {
64
+ const prompt = await this.promptTemplate.create(
65
+ 'Hello {name}',
66
+ {
67
+ chatOptions: { model: AnthropicModel.CLAUDE_3_5_SONNET },
68
+ variables: { name: 'Anthropic' }
69
+ }
70
+ );
71
+ const response$ = await this.anthropicChatModel.stream(prompt);
72
+ response$.subscribe({
73
+ next: response => console.log(response.result.output),
74
+ complete: () => console.log('Chat completed!')
75
+ });
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## 许可证
81
+
82
+ 本项目采用 MIT 许可证。
@@ -0,0 +1,16 @@
1
+ import { Observable } from 'rxjs';
2
+ import { RestOperations } from '@celljs/http';
3
+ import { ChatRequest } from './chat-request';
4
+ import { ChatResponse } from './chat-response';
5
+ import { AnthropicAPI, AnthropicAPIOptions } from './api-protocol';
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<ChatResponse>;
14
+ streamingChat(chatRequest: ChatRequest): Promise<Observable<ChatResponse>>;
15
+ }
16
+ //# sourceMappingURL=anthropic-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-api.d.ts","sourceRoot":"","sources":["../../../src/common/api/anthropic-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAMnE,qBACa,gBAAiB,YAAW,YAAY;IAGjD,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAGlD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAIjD,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,mBAAmB,CAAC;IAExD,SAAS,KAAK,OAAO,IAAI,MAAM,CAE9B;IAED,SAAS,KAAK,MAAM,IAAI,MAAM,GAAG,SAAS,CAEzC;IAED,SAAS,KAAK,gBAAgB,IAAI,MAAM,CAEvC;IAEK,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAOrD,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;CA6CnF"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnthropicAPIImpl = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const core_1 = require("@celljs/core");
6
+ const operators_1 = require("rxjs/operators");
7
+ const http_1 = require("@celljs/http");
8
+ const chat_response_1 = require("./chat-response");
9
+ const api_protocol_1 = require("./api-protocol");
10
+ const class_transformer_1 = require("class-transformer");
11
+ const ai_core_1 = require("@celljs/ai-core");
12
+ const event_1 = require("./event");
13
+ const utils_1 = require("../utils");
14
+ let AnthropicAPIImpl = class AnthropicAPIImpl {
15
+ get baseUrl() {
16
+ var _a, _b, _c, _d;
17
+ return (_d = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.baseUrl) !== null && _b !== void 0 ? _b : (_c = this.defaultOptions) === null || _c === void 0 ? void 0 : _c.baseUrl) !== null && _d !== void 0 ? _d : 'https://api.anthropic.com';
18
+ }
19
+ get apiKey() {
20
+ var _a, _b, _c;
21
+ return (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.apiKey) !== null && _b !== void 0 ? _b : (_c = this.defaultOptions) === null || _c === void 0 ? void 0 : _c.apiKey;
22
+ }
23
+ get anthropicVersion() {
24
+ var _a, _b, _c, _d;
25
+ return (_d = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.anthropicVersion) !== null && _b !== void 0 ? _b : (_c = this.defaultOptions) === null || _c === void 0 ? void 0 : _c.anthropicVersion) !== null && _d !== void 0 ? _d : '2023-06-01';
26
+ }
27
+ async chat(chatRequest) {
28
+ core_1.Assert.isTrue(!chatRequest.stream, 'Request must set the stream property to false.');
29
+ const { data } = await this.restOperations
30
+ .post('/v1/messages', (0, class_transformer_1.instanceToPlain)(chatRequest), { baseURL: this.baseUrl });
31
+ return (0, class_transformer_1.plainToInstance)(chat_response_1.ChatResponse, data);
32
+ }
33
+ async streamingChat(chatRequest) {
34
+ core_1.Assert.isTrue(chatRequest.stream, 'Request must set the stream property to true.');
35
+ const { data } = await this.restOperations
36
+ .post('/v1/messages', (0, class_transformer_1.instanceToPlain)(chatRequest), {
37
+ baseURL: this.baseUrl,
38
+ headers: {
39
+ 'Accept': 'text/event-stream',
40
+ },
41
+ responseType: 'stream'
42
+ });
43
+ let isInsideTool = false;
44
+ return ai_core_1.SSEUtil.toObservable(data)
45
+ .pipe((0, operators_1.map)(item => (0, class_transformer_1.plainToInstance)(event_1.AnthropicStreamEvent, item)), (0, operators_1.filter)(item => item.data.type !== event_1.EventType.PING), (0, operators_1.map)(item => {
46
+ if (utils_1.StreamUtil.isToolUseStart(item.data)) {
47
+ isInsideTool = true;
48
+ }
49
+ return item;
50
+ }), (0, operators_1.groupBy)(item => {
51
+ if (isInsideTool && utils_1.StreamUtil.isToolUseFinish(item.data)) {
52
+ isInsideTool = false;
53
+ return true;
54
+ }
55
+ return !isInsideTool;
56
+ }), (0, operators_1.concatMap)(group => group.pipe((0, operators_1.reduce)((acc, curr) => utils_1.StreamUtil.mergeToolUseEvents(acc, curr.data), new event_1.ToolUseAggregationEvent()))), (0, operators_1.map)(event => utils_1.StreamUtil.eventToChatResponse(event)), (0, operators_1.filter)(response => !!response.type));
57
+ }
58
+ };
59
+ tslib_1.__decorate([
60
+ (0, core_1.Autowired)(http_1.RestOperations),
61
+ tslib_1.__metadata("design:type", Function)
62
+ ], AnthropicAPIImpl.prototype, "restOperations", void 0);
63
+ tslib_1.__decorate([
64
+ (0, core_1.Value)('cell.ai.anthropic.api'),
65
+ tslib_1.__metadata("design:type", Object)
66
+ ], AnthropicAPIImpl.prototype, "options", void 0);
67
+ tslib_1.__decorate([
68
+ (0, core_1.Autowired)(api_protocol_1.AnthropicAPIOptions),
69
+ (0, core_1.Optional)(),
70
+ tslib_1.__metadata("design:type", Object)
71
+ ], AnthropicAPIImpl.prototype, "defaultOptions", void 0);
72
+ AnthropicAPIImpl = tslib_1.__decorate([
73
+ (0, core_1.Component)(api_protocol_1.AnthropicAPI)
74
+ ], AnthropicAPIImpl);
75
+ exports.AnthropicAPIImpl = AnthropicAPIImpl;
76
+ //# 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,uCAA6E;AAE7E,8CAA0E;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AAC,QAAQ,CAAC,IAAI,CAAC,CACtC,CAAC;IAEV,CAAC;CACJ,CAAA;AA1EG;IAAC,IAAA,gBAAS,EAAC,qBAAc,CAAC;;wDACwB;AAElD;IAAC,IAAA,YAAK,EAAC,uBAAuB,CAAC;;iDACkB;AAEjD;IAAC,IAAA,gBAAS,EAAC,kCAAmB,CAAC;IAC9B,IAAA,eAAQ,GAAE;;wDAC6C;AAV/C,gBAAgB;IAD5B,IAAA,gBAAS,EAAC,2BAAY,CAAC;GACX,gBAAgB,CA4E5B;AA5EY,4CAAgB"}
@@ -0,0 +1,2 @@
1
+ import '../index';
2
+ //# sourceMappingURL=anthropic-api.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-api.spec.d.ts","sourceRoot":"","sources":["../../../src/common/api/anthropic-api.spec.ts"],"names":[],"mappings":"AASA,OAAO,UAAU,CAAC"}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const chat_request_1 = require("./chat-request");
5
+ const http_1 = require("@celljs/http");
6
+ const test_container_1 = require("../test/test-container");
7
+ const api_protocol_1 = require("./api-protocol");
8
+ const anthropic_model_1 = require("./anthropic-model");
9
+ const content_block_1 = require("./content-block");
10
+ const message_1 = require("./message");
11
+ const chat_response_1 = require("./chat-response");
12
+ require("../index");
13
+ const container = (0, test_container_1.createContainer)();
14
+ describe('AnthropicAPIImpl', () => {
15
+ let anthropicAPI;
16
+ beforeEach(() => {
17
+ container.rebind(http_1.RestOperations).toConstantValue({
18
+ post: async (url, data, config) => {
19
+ if (data.stream) {
20
+ const chatResponse = {
21
+ id: 'msg_123',
22
+ type: 'message',
23
+ role: message_1.Role.ASSISTANT,
24
+ content: [
25
+ {
26
+ type: content_block_1.ContentBlockType.TEXT,
27
+ text: 'How can I assist you today?'
28
+ }
29
+ ],
30
+ model: data.model,
31
+ stop_reason: 'end_turn',
32
+ stop_sequence: undefined,
33
+ usage: {
34
+ input_tokens: 10,
35
+ output_tokens: 20
36
+ }
37
+ };
38
+ const steam = new ReadableStream({
39
+ start(controller) {
40
+ controller.enqueue('data: ' + JSON.stringify({
41
+ type: 'message_start',
42
+ data: chatResponse
43
+ }) + '\n\n');
44
+ controller.close();
45
+ }
46
+ });
47
+ return { data: steam };
48
+ }
49
+ return {
50
+ data: {
51
+ id: 'msg_123',
52
+ type: 'message',
53
+ role: message_1.Role.ASSISTANT,
54
+ content: [
55
+ {
56
+ type: content_block_1.ContentBlockType.TEXT,
57
+ text: 'How can I assist you today?'
58
+ }
59
+ ],
60
+ model: data.model,
61
+ stop_reason: 'end_turn',
62
+ stop_sequence: undefined,
63
+ usage: {
64
+ input_tokens: 10,
65
+ output_tokens: 20
66
+ }
67
+ }
68
+ };
69
+ }
70
+ });
71
+ anthropicAPI = container.get(api_protocol_1.AnthropicAPI);
72
+ });
73
+ describe('chat', () => {
74
+ it('should return a ChatResponse', async () => {
75
+ const messages = [
76
+ new message_1.AnthropicMessage([new content_block_1.ContentBlock(content_block_1.ContentBlockType.TEXT, undefined, 'Hello')], message_1.Role.USER)
77
+ ];
78
+ const chatRequest = chat_request_1.ChatRequest.builder()
79
+ .withModel(anthropic_model_1.AnthropicModel.CLAUDE_3_HAIKU)
80
+ .withMessages(messages)
81
+ .withMaxTokens(1000)
82
+ .withStream(false)
83
+ .build();
84
+ const response = await anthropicAPI.chat(chatRequest);
85
+ (0, chai_1.expect)(response).to.be.instanceOf(chat_response_1.ChatResponse);
86
+ (0, chai_1.expect)(response.model).to.equal(anthropic_model_1.AnthropicModel.CLAUDE_3_HAIKU);
87
+ });
88
+ it('should throw an error if stream mode is enabled', async () => {
89
+ const messages = [
90
+ new message_1.AnthropicMessage([new content_block_1.ContentBlock(content_block_1.ContentBlockType.TEXT, undefined, 'Hello')], message_1.Role.USER)
91
+ ];
92
+ const chatRequest = chat_request_1.ChatRequest.builder()
93
+ .withModel(anthropic_model_1.AnthropicModel.CLAUDE_3_HAIKU)
94
+ .withMessages(messages)
95
+ .withMaxTokens(1000)
96
+ .withStream(true)
97
+ .build();
98
+ try {
99
+ await anthropicAPI.chat(chatRequest);
100
+ chai_1.expect.fail('Should have thrown an error');
101
+ }
102
+ catch (e) {
103
+ (0, chai_1.expect)(e.message).to.equal('Request must set the stream property to false.');
104
+ }
105
+ });
106
+ });
107
+ describe('streamingChat', () => {
108
+ it('should return an Observable of ChatResponse', async () => {
109
+ const messages = [
110
+ new message_1.AnthropicMessage([new content_block_1.ContentBlock(content_block_1.ContentBlockType.TEXT, undefined, 'Hello')], message_1.Role.USER)
111
+ ];
112
+ const chatRequest = chat_request_1.ChatRequest.builder()
113
+ .withModel(anthropic_model_1.AnthropicModel.CLAUDE_3_HAIKU)
114
+ .withMessages(messages)
115
+ .withMaxTokens(1000)
116
+ .withStream(true)
117
+ .build();
118
+ const response$ = await anthropicAPI.streamingChat(chatRequest);
119
+ response$.subscribe({
120
+ next: response => {
121
+ (0, chai_1.expect)(response).to.be.instanceOf(chat_response_1.ChatResponse);
122
+ (0, chai_1.expect)(response.model).to.equal(anthropic_model_1.AnthropicModel.CLAUDE_3_HAIKU);
123
+ }
124
+ });
125
+ });
126
+ it('should throw an error if stream mode is disabled', async () => {
127
+ const messages = [
128
+ new message_1.AnthropicMessage([new content_block_1.ContentBlock(content_block_1.ContentBlockType.TEXT, undefined, 'Hello')], message_1.Role.USER)
129
+ ];
130
+ const chatRequest = chat_request_1.ChatRequest.builder()
131
+ .withModel(anthropic_model_1.AnthropicModel.CLAUDE_3_HAIKU)
132
+ .withMessages(messages)
133
+ .withMaxTokens(1000)
134
+ .withStream(false)
135
+ .build();
136
+ try {
137
+ await anthropicAPI.streamingChat(chatRequest);
138
+ chai_1.expect.fail('Should have thrown an error');
139
+ }
140
+ catch (e) {
141
+ (0, chai_1.expect)(e.message).to.equal('Request must set the stream property to true.');
142
+ }
143
+ });
144
+ });
145
+ });
146
+ //# sourceMappingURL=anthropic-api.spec.js.map
@@ -0,0 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CAA+C,CAAC,CAAC;aAC/E;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,34 @@
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
+ }
34
+ //# sourceMappingURL=anthropic-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-model.d.ts","sourceRoot":"","sources":["../../../src/common/api/anthropic-model.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,cAAc;IAEtB;;OAEG;IACH,iBAAiB,6BAA6B;IAE9C;;OAEG;IACH,aAAa,yBAAyB;IAEtC;;OAEG;IACH,eAAe,6BAA6B;IAE5C;;OAEG;IACH,gBAAgB,4BAA4B;IAE5C;;OAEG;IACH,cAAc,4BAA4B;IAG1C;;OAEG;IACH,UAAU,eAAe;IAEzB;;OAEG;IACH,QAAQ,eAAe;CAE1B"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnthropicModel = void 0;
4
+ /**
5
+ * Helper class for the Anthropic model.
6
+ */
7
+ var AnthropicModel;
8
+ (function (AnthropicModel) {
9
+ /**
10
+ * The claude-3-5-sonnet-20241022 model.
11
+ */
12
+ AnthropicModel["CLAUDE_3_5_SONNET"] = "claude-3-5-sonnet-latest";
13
+ /**
14
+ * The CLAUDE_3_OPUS
15
+ */
16
+ AnthropicModel["CLAUDE_3_OPUS"] = "claude-3-opus-latest";
17
+ /**
18
+ * The CLAUDE_3_SONNET
19
+ */
20
+ AnthropicModel["CLAUDE_3_SONNET"] = "claude-3-sonnet-20240229";
21
+ /**
22
+ * The CLAUDE 3.5 HAIKU
23
+ */
24
+ AnthropicModel["CLAUDE_3_5_HAIKU"] = "claude-3-5-haiku-latest";
25
+ /**
26
+ * The CLAUDE_3_HAIKU
27
+ */
28
+ AnthropicModel["CLAUDE_3_HAIKU"] = "claude-3-haiku-20240307";
29
+ // Legacy models
30
+ /**
31
+ * The CLAUDE_2_1
32
+ */
33
+ AnthropicModel["CLAUDE_2_1"] = "claude-2.1";
34
+ /**
35
+ * The CLAUDE_2_0
36
+ */
37
+ AnthropicModel["CLAUDE_2"] = "claude-2.0";
38
+ })(AnthropicModel = exports.AnthropicModel || (exports.AnthropicModel = {}));
39
+ //# 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,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,GAAd,sBAAc,KAAd,sBAAc,QAsCzB"}
@@ -0,0 +1,40 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ChatRequest } from './chat-request';
3
+ import { ChatResponse } from './chat-response';
4
+ export declare const AnthropicAPI: unique symbol;
5
+ export declare const AnthropicAPIOptions: unique symbol;
6
+ /**
7
+ * Anthropic API options.
8
+ */
9
+ export interface AnthropicAPIOptions {
10
+ /**
11
+ * Base URL of the Anthropic API.
12
+ */
13
+ baseUrl?: string;
14
+ /**
15
+ * API key to authenticate with the Anthropic API.
16
+ */
17
+ apiKey?: string;
18
+ /**
19
+ * Version of the Anthropic API.
20
+ */
21
+ anthropicVersion?: string;
22
+ }
23
+ export interface AnthropicAPI {
24
+ /**
25
+ * Generate the next message in a chat with a provided model.
26
+ * This is a streaming endpoint (controlled by the 'stream' request property), so
27
+ * there will be a series of responses. The final response object will include
28
+ * statistics and additional data from the request.
29
+ * @param chatRequest Chat request.
30
+ * @return Chat response.
31
+ */
32
+ chat(chatRequest: ChatRequest): Promise<ChatResponse>;
33
+ /**
34
+ * Streaming response for the chat completion request.
35
+ * @param chatRequest Chat request. The request must set the stream property to true.
36
+ * @return Chat response as a {@link Flux} stream.
37
+ */
38
+ streamingChat(chatRequest: ChatRequest): Promise<Observable<ChatResponse>>;
39
+ }
40
+ //# sourceMappingURL=api-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/api/api-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,eAAO,MAAM,YAAY,eAAyB,CAAC;AACnD,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY;IACzB;;;;;;;OAOG;IACH,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACtD;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;CAE9E"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnthropicAPIOptions = exports.AnthropicAPI = void 0;
4
+ exports.AnthropicAPI = Symbol('AnthropicAPI');
5
+ exports.AnthropicAPIOptions = Symbol('AnthropicAPIOptions');
6
+ //# sourceMappingURL=api-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-protocol.js","sourceRoot":"","sources":["../../../src/common/api/api-protocol.ts"],"names":[],"mappings":";;;AAIa,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACtC,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,144 @@
1
+ import { AnthropicMessage } from './message';
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
+ 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[]);
109
+ /**
110
+ * Builder class for ChatRequest
111
+ */
112
+ static builder(): ChatRequestBuilder;
113
+ static from(request: ChatRequest): ChatRequestBuilder;
114
+ }
115
+ /**
116
+ * Builder interface for ChatRequest
117
+ */
118
+ export declare class ChatRequestBuilder {
119
+ private model;
120
+ private messages;
121
+ private system?;
122
+ private maxTokens;
123
+ private metadata?;
124
+ private stopSequences?;
125
+ private stream;
126
+ private temperature?;
127
+ private topP?;
128
+ private topK?;
129
+ private tools?;
130
+ constructor(request?: ChatRequest);
131
+ withMessages(messages: AnthropicMessage[]): ChatRequestBuilder;
132
+ withStream(stream: boolean): ChatRequestBuilder;
133
+ withModel(model: string): ChatRequestBuilder;
134
+ withSystem(system: string): ChatRequestBuilder;
135
+ withStopSequences(stopSequences: string[]): ChatRequestBuilder;
136
+ withMaxTokens(maxTokens: number): ChatRequestBuilder;
137
+ withTemperature(temperature: number): ChatRequestBuilder;
138
+ withTopP(topP: number): ChatRequestBuilder;
139
+ withTopK(topK: number): ChatRequestBuilder;
140
+ withMetadata(metadata: Metadata): ChatRequestBuilder;
141
+ withTools(tools: Tool[]): ChatRequestBuilder;
142
+ build(): ChatRequest;
143
+ }
144
+ //# sourceMappingURL=chat-request.d.ts.map