@push.rocks/smartai 0.0.7 → 0.0.14

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 (40) hide show
  1. package/dist_ts/00_commitinfo_data.js +3 -3
  2. package/dist_ts/abstract.classes.multimodal.d.ts +24 -2
  3. package/dist_ts/abstract.classes.multimodal.js +2 -2
  4. package/dist_ts/classes.conversation.d.ts +26 -0
  5. package/dist_ts/classes.conversation.js +95 -0
  6. package/dist_ts/classes.smartai.d.ts +25 -0
  7. package/dist_ts/classes.smartai.js +41 -0
  8. package/dist_ts/classes.tts.d.ts +6 -0
  9. package/dist_ts/classes.tts.js +10 -0
  10. package/dist_ts/index.d.ts +1 -1
  11. package/dist_ts/index.js +2 -2
  12. package/dist_ts/interfaces.d.ts +1 -0
  13. package/dist_ts/interfaces.js +2 -0
  14. package/dist_ts/plugins.d.ts +8 -3
  15. package/dist_ts/plugins.js +9 -4
  16. package/dist_ts/provider.anthropic.d.ts +25 -0
  17. package/dist_ts/provider.anthropic.js +41 -0
  18. package/dist_ts/provider.ollama.d.ts +2 -0
  19. package/dist_ts/provider.ollama.js +4 -0
  20. package/dist_ts/provider.openai.d.ts +33 -10
  21. package/dist_ts/provider.openai.js +63 -41
  22. package/dist_ts/provider.perplexity.d.ts +2 -0
  23. package/dist_ts/provider.perplexity.js +4 -0
  24. package/npmextra.json +16 -2
  25. package/package.json +25 -9
  26. package/readme.hints.md +1 -0
  27. package/readme.md +107 -27
  28. package/ts/00_commitinfo_data.ts +2 -2
  29. package/ts/abstract.classes.multimodal.ts +28 -4
  30. package/ts/classes.conversation.ts +116 -0
  31. package/ts/classes.smartai.ts +62 -0
  32. package/ts/classes.tts.ts +15 -0
  33. package/ts/index.ts +1 -1
  34. package/ts/interfaces.ts +0 -0
  35. package/ts/plugins.ts +12 -2
  36. package/ts/provider.anthropic.ts +62 -0
  37. package/ts/provider.ollama.ts +3 -0
  38. package/ts/provider.openai.ts +97 -51
  39. package/ts/provider.perplexity.ts +3 -0
  40. package/ts/smartai.classes.smartai.ts +0 -53
package/npmextra.json CHANGED
@@ -5,14 +5,28 @@
5
5
  "githost": "code.foss.global",
6
6
  "gitscope": "push.rocks",
7
7
  "gitrepo": "smartai",
8
- "description": "a standardaized interface to talk to AI models",
8
+ "description": "A TypeScript library for integrating and interacting with multiple AI models, offering capabilities for chat and potentially audio responses.",
9
9
  "npmPackagename": "@push.rocks/smartai",
10
10
  "license": "MIT",
11
- "projectDomain": "push.rocks"
11
+ "projectDomain": "push.rocks",
12
+ "keywords": [
13
+ "AI integration",
14
+ "chatbot",
15
+ "TypeScript",
16
+ "OpenAI",
17
+ "Anthropic",
18
+ "multi-model support",
19
+ "audio responses",
20
+ "text-to-speech",
21
+ "streaming chat"
22
+ ]
12
23
  }
13
24
  },
14
25
  "npmci": {
15
26
  "npmGlobalTools": [],
16
27
  "npmAccessLevel": "public"
28
+ },
29
+ "tsdoc": {
30
+ "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
17
31
  }
18
32
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@push.rocks/smartai",
3
- "version": "0.0.7",
3
+ "version": "0.0.14",
4
4
  "private": false,
5
- "description": "a standardaized interface to talk to AI models",
5
+ "description": "A TypeScript library for integrating and interacting with multiple AI models, offering capabilities for chat and potentially audio responses.",
6
6
  "main": "dist_ts/index.js",
7
7
  "typings": "dist_ts/index.d.ts",
