Skip to main content

A trivial set of API bindings for AI models, because I'd like them to be easy to use.

Project description

TrivialAI

(A set of requests-based, trivial bindings for AI models)

Basics

$ pip install pytrivialai
$ python
>>> from trivialai import claude, gcp, ollama, chatgpt
>>>

Basic model usage

Ollama

>>> client = ollama.Ollama("gemma2:2b", "http://localhost:11434/")
>>> client.generate("This is a test message. Use the word 'platypus' in your response.", "Hello there! :D").content
'Hey!  Did you know platypuses lay eggs and have webbed feet? Pretty cool, huh? 😁'
>>>

Claude

>>> client = claude.Claude("claude-3-5-sonnet-20240620", os.environ["ANTHROPIC_API_KEY"])
>>> client.generate("This is a test message. Use the word 'platypus' in your response.", "Hello there! :D").content
"Hello! It's nice to meet you. I hope you're having a fantastic day. Since you mentioned using a specific word, I'll incorporate it here: Did you know that the platypus is one of the few mammals that can produce venom? It's quite an unusual and fascinating creature!"
>>>

GCP

>>> client = gcp.GCP("gemini-1.5-flash-001", "/path/to/your/gcp_creds.json", "us-central1")
>>> client.generate("This is a test message. Use the word 'platypus' in your response.", "Hello there! :D").content
"Hello! :D It's great to hear from you. Did you know platypuses are one of the few mammals that lay eggs? 🥚  They are truly fascinating creatures!  What can I help you with today? 😊"
>>> 

ChatGPT

>>> client = chatgpt.ChatGPT("gpt-3.5-turbo", os.environ["OPENAI_API_KEY"])
>>> client.generate("This is a test message. Use the word 'platypus' in your response.", "Hello there! :D").content
'Hello! How are you today? By the way, did you know the platypus is one of the few mammals that lays eggs?'
>>> 

Basic Tool Use

>>> from src.trivialai import tools
>>> client = ollama.Ollama("gemma2:2b", "http://localhost:11434/")
>>> tls = tools.Tools()
>>> from typing import Optional, List
>>> def _screenshot(url: str, selectors: Optional[List[str]] = None) -> None:
    "Takes a url and an optional list of selectors. Takes a screenshot"
    print(f"GOT {url}, {selectors}!")
... ... ... 
>>> tls.define(_screenshot)
True
>>> tls.list()
[{'name': '_screenshot', 'type': {'url': <class 'str'>, 'selectors': typing.Optional[typing.List[str]]}, 'description': 'Takes a url and an optional list of selectors. Takes a screenshot'}]
>>> res = client.generate_tool_call(tls, "Take a screenshot of the Google website and highlight the search box")
>>> res.content
{'functionName': '_screenshot', 'args': {'url': 'https://www.google.com', 'selectors': ['#search']}}
>>> tls.call(res.content)
GOT https://www.google.com, ['#search']!
>>> 
``

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

trivialai-0.0.10.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

trivialai-0.0.10-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file trivialai-0.0.10.tar.gz.

File metadata

  • Download URL: trivialai-0.0.10.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for trivialai-0.0.10.tar.gz
Algorithm Hash digest
SHA256 4c43b875076af18396cacbddb2a30f9760431a89fcfbe5c7c4678418352e4a6e
MD5 d15269a90c3fcb3fb20d4fd90b81e4fb
BLAKE2b-256 58ac569dd4aef0c160d3cbc212c89a86a3819524411a39bfbcc19c0cf7797266

See more details on using hashes here.

File details

Details for the file trivialai-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: trivialai-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for trivialai-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 4800b786083716d4f9b9c6d2d242a590b87fadaf6fc2edd0925dce83a6e137f9
MD5 bf4bab66d734dc34d0d00053d16dc6ae
BLAKE2b-256 e4606a85d96f66f987b393b7935ccafefdb465dc82a1bdb169f1306ff8ff5c7b

See more details on using hashes here.

Supported by

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