Funkai is a Python library that encapsulates linguistic operations and uses OpenAI or Claude to perform them based on user inputs.
- Diverse Operations: Easily define linguistic tasks that can process various data types.
- Interaction with LLM: Seamlessly connect and utilize the LLM (OpenAI or Claude) API to run operations.
- Dynamic Management: Add, remove, and run operations on-the-fly with the FunkManager.
Install via pip:
pip install funkai
Or clone the repository:
git clone https://github.com/ciaraadkins/funkai.git
pip install ./funkai/
Once installed, import the necessary modules:
For the OpenAI functionality to work, you need to set up your OpenAI API key with init of FunkManager
from funkai import OpenAIFunk
funk = OpenAIFunk(
model="gpt-4-turbo-preview",
api_key='OPEN_API_KEY'
)
Additionally, if you want to monitor your llm usage, we recommend using llmonitor (you will need to also set up an account and get an app id on llmonitor.com):
pip install openai llmonitor
os.environ["LLMONITOR_APP_ID"] = "YOUR_LLMONITOR_APP_ID"
For the Claude functionality to work, you need to set up your Claude API key with init of FunkManager
from funkai import ClaudeFunk
funk = ClaudeFunk(
model="claude-3-opus-20240229",
api_key='CLAUDE_API_KEY'
)
add(name, operation, api_key=None, model=None, retry_count=0, input_dtype=str, output_dtype=str, options={'temperature': int, 'max_tokens': int})
Add a new Funk instance to the manager.
-
name
: Unique identifier for the Funk instance. -
operation
: Description of the operation or task performed by the Funk instance. -
api_key
: API key for accessing the LLM API. If not provided, the API key from FunkManager will be used. -
model
: Model to be used for the Funk instance. If not provided, the default model from FunkManager will be used. -
retry_count
: Number of retries allowed if there's an error during execution (default is 0). -
input_dtype
: Data type expected for input to the Funk instance (default isstr
). -
output_dtype
: Data type expected for output from the Funk instance (default isstr
). -
options
: Allows you to pass parameters such astemperate
andmax_tokens
to each jobs.
-
ValueError
: If a Funk with the same name already exists or if the parameters are invalid.
Update parameters of an existing Funk instance.
-
name
: Name of the Funk instance to update. -
**kwargs
: Parameters to update. Supported parameters areretry_count
,input_dtype
,output_dtype
.
-
ValueError
: If no Funk with the specified name is found or if an invalid parameter is provided.
Execute a Funk operation by name.
-
name
: Name of the Funk instance to run. -
input_content
: Input data for the Funk operation. -
examples
: Dictionary of examples to provide context or guidance to the Funk operation (default isNone
). -
full_resp
: Boolean indicating whether to return the full response including metadata (default isFalse
).
- Output of the Funk operation.
-
ValueError
: If no Funk with the specified name is found.
# Initialize FunkManager
manager = OpenAIFunk(model="gpt-4-turbo-preview", api_key="YOUR_OPENAI_API_KEY")
# Add a new Funk instance
manager.add(name="example_funk", operation="Perform a sample task")
# Update parameters of the Funk instance
manager.update("example_funk", retry_count=3, output_dtype=int)
# Run the Funk operation
output = manager.run(name="example_funk", input_content="Input data")
print(output)
## Using Functions (Funks)
## Execute your defined function:
my_funks.run("rhyme5", "cat")
# should return something like: ['bat', 'hat', 'mat', 'rat', 'sat']
items = ["apple", "bike", "carrot", "date", "elephant", "fig", "grape", "helicopter", "ice cream", "jackfruit", "kite", "lemon", "mango", "notebook","strawberry", "television", "umbrella", "van", "watermelon", "xylophone", "yellow", "zebra"]
my_funks.run("find fruit", items)
# should return something like: ['apple','date','fig','grape','jackfruit','lemon','mango','strawberry','watermelon']
This library is built on top of the OpenAI & Claude API. Ensure you have the OpenAI or Claude Python client installed and configured.
If you find any bugs or want to propose enhancements, feel free to create issues and pull requests on GitHub.
This library is under the MIT license. See LICENSE for more details.