Skip to content

Commit

Permalink
Updated README to include the new EmbeddedDocumentStore stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
btfranklin committed Sep 8, 2023
1 parent e793eb5 commit cf11361
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
[![GitHub tag](https://img.shields.io/github/tag/btfranklin/CleverBird.svg)](https://github.com/btfranklin/CleverBird)
[![build](https://github.com/btfranklin/CleverBird/actions/workflows/build.yml/badge.svg)](https://github.com/btfranklin/CleverBird/actions/workflows/build.yml)

`CleverBird` is a Swift Package that provides a convenient way to interact with OpenAI's chat APIs and perform various tasks, including token counting and encoding. The package is designed to deliver a superior Developer Experience (DX) by making the chat thread the center of the interactions. While there are numerous Swift Packages available for interacting with OpenAI, `CleverBird` stands out due to its focus on simplicity and seamless integration of the handy `TokenEncoder` class.
`CleverBird` is a Swift Package that provides a convenient way to interact with OpenAI's chat APIs and perform various tasks, including token counting and encoding. The package is designed to deliver a superior Developer Experience (DX) by making the chat thread the center of the interactions.

`CleverBird` includes support for document embeddings and similarity queries. This makes it a versatile tool for a broad range of applications, especially cases where chat prompts need enhanced contextual memory.

`CleverBird` is focused narrowly on chat-based interactions, and making them awesome.

Please note that `CleverBird` is an *unofficial* package, not provided by OpenAI itself.

## Features

### Core Features
- Asynchronous API calls with Swift's async/await syntax
- Supports token counting and encoding with the `TokenEncoder` class
- Allows customization of various parameters, such as temperature and penalties
- Streamed responses for real-time generated content
- Built-in token counting for usage limit calculations

### Specialized Features
- Token Encoding: Facilitates token counting and encoding through the `TokenEncoder` class.
- Document Embedding and Similarity Queries: Utilize the `EmbeddedDocumentStore` class for managing and querying document similarities.

## Usage Instructions

Import the `CleverBird` package:
Expand Down Expand Up @@ -162,6 +167,46 @@ Finally, call the `complete()` function to generate a response. If the assistant

Please note that functions are only supported in non-streaming completions at this time.

## Using Embeddings

The `EmbeddedDocumentStore` class provides a convenient way to manage and query a collection of documents based on their similarity. This class allows you to:

- Add documents to an internal store.
- Generate embeddings for those documents using a specified model.
- Query the store for similar documents to a given input document.

First, add an instance of the `EmbeddedDocumentStore` to your code:

```swift
let openAIAPIConnection = OpenAIAPIConnection(apiKey: "your_api_key_here")
let embeddedDocumentStore = EmbeddedDocumentStore(connection: connection)
```

You can add a single document or a batch of documents to the store.

```swift
let singleDocument = "My single document"
try await embeddedDocumentStore.embedAndStore(singleDocument)

let documentCollection = ["First document", "Second document", "Third document"]
try await embeddedDocumentStore.embedAndStore(documentCollection)

```

You can query the store for documents that are similar to an input document.

```swift
let similarityResults = try await embeddedDocumentStore.queryDocumentSimilarity("Query text here")
let mostSimilarResult = similarityResults.first?.document ?? "No result returned"
```

The store can be saved to and loaded from a file (represented in JSON format) for persistent storage.

```swift
embeddedDocumentStore.save(to: fileURL)
embeddedDocumentStore.load(from: fileURL)
```

## License

`CleverBird` was written by B.T. Franklin ([@btfranklin](https://github.com/btfranklin)) from 2023 onward and is licensed under the [MIT](https://opensource.org/licenses/MIT) license. See [LICENSE.md](LICENSE.md).

0 comments on commit cf11361

Please sign in to comment.