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
Release history Release notifications | RSS feed
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.13.tar.gz
(6.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trivialai-0.0.13.tar.gz.
File metadata
- Download URL: trivialai-0.0.13.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3eb5b46dd4b93ab2f6f5606493de946b8b6a8b91a869b660837ab8ee78d5b2aa
|
|
| MD5 |
6ef53349b943ec4b1ae898b9b55219cb
|
|
| BLAKE2b-256 |
e3ea4bdb88949dec6cc5719c02ef88e14f38eb81ce3b448b73b987f5e82c9bb4
|
File details
Details for the file trivialai-0.0.13-py3-none-any.whl.
File metadata
- Download URL: trivialai-0.0.13-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7bf0d29ab97046d797c24df1337c65c2fb745d3334e54ab7f7aa8b9f738c25e
|
|
| MD5 |
3ef0a81df84b955af82c28169859e399
|
|
| BLAKE2b-256 |
8a7426c5bcace4fd604aad76636f9e2afda8dffcb856424989e4c69d96cca166
|