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/")
# or ollama.Ollama("deepseek-coder-v2:latest", "http://localhost:11434/")
# or ollama.Ollama("mannix/llama3.1-8b-abliterated:latest", "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? 😁'
>>> client.generate_json("This is a test message. Use the word 'platypus' in your response.", "Generate a list of animal names in JSON format. Return [Name] and no other commentary").content
[{'name': 'Platypus'}, {'name': 'Eagle'}, {'name': 'Elephant'}, {'name': 'Giraffe'}, {'name': 'Lion'}, {'name': 'Tiger'}, {'name': 'Zebra'}, {'name': 'Dolphin'}, {'name': 'Whale'}, {'name': 'Bear'}, {'name': 'Wolf'}, {'name': 'Dog'}, {'name': 'Cat'}, {'name': 'Monkey'}]
>>>

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("deepseek-v2:16b", "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
## You could also equivalently use
## >>> @tls.define()
## >>> 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.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, "This space intentionally left blank.",  "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.1.18.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

trivialai-0.1.18-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trivialai-0.1.18.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for trivialai-0.1.18.tar.gz
Algorithm Hash digest
SHA256 b771da080cc604b3411addeb98883f62e5ded58de15af4e2febace62bc8a1890
MD5 10e615f9c9d074c1edd44c57f6373d35
BLAKE2b-256 d59b85ea0237e330c2a40ed642acc5ef1abd4d1e8266cb967f3d822111fb7221

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trivialai-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for trivialai-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 7694ea5fca4c45b3f21e46e5806958ccc4de3fce2a23873db870076f755c0136
MD5 5f2bcabd5a9d8bf0dd1ba89df1facabc
BLAKE2b-256 ad1d98933fff199af6083a0810dc9c1d0beff73a515c80069a5ef78afee1ed30

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