8
8
  "type": "module",
@@ -12,16 +12,21 @@
12
12
  "@git.zone/tsbuild": "^2.1.25",
13
13
  "@git.zone/tsbundle": "^2.0.5",
14
14
  "@git.zone/tsrun": "^1.2.46",
15
- "@git.zone/tstest": "^1.0.44",
16
- "@push.rocks/tapbundle": "^5.0.15",
17
- "@types/node": "^20.8.7"
15
+ "@git.zone/tstest": "^1.0.90",
16
+ "@push.rocks/qenv": "^6.0.5",
17
+ "@push.rocks/tapbundle": "^5.0.23",
18
+ "@types/node": "^20.12.7"
18
19
  },
19
20
  "dependencies": {
20
- "@push.rocks/qenv": "^6.0.5",
21
- "@push.rocks/smartfile": "^11.0.4",
22
- "@push.rocks/smartpath": "^5.0.11",
21
+ "@anthropic-ai/sdk": "^0.20.7",
22
+ "@push.rocks/smartarray": "^1.0.8",
23
+ "@push.rocks/smartfile": "^11.0.14",
24
+ "@push.rocks/smartpath": "^5.0.18",
25
+ "@push.rocks/smartpdf": "^3.1.5",
23
26
  "@push.rocks/smartpromise": "^4.0.3",
24
- "openai": "^4.31.0"
27
+ "@push.rocks/smartrequest": "^2.0.22",
28
+ "@push.rocks/webstream": "^1.0.8",
29
+ "openai": "^4.38.5"
25
30
  },
26
31
  "repository": {
27
32
  "type": "git",
@@ -46,6 +51,17 @@
46
51
  "npmextra.json",
47
52
  "readme.md"
48
53
  ],
