Skip to content

Magic-Goose-Software-Co/ai-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ai-helper

A small Python helper library for working with artificial intelligence providers that use the OpenAI schema.


Installation

pip install git+https://github.com/magic-goose-software-co/ai-helper.git

Usage

Basic usage

import ai

openai = ai.Provider("your-api-key")

model = ai.AI(openai, "gpt-4.1-mini", "You are a helpful AI assistant.")

while True:
    prompt = input("You: ")
    response = model.prompt(prompt)
    print(response)

Using a different provider

If you want to use a provider other than OpenAI (e.g. GitHub models), pass it as a string to ai.Provider.

github = ai.Provider("your-api-key", baseUrl="https://models.github.ai/inference")

Tool Calls

To enable tool calls, pass a list of tool definitions to ai.AI.
If a tool takes no parameters, you may pass an empty list.

model = ai.AI(provider, "gpt-4.1-mini", "You are a helpful AI assistant.", [
    {"name": "web",
        "description": "Browse the web.",
        "parameters": [
            {
                "url": {
                    "type": "string",
                    "description": "The URL of the page you want to visit."
                }
            }
        ]
    }
]
)

If the model uses a tool call, ai.AI.prompt will return a list of instances of ai.AI.ToolCall.
ai.AI.ToolCall has the attributes name, a string of the name (e.g. "web" from the example above), and arguments, a dictionary of the parameters passed (e.g. {"url": "google.com"} from the example above).
ai.AI.ToolCall has the method respond(), which takes one parameter, the response as a string. You must call respond for all tool calls returned by ai.AI.prompt.

About

A small Python helper library for working with artificial intelligence providers that use the OpenAI schema.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages