Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cfahlgren1/observers
A Lightweight Library for AI Observability
https://github.com/cfahlgren1/observers
Last synced: about 1 month ago
JSON representation
A Lightweight Library for AI Observability
- Host: GitHub
- URL: https://github.com/cfahlgren1/observers
- Owner: cfahlgren1
- Created: 2024-11-19T22:45:49.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-29T07:51:55.000Z (about 2 months ago)
- Last Synced: 2024-11-29T08:34:41.878Z (about 2 months ago)
- Language: Python
- Homepage:
- Size: 1.69 MB
- Stars: 189
- Watchers: 3
- Forks: 18
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
- StarryDivineSky - cfahlgren1/observers
README
๐ค๐ญ Observers ๐ญ๐ค
A Lightweight Library for AI Observability
![Observers Logo](./assets/observers.png)
## Installation
First things first! You can install the SDK with pip as follows:
```bash
pip install observers
```Or if you want to use other LLM providers through AISuite or Litellm, you can install the SDK with pip as follows:
```bash
pip install observers[aisuite] # or observers[litellm]
```Whenever you want to observer document information, you can use our Docling integration.
```bash
pip install observers[docling]
```For open telemetry, you can install the following:
```bash
pip install observers[opentelemetry]
```## Usage
We differentiate between observers and stores. Observers wrap generative AI APIs (like OpenAI or llama-index) and track their interactions. Stores are classes that sync these observations to different storage backends (like DuckDB or Hugging Face datasets).
To get started you can run the code below. It sends requests to a HF serverless endpoint and log the interactions into a Hub dataset, using the default store `DatasetsStore`. The dataset will be pushed to your personal workspace (http://hf.co/{your_username}). To learn how to configure stores, go to the next section.
```python
from observers.observers import wrap_openai
from observers.stores import DuckDBStore
from openai import OpenAIstore = DuckDBStore()
openai_client = OpenAI()
client = wrap_openai(openai_client, store=store)response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Tell me a joke."}],
)
```## Observers
### Supported Observers
- [OpenAI](https://openai.com/) and every other LLM provider that implements the [OpenAI API message formate](https://platform.openai.com/docs/api-reference)
- [AISuite](https://github.com/andrewyng/aisuite), which is an LLM router by Andrew Ng and which maps to [a lot of LLM API providers](https://github.com/andrewyng/aisuite/tree/main/aisuite/providers) with a uniform interface.
- [Litellm](https://docs.litellm.ai/docs/), which is a library that allows you to use [a lot of different LLM APIs](https://docs.litellm.ai/docs/providers) with a uniform interface.
- [Docling](https://github.com/docling/docling), Docling parses documents and exports them to the desired format with ease and speed. This observer allows you to wrap this and push popular document formats (PDF, DOCX, PPTX, XLSX, Images, HTML, AsciiDoc & Markdown) to the different stores.### Change OpenAI compliant LLM provider
The `wrap_openai` function allows you to wrap any OpenAI compliant LLM provider. Take a look at [the example doing this for Ollama](./examples/observers/ollama_example.py) for more details.
## Stores
### Supported Stores
| Store | Example | Annotate | Local | Free | UI filters | SQL filters |
|-------|---------|----------|-------|------|-------------|--------------|
| [Hugging Face Datasets](https://huggingface.co/docs/huggingface_hub/en/package_reference/io-management#datasets) | [example](./examples/stores/datasets_example.py) | โ | โ | โ | โ | โ |
| [DuckDB](https://duckdb.org/) | [example](./examples/stores/duckdb_example.py) | โ | โ | โ | โ | โ |
| [Argilla](https://argilla.io/) | [example](./examples/stores/argilla_example.py) | โ | โ | โ | โ | โ |
| [OpenTelemetry](https://opentelemetry.io/) | [example](./examples/stores/opentelemetry_example.py) | ๏ธ* | ๏ธ* | ๏ธ* | ๏ธ* | ๏ธ* |
| [Honeycomb](https://honeycomb.io/) | [example](./examples/stores/opentelemetry_example.py) | โ |โ| โ | โ | โ |
* These features, for the OpenTelemetry store, depend upon the provider you use### Viewing / Querying
#### Hugging Face Datasets Store
To view and query Hugging Face Datasets, you can use the [Hugging Face Datasets Viewer](https://huggingface.co/docs/hub/en/datasets-viewer). You can [find example datasets on the Hugging Face Hub](https://huggingface.co/datasets?other=observers). From within here, you can query the dataset using SQL or using your own UI. Take a look at [the example](./examples/stores/datasets_example.py) for more details.
![Hugging Face Datasets Viewer](./assets/datasets.png)
#### DuckDB Store
The default store is [DuckDB](https://duckdb.org/) and can be viewed and queried using the [DuckDB CLI](https://duckdb.org/#quickinstall). Take a look at [the example](./examples/stores/duckdb_example.py) for more details.
```bash
> duckdb store.db
> from openai_records limit 10;
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโฌโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโ
โ id โ model โ timestamp โ messages โ โฆ โ error โ raw_response โ synced_at โ
โ varchar โ varchar โ timestamp โ struct("role" varcโฆ โ โ varchar โ json โ timestamp โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโผโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโค
โ 89cb15f1-d902-4586โฆ โ Qwen/Qwen2.5-Coderโฆ โ 2024-11-19 17:12:3โฆ โ [{'role': user, 'cโฆ โ โฆ โ โ {"id": "", "choiceโฆ โ โ
โ 415dd081-5000-4d1aโฆ โ Qwen/Qwen2.5-Coderโฆ โ 2024-11-19 17:28:5โฆ โ [{'role': user, 'cโฆ โ โฆ โ โ {"id": "", "choiceโฆ โ โ
โ chatcmpl-926 โ llama3.1 โ 2024-11-19 17:31:5โฆ โ [{'role': user, 'cโฆ โ โฆ โ โ {"id": "chatcmpl-9โฆ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโดโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโค
โ 3 rows 16 columns (7 shown) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```#### Argilla Store
The Argilla Store allows you to sync your observations to [Argilla](https://argilla.io/). To use it, you first need to create a [free Argilla deployment on Hugging Face](https://docs.argilla.io/latest/getting_started/quickstart/). Take a look at [the example](./examples/stores/argilla_example.py) for more details.
![Argilla Store](./assets/argilla.png)
#### OpenTelemetry Store
The OpenTelemetry "Store" allows you to sync your observations to any provider that supports OpenTelemetry! Examples are provided for [Honeycomb](https://honeycomb.io), but any provider that supplies OpenTelemetry compatible environment variables should Just Workยฎ, and your queries will be executed as usual in your provider, against _trace_ data coming from Observers.
## Contributing
See [CONTRIBUTING.md](./CONTRIBUTING.md)