54
+ "keywords": [
55
+ "AI integration",
56
+ "chatbot",
57
+ "TypeScript",
58
+ "OpenAI",
59
+ "Anthropic",
60
+ "multi-model support",
61
+ "audio responses",
62
+ "text-to-speech",
63
+ "streaming chat"
64
+ ],
49
65
  "scripts": {
50
66
  "test": "(tstest test/ --web)",
51
67
  "build": "(tsbuild --web --allowimplicitany)",
@@ -0,0 +1 @@
1
+
package/readme.md CHANGED
@@ -1,31 +1,111 @@
1
1
  # @push.rocks/smartai
2
- a standardaized interface to talk to AI models
3
-
4
- ## Availabililty and Links
5
- * [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartai)
6
- * [gitlab.com (source)](https://code.foss.global/push.rocks/smartai)
7
- * [github.com (source mirror)](https://github.com/push.rocks/smartai)
8
- * [docs (typedoc)](https://push.rocks.gitlab.io/smartai/)
9
-
10
- ## Status for master
11
-
12
- Status Category | Status Badge
13
- -- | --
14
- GitLab Pipelines | [![pipeline status](https://code.foss.global/push.rocks/smartai/badges/master/pipeline.svg)](https://lossless.cloud)
15
- GitLab Pipline Test Coverage | [![coverage report](https://code.foss.global/push.rocks/smartai/badges/master/coverage.svg)](https://lossless.cloud)
16
- npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartai)](https://lossless.cloud)
17
- Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartai)](https://lossless.cloud)
18
- TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
19
- node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
20
- Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
21
- PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartai)](https://lossless.cloud)
22
- PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartai)](https://lossless.cloud)
23
- BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartai)](https://lossless.cloud)
2
+
3
+ Provides a standardized interface for integrating and conversing with multiple AI models, supporting operations like chat and potentially audio responses.
4
+
5
+ ## Install
6
+
7
+ To add @push.rocks/smartai to your project, run the following command in your terminal:
8
+
9
+ ```bash
10
+ npm install @push.rocks/smartai
11
+ ```
12
+
13
+ This command installs the package and adds it to your project's dependencies.
24
14
 
25
15
  ## Usage
26
- Use TypeScript for best in class intellisense
27
- For further information read the linked docs at the top of this readme.
28
16
 
29
- ## Legal
30
- > MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
31
- | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
17
+ The `@push.rocks/smartai` package is a comprehensive solution for integrating and interacting with various AI models, designed to support operations ranging from chat interactions to possibly handling audio responses. This documentation will guide you through the process of utilizing `@push.rocks/smartai` in your applications, focusing on TypeScript and ESM syntax to demonstrate its full capabilities.
18
+
19
+ ### Getting Started
20
+
21
+ Before you begin, ensure you have installed the package in your project as described in the **Install** section above. Once installed, you can start integrating AI functionalities into your application.
22
+
23
+ ### Initializing SmartAi
24
+
25
+ The first step is to import and initialize the `SmartAi` class with appropriate options, including tokens for the AI services you plan to use:
26
+
27
+ ```typescript
28
+ import { SmartAi } from '@push.rocks/smartai';
29
+
30
+ const smartAi = new SmartAi({
31
+ openaiToken: 'your-openai-access-token',
32
+ anthropicToken: 'your-anthropic-access-token'
33
+ });
34
+
35
+ await smartAi.start();
36
+ ```
37
+
38
+ ### Creating Conversations with AI
39
+
40
+ `SmartAi` provides a flexible interface to create and manage conversations with different AI providers. You can create a conversation with any supported AI provider like OpenAI or Anthropic by specifying the provider you want to use:
41
+
42
+ ```typescript
43
+ const openAiConversation = await smartAi.createConversation('openai');
44
+ const anthropicConversation = await smartAi.createConversation('anthropic');
45
+ ```
46
+
47
+ ### Chatting with AI
48
+
49
+ Once you have a conversation instance, you can start sending messages to the AI and receive responses. Each conversation object provides methods to interact in a synchronous or asynchronous manner, depending on your use case.
50
+
51
+ #### Synchronous Chat Example
52
+
53
+ Here's how you can have a synchronous chat with OpenAI:
54
+
55
+ ```typescript
56
+ const response = await openAiConversation.chat({
57
+ systemMessage: 'This is a greeting from the system.',
58
+ userMessage: 'Hello, AI! How are you today?',
59
+ messageHistory: [] // Previous messages in the conversation
60
+ });
61
+
62
+ console.log(response.message); // Log the response from AI
63
+ ```
64
+
65
+ #### Streaming Chat Example
66
+
67
+ For real-time, streaming interactions, you can utilize the streaming capabilities provided by the conversation object. This enables a continuous exchange of messages between your application and the AI:
68
+
69
+ ```typescript
70
+ const inputStreamWriter = openAiConversation.getInputStreamWriter();
71
+ const outputStream = openAiConversation.getOutputStream();
72
+
73
+ inputStreamWriter.write('Hello, AI! Can you stream responses?');
74
+
75
+ const reader = outputStream.getReader();
76
+ reader.read().then(function processText({done, value}) {
77
+ if (done) {
78
+ console.log('Stream finished.');
79
+ return;
80
+ }
81
+ console.log('AI says:', value);
82
+ reader.read().then(processText); // Continue reading messages
83
+ });
84
+ ```
85
+
86
+ ### Extending Conversations
87
+
88
+ The modular design of `@push.rocks/smartai` allows you to extend conversations with additional features, such as handling audio responses or integrating other AI-powered functionalities. Utilize the provided AI providers' APIs to explore and implement a wide range of AI interactions within your conversations.
89
+
90
+ ### Conclusion
91
+
92
+ With `@push.rocks/smartai`, integrating AI functionalities into your applications becomes streamlined and efficient. By leveraging the standardized interface provided by the package, you can easily converse with multiple AI models, expanding the capabilities of your applications with cutting-edge AI features. Whether you're implementing simple chat interactions or complex, real-time communication flows, `@push.rocks/smartai` offers the tools and flexibility needed to create engaging, AI-enhanced experiences.
93
+
94
+ ## License and Legal Information
95
+
96
+ This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
97
+
98
+ **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
99
+
100
+ ### Trademarks
101
+
102
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
103
+
104
+ ### Company Information
105
+
106
+ Task Venture Capital GmbH
107
+ Registered at District court Bremen HRB 35230 HB, Germany
108
+
109
+ For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
110
+
111
+ By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartai',
6
- version: '0.0.7',
7
- description: 'a standardaized interface to talk to AI models'
6
+ version: '0.0.14',
7
+ description: 'A TypeScript library for integrating and interacting with multiple AI models, offering capabilities for chat and potentially audio responses.'
8
8
  }
@@ -1,8 +1,32 @@
1
- export abstract class MultiModal {
1
+ export abstract class MultiModalModel {
2
+ /**
3
+ * starts the model
4
+ */
2
5
  abstract start(): Promise<void>;
6
+
7
+ /**
8
+ * stops the model
9
+ */
3
10
  abstract stop(): Promise<void>;
11
+
12
+ public abstract chat(optionsArg: {
13
+ systemMessage: string,
14
+ userMessage: string,
15
+ messageHistory: {
16
+ role: 'assistant' | 'user';
17
+ content: string;
18
+ }[]
19
+ }): Promise<{
20
+ role: 'assistant';
21
+ message: string;
22
+ }>
4
23
 
5
- // Defines a streaming interface for chat interactions.
6
- // The implementation will vary based on the specific AI model.
7
- abstract chatStream(input: ReadableStream<string>): ReadableStream<string>;
24
+ /**
25
+ * Defines a streaming interface for chat interactions.
26
+ * The implementation will vary based on the specific AI model.
27
+ * @param input
28
+ */
29
+ public abstract chatStream(input: ReadableStream<string>): Promise<ReadableStream<string>>;
30
+
31
+
8
32
  }
@@ -0,0 +1,116 @@
1
+ import type { SmartAi } from "./classes.smartai.js";
2
+ import { OpenAiProvider } from "./provider.openai.js";
3
+
4
+ type TProcessFunction = (input: string) => Promise<string>;
5
+
6
+ export interface IConversationOptions {
7
+ processFunction: TProcessFunction;
8
+ }
9
+
10
+ /**
11
+ * a conversation
12
+ */
13
+ export class Conversation {
14
+ // STATIC
15
+ public static async createWithOpenAi(smartaiRefArg: SmartAi) {
16
+ if (!smartaiRefArg.openaiProvider) {
17
+ throw new Error('OpenAI provider not available');
18
+ }
19
+ const conversation = new Conversation(smartaiRefArg, {
20
+ processFunction: async (input) => {
21
+ return '' // TODO implement proper streaming
22
+ }
23
+ });
24
+ return conversation;
25
+ }
26
+
27
+ public static async createWithAnthropic(smartaiRefArg: SmartAi) {
28
+ if (!smartaiRefArg.anthropicProvider) {
29
+ throw new Error('Anthropic provider not available');
30
+ }
31
+ const conversation = new Conversation(smartaiRefArg, {
32
+ processFunction: async (input) => {
33
+ return '' // TODO implement proper streaming
34
+ }
35
+ });
36
+ return conversation;
37
+ }
38
+
39
+ public static async createWithPerplexity(smartaiRefArg: SmartAi) {
40
+ if (!smartaiRefArg.perplexityProvider) {
41
+ throw new Error('Perplexity provider not available');
42
+ }
43
+ const conversation = new Conversation(smartaiRefArg, {
44
+ processFunction: async (input) => {
45
+ return '' // TODO implement proper streaming
46
+ }
47
+ });
48
+ return conversation;
49
+ }
50
+
51
+ public static async createWithOllama(smartaiRefArg: SmartAi) {
52
+ if (!smartaiRefArg.ollamaProvider) {
53
+ throw new Error('Ollama provider not available');
54
+ }
55
+ const conversation = new Conversation(smartaiRefArg, {
56
+ processFunction: async (input) => {
57
+ return '' // TODO implement proper streaming
58
+ }
59
+ });
60
+ return conversation;
61
+ }
62
+
63
+ // INSTANCE
64
+ smartaiRef: SmartAi
65
+ private systemMessage: string;
66
+ private processFunction: TProcessFunction;
67
+ private inputStreamWriter: WritableStreamDefaultWriter<string> | null = null;
68
+ private outputStreamController: ReadableStreamDefaultController<string> | null = null;
69
+
70
+ constructor(smartairefArg: SmartAi, options: IConversationOptions) {
71
+ this.processFunction = options.processFunction;
72
+ }
73
+
74
+ public async setSystemMessage(systemMessageArg: string) {
75
+ this.systemMessage = systemMessageArg;
76
+ }
77
+
78
+ private setupOutputStream(): ReadableStream<string> {
79
+ return new ReadableStream<string>({
80
+ start: (controller) => {
81
+ this.outputStreamController = controller;
82
+ }
83
+ });
84
+ }
85
+
86
+ private setupInputStream(): WritableStream<string> {
87
+ const writableStream = new WritableStream<string>({
88
+ write: async (chunk) => {
89
+ const processedData = await this.processFunction(chunk);
90
+ if (this.outputStreamController) {
91
+ this.outputStreamController.enqueue(processedData);
92
+ }
93
+ },
94
+ close: () => {
95
+ this.outputStreamController?.close();
96
+ },
97
+ abort: (err) => {
98
+ console.error('Stream aborted', err);
99
+ this.outputStreamController?.error(err);
100
+ }
101
+ });
102
+ return writableStream;
103
+ }
104
+
105
+ public getInputStreamWriter(): WritableStreamDefaultWriter<string> {
106
+ if (!this.inputStreamWriter) {
107
+ const inputStream = this.setupInputStream();
108
+ this.inputStreamWriter = inputStream.getWriter();
109
+ }
110
+ return this.inputStreamWriter;
111
+ }
112
+
113
+ public getOutputStream(): ReadableStream<string> {
114
+ return this.setupOutputStream();
115
+ }
116
+ }
@@ -0,0 +1,62 @@
1
+ import { Conversation } from './classes.conversation.js';
2
+ import * as plugins from './plugins.js';
3
+ import { AnthropicProvider } from './provider.anthropic.js';
4
+ import type { OllamaProvider } from './provider.ollama.js';
5
+ import { OpenAiProvider } from './provider.openai.js';
6
+ import type { PerplexityProvider } from './provider.perplexity.js';
7
+
8
+
9
+ export interface ISmartAiOptions {
10
+ openaiToken?: string;
11
+ anthropicToken?: string;
12
+ perplexityToken?: string;
13
+ }
14
+
15
+ export type TProvider = 'openai' | 'anthropic' | 'perplexity' | 'ollama';
16
+
17
+ export class SmartAi {
18
+ public options: ISmartAiOptions;
19
+
20
+ public openaiProvider: OpenAiProvider;
21
+ public anthropicProvider: AnthropicProvider;
22
+ public perplexityProvider: PerplexityProvider;
23
+ public ollamaProvider: OllamaProvider;
24
+
25
+ constructor(optionsArg: ISmartAiOptions) {
26
+ this.options = optionsArg;
27
+ }
28
+
29
+ public async start() {
30
+ if (this.options.openaiToken) {
31
+ this.openaiProvider = new OpenAiProvider({
32
+ openaiToken: this.options.openaiToken,
33
+ });
34
+ await this.openaiProvider.start();
35
+ }
36
+ if (this.options.anthropicToken) {
37
+ this.anthropicProvider = new AnthropicProvider({
38
+ anthropicToken: this.options.anthropicToken,
39
+ });
40
+ }
41
+ }
42
+
43
+ public async stop() {}
44
+
45
+ /**
46
+ * create a new conversation
47
+ */
48
+ createConversation(provider: TProvider) {
49
+ switch (provider) {
50
+ case 'openai':
51
+ return Conversation.createWithOpenAi(this);
52
+ case 'anthropic':
53
+ return Conversation.createWithAnthropic(this);
54
+ case 'perplexity':
55
+ return Conversation.createWithPerplexity(this);
56
+ case 'ollama':
57
+ return Conversation.createWithOllama(this);
58
+ default:
59
+ throw new Error('Provider not available');
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,15 @@
1
+ import type { SmartAi } from './classes.smartai.js';
2
+ import * as plugins from './plugins.js';
3
+
4
+ export class TTS {
5
+ public static async createWithOpenAi(smartaiRef: SmartAi): Promise<TTS> {
6
+ return new TTS(smartaiRef);
7
+ }
8
+
9
+ // INSTANCE
10
+ smartaiRef: SmartAi;
11
+
12
+ constructor(smartairefArg: SmartAi) {
13
+ this.smartaiRef = smartairefArg;
14
+ }
15
+ }
package/ts/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './smartai.classes.smartai.js';
1
+ export * from './classes.smartai.js';
2
2
  export * from './abstract.classes.multimodal.js';
3
3
  export * from './provider.openai.js';
File without changes
package/ts/plugins.ts CHANGED
@@ -7,20 +7,30 @@ export {
7
7
 
8
8
  // @push.rocks scope
9
9
  import * as qenv from '@push.rocks/qenv';
10
+ import * as smartarray from '@push.rocks/smartarray';
11
+ import * as smartfile from '@push.rocks/smartfile';
10
12
  import * as smartpath from '@push.rocks/smartpath';
13
+ import * as smartpdf from '@push.rocks/smartpdf';
11
14
  import * as smartpromise from '@push.rocks/smartpromise';
12
- import * as smartfile from '@push.rocks/smartfile';
15
+ import * as smartrequest from '@push.rocks/smartrequest';
16
+ import * as webstream from '@push.rocks/webstream';
13
17
 
14
18
  export {
19
+ smartarray,
15
20
  qenv,
21
+ smartfile,
16
22
  smartpath,
23
+ smartpdf,
17
24
  smartpromise,
18
- smartfile,
25
+ smartrequest,
26
+ webstream,
19
27
  }
20
28
 
21
29
  // third party
30
+ import * as anthropic from '@anthropic-ai/sdk';
22
31
  import * as openai from 'openai';
23
32
 
24
33
  export {
34
+ anthropic,
25
35
  openai,
26
36
  }
@@ -0,0 +1,62 @@
1
+ import * as plugins from './plugins.js';
2
+ import * as paths from './paths.js';
3
+ import { MultiModalModel } from './abstract.classes.multimodal.js';
4
+
5
+ export interface IAnthropicProviderOptions {
6
+ anthropicToken: string;
7
+ }
8
+
9
+ export class AnthropicProvider extends MultiModalModel {
10
+ private options: IAnthropicProviderOptions;
11
+ public anthropicApiClient: plugins.anthropic.default;
12
+
13
+ constructor(optionsArg: IAnthropicProviderOptions) {
14
+ super();
15
+ this.options = optionsArg // Ensure the token is stored
16
+ }
17
+
18
+ async start() {
19
+ this.anthropicApiClient = new plugins.anthropic.default({
20
+ apiKey: this.options.anthropicToken,
21
+ });
22
+ }
23
+
24
+ async stop() {}
25
+
26
+ public async chatStream(input: ReadableStream<string>): Promise<ReadableStream<string>> {
27
+ // TODO: implement for OpenAI
28
+
29
+ const returnStream = new ReadableStream();
30
+ return returnStream;
31
+ }
32
+
33
+ // Implementing the synchronous chat interaction
34
+ public async chat(optionsArg: {
35
+ systemMessage: string;
36
+ userMessage: string;
37
+ messageHistory: {
38
+ role: 'assistant' | 'user';
39
+ content: string;
40
+ }[];
41
+ }) {
42
+ const result = await this.anthropicApiClient.messages.create({
43
+ model: 'claude-3-opus-20240229',
44
+ system: optionsArg.systemMessage,
45
+ messages: [
46
+ ...optionsArg.messageHistory,
47
+ { role: 'user', content: optionsArg.userMessage },
48
+ ],
49
+ max_tokens: 4000,
50
+ });
51
+
52
+ return {
53
+ role: result.role as 'assistant',
54
+ message: result.content.join('\n'),
55
+ };
56
+ }
57
+
58
+ private async audio(messageArg: string) {
59
+ // Anthropic does not provide an audio API, so this method is not implemented.
60
+ throw new Error('Audio generation is not yet supported by Anthropic.');
61
+ }
62
+ }
@@ -0,0 +1,3 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ export class OllamaProvider {}