Skip to main content

Generate code

Project description

abbu

abbu is a python library for easy code generation with ChatGPT.

Installation

pip install abbu

Usage example

To use abbu, there's three simple key components:

  • setup: This function initializes abbu by setting up the necessary configuration. Provide your OpenAI API key, a file path for caching, and optional settings. This step prepares everything abbu needs to generate and manage code.
  • FunctionSpec: This class defines what you want your function to do. You specify the function name, input parameters, and the desired functionality.
  • create_function: This function generates the code based on your FunctionSpec. It checks if the function is already in the cache; if not, it generates the code using the OpenAI API and saves it to the cache. The function is then returned, ready for use.

An example of how these come together is in the

# my_example.py
import os
import sys
import abbu 

abbu.setup(
    api_key = os.getenv("OPENAI_API_KEY"),
    cache_file = "/Users/jawada/Documents/CC/jawad_cache.py",
    reset_cache=True 
)

spec = abbu.FunctionSpec(
    name = "number_adder_2",
    params = ["num1", "num2"],
    description = "takes as input two numbers and returns their sum"
)

def add_three_numbers(a, b, c):
    f = abbu.create_function(spec=spec)
    return f(a, b) + c

add_three_numbers(1,2,3)

As an example of how this would get run:

$ python3 /path/to/my_example.py
Creating function for spec: <abbu.spec.FunctionSpec object at 0x108a8b8f0>
Loaded cache: {}
Generating code for spec: <abbu.spec.FunctionSpec object at 0x108a8b8f0>
Cache saved to /Users/jawada/Documents/CC/jawad_cache.py.
6

abbu will create a cache file at /path/to/your/cache.py so that you can see what was generated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abbu-0.0.7.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abbu-0.0.7-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file abbu-0.0.7.tar.gz.

File metadata

  • Download URL: abbu-0.0.7.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for abbu-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c95fc3ec2d465a7212b84b93c2652aace3036631df0c4142c16093c11550c894
MD5 f01de148e8d70fefc3af22e9580b7c47
BLAKE2b-256 1460bf0e274e43dfa3976a86e787b40fdfcfd0826068214f95dadc7b319392fc

See more details on using hashes here.

File details

Details for the file abbu-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: abbu-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for abbu-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6af08bde63473d4caa267dd202429ea8b743375a2c1cccbcfe2ec2c4753c051e
MD5 6eade874e99a9db89664d8ca65099ecb
BLAKE2b-256 95253bb70c5e92ff9abddec083d5e9d13b28547f7a8f29f9a5c5e8fd9d069893

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page