Metadata-Version: 2.1
Name: utilityai
Version: 1.0.0
Summary: This package brings language model capabilities into the coding environment, providing a variety of functionalities.
Home-page: https://github.com/navid-matinmo/utilityai
License: MIT
Keywords: LLM,AI
Author: Navid Matin Moghaddam
Author-email: navid.matinmo@gmail.com
Requires-Python: >=3.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: huggingface_hub (>=0.13.0)
Requires-Dist: numpy (>=1.21.2)
Requires-Dist: onnxruntime-genai (>=0.2.0) ; sys_platform == "linux"
Requires-Dist: onnxruntime-genai (>=0.2.0) ; sys_platform == "win32"
Requires-Dist: onnxruntime-genai (>=0.3.0rc1) ; sys_platform != "win32" and sys_platform != "linux"
Requires-Dist: requests (>=1.2.0)
Project-URL: Documentation, https://github.com/navid-matinmo/utilityai
Project-URL: Repository, https://github.com/navid-matinmo/utilityai
Project-URL: documentation, https://github.com/navid-matinmo/utilityai
Project-URL: homepage, https://github.com/navid-matinmo/utilityai
Project-URL: issues, https://github.com/navid-matinmo/utilityai/issues
Project-URL: repository, https://github.com/navid-matinmo/utilityai
Description-Content-Type: text/markdown

# utilityai

This package brings language model capabilities into the coding environment, providing a variety of functionalities such as:

- Message and ask anything
- Chat and have a conversation
- Chat about a function
- Chat about a numpy array
- Chat about a pandas dataframe
- Chat about a pytorch tensor
- Generate a function interactively
- Generate a function by setting data within the code
- Generate a function and provide a comment on the result for guided generation

## install

```
pip install utilityai
```

## quick start

Download the model once after installation:
```
from utilityai.model import download
download()
```

Message and ask anything
```
message("how to transpose a pytorch tensor?")
```

Chat and have a conversation
```
r1, c1 = message("why does mutable and immutable mean")
print()
print("-------------- next message --------------")
print()
message("give some examples", c1)
```

Chat about a function
```
def list_sum(numbers):
    return sum(numbers)
r1, c1 = message("what does this do?", attachment=list_sum)
print()
print("-------------- next message --------------")
print()
message("return min and max of numbers too", c1)
```

Chat about a numpy array
```
import numpy as np
array = np.array([[1, 2, 3, 4], 
                  [5, 6, 7, 8], 
                  [9, 10, 11, 12]])
r1, c1 = message("each row is salaries of a person. how to get average salary of each person in an array", attachment=array)
print()
print("-------------- next message --------------")
print()
message("what about age?", c1)
```

Chat about a pandas dataframe
```
import pandas as pd
data = {
    'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
    'Age': [24, 27, 22, 32, 29],
    'Salary': [50000, 54000, 49000, 62000, 58000],
    'Department': ['HR', 'Engineering', 'Marketing', 'Finance', 'Engineering'],
    'Joining Date': pd.to_datetime(['2020-01-15', '2019-06-23', '2021-03-01', '2018-11-15', '2020-08-30'])
}
df = pd.DataFrame(data)
r1, c1 = message("write code to get average of salary", attachment=df)
print()
print("-------------- next message --------------")
print()
message("how to get average salary of each department?", c1)
```

Chat about a pytorch tensor
```
import torch
tensor = torch.tensor([[1, 2, 3], [4, 5, 6]])
r1, c1 = message("how to transpose this tensor", attachment=tensor)
print()
print("-------------- next message --------------")
print()
message("how to get the size of the resulting tensor", c1)
```

Generate a function interactively by calling data() first, then provide function information
```
data = InputData()
data()
function(data)
```

Generate a function by setting data within the code
```
data = InputData()
data_dict = {
    'function_name': 'prime_number_checker',
    'input_names': ['num'],
    'input_types': ['int'],
    'output_names': ['is_prime'],
    'output_types': ['bool'],
    'description': "function that checks if a given number is a prime number",
    'test_cases': [
        {'inputs': [5], 'outputs': [True]},
        {'inputs': [10], 'outputs': [False]},
        {'inputs': [17], 'outputs': [True]}
    ]
}
data.set_data(data_dict['function_name'], data_dict['input_names'], data_dict['output_names'], data_dict['input_types'], data_dict['output_types'], data_dict['description'], data_dict['test_cases'])
function(data)
```

Generate a function and provide a comment on the result for guided generation
```
data = InputData()
data_dict = {
    'function_name': 'vague_function',
    'input_names': ['a', 'b'],
    'input_types': ['int', 'int'],
    'output_names': ['subtract'],
    'output_types': ['int'],
    'description': "function that subtracts two numbers",
    'test_cases': [
        {'inputs': [1,2], 'outputs': [1]}
    ]
}
data.set_data(data_dict['function_name'], data_dict['input_names'], data_dict['output_names'], data_dict['input_types'], data_dict['output_types'], data_dict['description'], data_dict['test_cases'])
res = function(data, max_tries=1)
print()
print("-------------- comment --------------")
print()
res.comment = "actually the smaller number must be subtracted from the larger one"
function(data, res)
```
