From 63d3b7c9bb510924000afe58c8c0e0c97ebb4b03 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 14 Apr 2024 17:19:32 +0200 Subject: [PATCH] update tsconfig --- npmextra.json | 5 ++- package.json | 7 +++-- readme.hints.md | 1 + readme.md | 84 ++++++++++++++++++++++++++----------------------- 4 files changed, 54 insertions(+), 43 deletions(-) create mode 100644 readme.hints.md diff --git a/npmextra.json b/npmextra.json index c2ce1f0..a0c81ee 100644 --- a/npmextra.json +++ b/npmextra.json @@ -16,7 +16,10 @@ "text-to-speech", "conversation stream", "TypeScript", - "ESM" + "ESM", + "streaming API", + "modular design", + "development tool" ] } }, diff --git a/package.json b/package.json index e7ff10d..4ce9b2e 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,9 @@ "text-to-speech", "conversation stream", "TypeScript", - "ESM" + "ESM", + "streaming API", + "modular design", + "development tool" ] -} +} \ No newline at end of file diff --git a/readme.hints.md b/readme.hints.md new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/readme.hints.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/readme.md b/readme.md index 5d8adea..b8ca792 100644 --- a/readme.md +++ b/readme.md @@ -1,108 +1,112 @@ # @push.rocks/smartai -a standardized interface to talk to AI models + +Provides a standardized interface for integrating and conversing with multiple AI models, supporting operations like chat and potentially audio responses. ## Install -To install `@push.rocks/smartai`, run the following command in your terminal: + +To add @push.rocks/smartai to your project, run the following command in your terminal: + ```bash npm install @push.rocks/smartai ``` -This will add the package to your project's dependencies. +This command installs the package and adds it to your project's dependencies. ## Usage -In the following guide, you'll learn how to leverage `@push.rocks/smartai` for integrating AI models into your applications using TypeScript with ESM syntax. +The usage section delves into how to leverage the `@push.rocks/smartai` package to interact with AI models in an application. This package simplifies the integration and conversation with AI models by providing a standardized interface. The examples below demonstrate the package's capabilities in engaging with AI models for chat operations and potentially handling audio responses using TypeScript and ESM syntax. -### Getting Started +### Integrating AI Models -First, you'll need to import the necessary modules from `@push.rocks/smartai`. This typically includes the main `SmartAi` class along with any specific provider classes you intend to use, such as `OpenAiProvider` or `AnthropicProvider`. +#### Importing the Module + +Start by importing `SmartAi` and the AI providers you wish to use from `@push.rocks/smartai`. ```typescript import { SmartAi, OpenAiProvider, AnthropicProvider } from '@push.rocks/smartai'; ``` -### Initialization +#### Initializing `SmartAi` -Create an instance of `SmartAi` by providing the required options, which include authentication tokens for the AI providers you plan to use. +Create an instance of `SmartAi` with the necessary credentials for accessing the AI services. ```typescript const smartAi = new SmartAi({ - openaiToken: 'your-openai-token-here', - anthropicToken: 'your-anthropic-token-here' + openaiToken: 'your-openai-access-token', + anthropicToken: 'your-anthropic-access-token' }); ``` -### Creating a Conversation +### Chatting with the AI -`@push.rocks/smartai` offers a versatile way to handle conversations with AI. To create a conversation using OpenAI, for instance: +#### Creating a Conversation + +To begin a conversation, choose the AI provider you'd like to use. For instance, to use OpenAI: ```typescript async function createOpenAiConversation() { const conversation = await smartAi.createOpenApiConversation(); + // Use the conversation for chatting } ``` -For Anthropic-based conversations: +Similarly, for an Anthropic AI conversation: ```typescript async function createAnthropicConversation() { const conversation = await smartAi.createAnthropicConversation(); + // Use the conversation for chatting } ``` -### Advanced Usage: Streaming and Chat +### Streaming Chat with OpenAI -Advanced use cases might require direct access to the streaming APIs provided by the AI models. For instance, handling a chat stream with OpenAI can be achieved as follows: - -#### Set Up the Conversation Stream - -First, create a conversation and obtain the input and output streams. +For more advanced scenarios, like a streaming chat with OpenAI, you would interact with the chat stream directly: ```typescript -const conversation = await smartAi.createOpenApiConversation(); +// Assuming a conversation has been created and initialized... const inputStreamWriter = conversation.getInputStreamWriter(); const outputStream = conversation.getOutputStream(); -``` -#### Write to Input Stream +// Write a message to the input stream for the AI to process +await inputStreamWriter.write('Hello, how can I help you today?'); -To send messages to the AI model, use the input stream writer. - -```typescript -await inputStreamWriter.write('Hello, SmartAI!'); -``` - -#### Processing Output Stream - -Output from the AI model can be processed by reading from the output stream. - -```typescript +// Listen to the output stream for responses from AI const reader = outputStream.getReader(); reader.read().then(function processText({ done, value }) { if (done) { - console.log("Stream complete"); + console.log("No more messages from AI"); return; } - console.log("Received from AI:", value); + console.log("AI says:", value); + // Continue reading messages reader.read().then(processText); }); ``` -### Handling Audio +### Handling Audio Responses -`@push.rocks/smartai` also supports handling audio responses from AI models. To generate and retrieve audio output: +The package may also support converting text responses from the AI into audio. While specific implementation details depend on the AI provider's capabilities, a generic approach would involve creating a text-to-speech instance and utilizing it: ```typescript +// This is a hypothetical function call as the implementation might vary const tts = await TTS.createWithOpenAi(smartAi); + +// The TTS instance would then be used to convert text to speech ``` -This code snippet initializes text-to-speech (TTS) capabilities using the OpenAI model. Further customization and usage of audio APIs will depend on the capabilities offered by the specific AI model and provider you are working with. +### Extensive Feature Set + +`@push.rocks/smartai` provides comprehensive support for interacting with various AI models, not limited to text chat. It encompasses audio responses, potentially incorporating AI-powered analyses, and other multi-modal interactions. + +Refer to the specific AI providers’ documentation through `@push.rocks/smartai`, such as OpenAI and Anthropic, for detailed guidance on utilizing the full spectrum of capabilities, including the implementation of custom conversation flows, handling streaming data efficiently, and generating audio responses from AI conversations. ### Conclusion -`@push.rocks/smartai` offers a flexible and standardized interface for interacting with AI models, streamlining the development of applications that leverage AI capabilities. Through the outlined examples, you've seen how to initialize the library, create conversations, and handle both text and audio interactions with AI models in a TypeScript environment following ESM syntax. +Equipped with `@push.rocks/smartai`, developers can streamline the integration of sophisticated AI interactions into their applications. The package facilitates robust communication with AI models, supporting diverse operations from simple chats to complex audio feedback mechanisms, all within a unified, easy-to-use interface. + +Explore the package more to uncover its full potential in creating engaging, AI-enhanced interactions in your applications. -For a comprehensive understanding of all features and to explore more advanced use cases, refer to the official [documentation](https://code.foss.global/push.rocks/smartai#readme) and check the `npmextra.json` file's `tsdocs` section for additional insights on module usage. ## License and Legal Information