An unofficial async client library for Straico API
Project description
Async Client Libary for the Straico API
A client side implementation of Straico API.
Installation
# install from PyPI
pip install aio-straico
Usage
Please see the official Straico API documentation https://documenter.getpostman.com/view/5900072/2s9YyzddrR
Basic Prompt Completion
from aio_straico.client import aio_straico_client
from aio_straico.utils import cheapest_model
async def main():
async with aio_straico_client(API_KEY="ko-11111111111111111111111111", ssl=False) as client:
user_info = await client.user()
print(user_info)
"""
{'data': {'coins': 100000.00,
'first_name': 'User',
'last_name': 'Name',
'plan': 'License Tier 1'},
"""
models = await client.models()
cheapest_chat_model = cheapest_model(models)
print(cheapest_chat_model)
"""
{'name': 'Google: Gemma 2 27B',
'model': 'google/gemma-2-27b-it',
'word_limit': 3072,
'pricing': {'coins': 0.4,
'words': 100}}
"""
reply = await client.prompt_completion(cheapest_chat_model, "Hello there")
print(reply["completion"]["choices"][0]["message"]["content"])
"""
General Kenobi! 👋
What can I do for you today? 😊
"""
asyncio.run(main())
when API_KEY
is not set in aio_straico_client, it will use the value from environment variable STRAICO_API_KEY
.
If no environment variable is found the program will raise an error.
You can also set the model name manually
reply = await client.prompt_completion("openai/gpt-4o-mini", "Hello there")
print(reply["completion"]["choices"][0]["message"]["content"])
"""
General Kenobi! 👋
What can I do for you today? 😊
"""
Add file attachment and Transcript
mp3_files = [*Path("test_data/audio/").glob("*.mp3")]
response = await client.prompt_completion(
"openai/gpt-4o-mini",
"summarize the main points",
files=mp3_files,
display_transcripts=True,
)
print("## Summary")
print(
response["completions"]["openai/gpt-4o-mini"]["completion"]["choices"][0][
"message"
]["content"]
)
print("## Transcript")
for transcript in response["transcripts"]:
print("Name:", transcript["name"])
print("Transcript:", transcript["text"])
print()
"""
## Summary
The . . .
## Transcript
Name: . . .
Transcript: . . .
"""
Add Youtube URL and Transcript
youtube_url = "https://www.youtube.com/watch?v=zWPe_CUR4yU"
response = await client.prompt_completion(
"openai/gpt-4o-mini",
"summarize the main points",
youtube_urls=youtube_url,
display_transcripts=True,
)
print("## Summary")
print(
response["completions"]["openai/gpt-4o-mini"]["completion"]["choices"][0][
"message"
]["content"]
)
print("## Transcript")
for transcript in response["transcripts"]:
print("Name:", transcript["name"])
print("Transcript:", youtube_trasncript_to_plain_text(transcript["text"]))
print()
"""
## Summary
The . . .
## Transcript
Name: . . .
Transcript: . . .
"""
Image Generation
Generate images and download zip file to local directory
model ="openai/dall-e-3"
directory = Path(".")
# with tempfile.TemporaryDirectory() as temp_directory:
zip_file_path = await client.image_generation_as_zipfile(
model=model,
description="A cute cat",
size=ImageSize.square,
variations=4,
destination_zip_path=directory,
)
Generate images and download image files to local directory
model ="openai/dall-e-3"
directory = Path(".")
# with tempfile.TemporaryDirectory() as temp_directory:
image_paths = await client.image_generation_as_images(
model=model,
description="A cute cat",
size=ImageSize.landscape,
variations=4,
destination_zip_path=directory,
)
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
aio_straico-0.0.3.tar.gz
(9.1 kB
view details)
Built Distribution
File details
Details for the file aio_straico-0.0.3.tar.gz
.
File metadata
- Download URL: aio_straico-0.0.3.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba2f5a1b8d6684222ce5f014a3cf92ec5b57655d56780010255b84400e9f40b1 |
|
MD5 | 42098070d7b282f07129ea005e8fa474 |
|
BLAKE2b-256 | 677ac768bf42ea6a5e4976dc92378981c62ff265121550bbf7b0f0767d6d0a77 |
File details
Details for the file aio_straico-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: aio_straico-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30e51b29a6e10ec1e8ce1db0c7e3e9c3f6d0fe606e1b6cb94264abf6f106df5a |
|
MD5 | 255a286b569cf10ee550832cf21354ee |
|
BLAKE2b-256 | 70b29e3b6fca81e0a70523ad62d6aa13aa2999aba6071dbf3c58cd73eea83f00 |