Metadata-Version: 2.1
Name: danai
Version: 0.3.9
Summary: Utility functions for token counting and pricing checks for OpenAI models.
Author-email: Aidan Coughlan <dev@farfromavocados.com>
License: MIT
Project-URL: Homepage, https://github.com/farfromavocaido/ai_utils
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tiktoken
Requires-Dist: requests
Requires-Dist: openai
Requires-Dist: datetime

# Danai

Danai is a utility package for token counting and pricing checks for OpenAI models. It provides functions to calculate the cost of tokens generated by OpenAI models, count tokens in text files and strings, and manage pricing data updates.

## Features

- **Token Counting**: Count the number of tokens in text files or strings using specified OpenAI models.
- **Pricing Calculation**: Calculate the cost of tokens generated by OpenAI models based on pricing data.
- **Quick Queries**: Quickly generate responses from OpenAI models and print them.
- **Directory Summarization**: Print directory contents and generate directory trees while ignoring certain files and directories.
- **JSON Response Saving**: Save OpenAI API responses as JSON files with optional pretty-printing and cost calculation.

## Installation

To install Danai, use pip:

```
pip install danai
```

## Usage

### Token Counting

Count tokens in a text file:

```python
from danai import tokencount_file

token_count = tokencount_file("path/to/textfile.txt", model="gpt-4o")
print(f"Token count: {token_count}")
```

Count tokens in a text string:

```python
from danai import tokencount_text

text = "Your text here"
token_count = tokencount_text(text, model="gpt-4o")
print(f"Token count: {token_count}")
```

### Pricing Calculation

Calculate the cost of tokens generated by an OpenAI model:

```python
from danai import pricecheck

response = ...  # Your OpenAI API response object
cost_details = pricecheck(response)
print(cost_details)
```

### Quick Queries

Generate a quick response from an OpenAI model and print it:

```python
from danai import quickprint

prompt = "Your prompt here"
quickprint(prompt, model="gpt-4o-mini")
```

### Directory Summarization

Print the contents of a directory while ignoring certain files and directories:

```python
from danai import print_directory_contents

print_directory_contents(
    directory="path/to/directory",
    output_dir="path/to/output",
    ignore_dirs=[".git", "__pycache__"],
    ignore_files=[".DS_Store"],
    ignore_extensions=[".pyc"]
)
```

Generate a directory tree:

```python
from danai import print_directory_tree

print_directory_tree(
    directory="path/to/directory",
    output_dir="path/to/output",
    ignore_dirs=[".git", "__pycache__"]
)
```

Join summaries of directory contents and tree:

```python
from danai import join_summaries

join_summaries(output_directory="path/to/output")
```

### JSON Response Saving

Save an OpenAI API response as a JSON file:

```python
from danai import jsonsave

response = ...  # Your OpenAI API response object
jsonsave(response, filename="response", directory="outputs", overwrite=False, pretty=True, price=True)
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Author

Aidan Coughlan - [dev@farfromavocados.com](mailto:dev@farfromavocados.com)

## Project Links

- [Homepage](https://github.com/farfromavocaido/ai_utils)
```
# Danai

Danai is a utility package for token counting and pricing checks for OpenAI models. It provides functions to calculate the cost of tokens generated by OpenAI models, count tokens in text files and strings, and manage pricing data updates.

## Features

- **Token Counting**: Count the number of tokens in text files or strings using specified OpenAI models.
- **Pricing Calculation**: Calculate the cost of tokens generated by OpenAI models based on pricing data.
- **Quick Queries**: Quickly generate responses from OpenAI models and print them.
- **Directory Summarization**: Print directory contents and generate directory trees while ignoring certain files and directories.
- **JSON Response Saving**: Save OpenAI API responses as JSON files with optional pretty-printing and cost calculation.

## Installation

To install Danai, use pip:

```
pip install danai
```

## Usage

### Token Counting

Count tokens in a text file:

```python
from danai import tokencount_file

token_count = tokencount_file("path/to/textfile.txt", model="gpt-4o")
print(f"Token count: {token_count}")
```

Count tokens in a text string:

```python
from danai import tokencount_text

text = "Your text here"
token_count = tokencount_text(text, model="gpt-4o")
print(f"Token count: {token_count}")
```

### Pricing Calculation

Calculate the cost of tokens generated by an OpenAI model:

```python
from danai import pricecheck

response = ...  # Your OpenAI API response object
cost_details = pricecheck(response)
print(cost_details)
```

### Quick Queries

Generate a quick response from an OpenAI model and print it:

```python
from danai import quickprint

prompt = "Your prompt here"
quickprint(prompt, model="gpt-4o-mini")
```

### Directory Summarization

Print the contents of a directory while ignoring certain files and directories:

```python
from danai import print_directory_contents

print_directory_contents(
    directory="path/to/directory",
    output_dir="path/to/output",
    ignore_dirs=[".git", "__pycache__"],
    ignore_files=[".DS_Store"],
    ignore_extensions=[".pyc"]
)
```

Generate a directory tree:

```python
from danai import print_directory_tree

print_directory_tree(
    directory="path/to/directory",
    output_dir="path/to/output",
    ignore_dirs=[".git", "__pycache__"]
)
```

Join summaries of directory contents and tree:

```python
from danai import join_summaries

join_summaries(output_directory="path/to/output")
```

### JSON Response Saving

Save an OpenAI API response as a JSON file:

```python
from danai import jsonsave

response = ...  # Your OpenAI API response object
jsonsave(response, filename="response", directory="outputs", overwrite=False, pretty=True, price=True)
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Author

Aidan Coughlan - [dev@farfromavocados.com](mailto:dev@farfromavocados.com)

## Project Links

- [Homepage](https://github.com/farfromavocaido/ai_utils)
```
