An unofficial async/sync 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 import straico_client
from aio_straico.utils import cheapest_model
def main():
with straico_client(API_KEY="ko-11111111111111111111111111") as client:
user_info = client.user()
print(user_info)
"""
{'coins': 100000.00,
'first_name': 'User',
'last_name': 'Name',
'plan': 'License Tier 1'}
"""
models = 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 = client.prompt_completion(cheapest_chat_model, "Hello there")
print(reply["completion"]["choices"][0]["message"]["content"])
"""
General Kenobi! 👋
What can I do for you today? 😊
"""
if __name__=="__main__":
main()
Async Basic Prompt Completion
from aio_straico import aio_straico_client
from aio_straico.utils import cheapest_model
async def main():
async with aio_straico_client(API_KEY="ko-11111111111111111111111111") as client:
user_info = await client.user()
print(user_info)
"""
{'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? 😊
"""
Example Async Code
While the code below is async code, it can also be executed in a non-async mode by removing "await" and using the code with straico_client as shown in the "Basic Prompt Completion" section.
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(".")
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(".")
image_paths = await client.image_generation_as_images(
model=model,
description="A cute cat",
size=ImageSize.landscape,
variations=4,
destination_zip_path=directory,
)
RAG (Retrieval Augmented Generation)
Creating a RAG
Async Example
from aio_straico import aio_straico_client
from pathlib import Path
async def main():
async with aio_straico_client() as client:
# Create a RAG by providing a name, description, and files to index
rag = await client.create_rag(
"My Code RAG",
"RAG for my project files",
Path("./my_project/utils.py"),
Path("./my_project/main.py")
)
print(rag) # Print RAG details
# Alternatively, create a new RAG object
rag_obj = await client.new_rag(
"My Code RAG",
"RAG for my project files",
Path("./my_project/utils.py"),
Path("./my_project/main.py")
)
print(rag_obj.data)
Synchronous Example
from aio_straico import straico_client
from pathlib import Path
def main():
with straico_client() as client:
# Create a RAG by providing a name, description, and files to index
rag = client.create_rag(
"My Code RAG",
"RAG for my project files",
Path("./my_project/utils.py"),
Path("./my_project/main.py")
)
print(rag) # Print RAG details
# Alternatively, create a new RAG object
rag_obj = client.new_rag(
"My Code RAG",
"RAG for my project files",
Path("./my_project/utils.py"),
Path("./my_project/main.py")
)
print(rag_obj.data)
Deleting a RAG
Async Example
async def delete_rag():
async with aio_straico_client() as client:
# Get existing RAGs
rags = await client.rags()
rag_id = rags[0]['_id'] # Get ID of first RAG
# Delete RAG by ID
await client.rag_delete(rag_id)
# Or delete RAG object directly
rag_obj = await client.rag(rag_id)
await rag_obj.delete()
Synchronous Example
def delete_rag():
with straico_client() as client:
# Get existing RAGs
rags = client.rags()
rag_id = rags[0]['_id'] # Get ID of first RAG
# Delete RAG by ID
client.rag_delete(rag_id)
# Or delete RAG object directly
rag_obj = client.rag(rag_id)
rag_obj.delete()
RAG Prompt Completion
Async Example
async def rag_prompt():
async with aio_straico_client() as client:
# Get existing RAGs
rags = await client.rags()
rag_id = rags[0]['_id'] # Get ID of first RAG
# Get available models
models = await client.models()
cheapest_model = cheapest_model(models)
# Perform RAG prompt completion
response = await client.rag_prompt_completion(
rag_id,
cheapest_model,
"Explain the main functionality of my project"
)
print(response)
# Alternatively, with RAG object
rag_obj = await client.rag(rag_id)
response = await rag_obj.prompt_completion(
cheapest_model,
"Explain the main functionality of my project"
)
print(response)
Synchronous Example
def rag_prompt():
with straico_client() as client:
# Get existing RAGs
rags = client.rags()
rag_id = rags[0]['_id'] # Get ID of first RAG
# Get available models
models = client.models()
cheapest_model = cheapest_model(models)
# Perform RAG prompt completion
response = client.rag_prompt_completion(
rag_id,
cheapest_model,
"Explain the main functionality of my project"
)
print(response)
# Alternatively, with RAG object
rag_obj = client.rag(rag_id)
response = rag_obj.prompt_completion(
cheapest_model,
"Explain the main functionality of my project"
)
print(response)
Agents
Creating an Agent
Async Example
from aio_straico import aio_straico_client
from aio_straico.utils import cheapest_model
async def create_agent():
async with aio_straico_client() as client:
# Get available models
models = await client.models()
cheapest_chat_model = cheapest_model(models)
# Create a new agent
agent = await client.create_agent(
"My Project Agent",
"An agent to help with my project",
cheapest_chat_model,
"You are a helpful assistant for my project.",
["Python", "Project"]
)
print(agent) # Print agent details
# Alternatively, create a new agent object
agent_obj = await client.new_agent(
"My Project Agent",
"An agent to help with my project",
cheapest_chat_model,
"You are a helpful assistant for my project.",
["Python", "Project"]
)
print(agent_obj.data)
Synchronous Example
from aio_straico import straico_client
from aio_straico.utils import cheapest_model
def create_agent():
with straico_client() as client:
# Get available models
models = client.models()
cheapest_chat_model = cheapest_model(models)
# Create a new agent
agent = client.create_agent(
"My Project Agent",
"An agent to help with my project",
cheapest_chat_model,
"You are a helpful assistant for my project.",
["Python", "Project"]
)
print(agent) # Print agent details
# Alternatively, create a new agent object
agent_obj = client.new_agent(
"My Project Agent",
"An agent to help with my project",
cheapest_chat_model,
"You are a helpful assistant for my project.",
["Python", "Project"]
)
print(agent_obj.data)
Adding a RAG to an Agent
Async Example
async def add_rag_to_agent():
async with aio_straico_client() as client:
# Get existing RAGs and Agents
rags = await client.rags()
rag_id = rags[0]['_id'] # Get ID of first RAG
agents = await client.agents()
agent_id = agents[0]['_id'] # Get ID of first agent
# Add RAG to agent by ID
await client.agent_add_rag(agent_id, rag_id)
# Or add RAG to agent object directly
agent_obj = await client.agent(agent_id)
await agent_obj.update(rag=rag_id)
Synchronous Example
def add_rag_to_agent():
with straico_client() as client:
# Get existing RAGs and Agents
rags = client.rags()
rag_id = rags[0]['_id'] # Get ID of first RAG
agents = client.agents()
agent_id = agents[0]['_id'] # Get ID of first agent
# Add RAG to agent by ID
client.agent_add_rag(agent_id, rag_id)
# Or add RAG to agent object directly
agent_obj = client.agent(agent_id)
agent_obj.update(rag=rag_id)
Updating an Agent
Async Example
async def update_agent():
async with aio_straico_client() as client:
# Get an existing agent
agents = await client.agents()
agent_id = agents[0]['_id']
# Update agent details
await client.agent_update(
agent_id,
name="Updated Agent Name",
description="Updated description",
system_prompt="You are an updated helpful assistant."
)
# Or update agent object directly
agent_obj = await client.agent(agent_id)
await agent_obj.update(
name="Updated Agent Name",
description="Updated description",
system_prompt="You are an updated helpful assistant."
)
Synchronous Example
def update_agent():
with straico_client() as client:
# Get an existing agent
agents = client.agents()
agent_id = agents[0]['_id']
# Update agent details
client.agent_update(
agent_id,
name="Updated Agent Name",
description="Updated description",
system_prompt="You are an updated helpful assistant."
)
# Or update agent object directly
agent_obj = client.agent(agent_id)
agent_obj.update(
name="Updated Agent Name",
description="Updated description",
system_prompt="You are an updated helpful assistant."
)
Agent Prompt Completion
Async Example
async def agent_prompt():
async with aio_straico_client() as client:
# Get existing agents
agents = await client.agents()
agent_id = agents[0]['_id'] # Get ID of first agent
# Perform agent prompt completion
response = await client.agent_prompt_completion(
agent_id,
"Explain the main functionality of my project"
)
print(response)
# Alternatively, with agent object
agent_obj = await client.agent(agent_id)
response = await agent_obj.prompt_completion(
"Explain the main functionality of my project"
)
print(response)
Synchronous Example
def agent_prompt():
with straico_client() as client:
# Get existing agents
agents = client.agents()
agent_id = agents[0]['_id'] # Get ID of first agent
# Perform agent prompt completion
response = client.agent_prompt_completion(
agent_id,
"Explain the main functionality of my project"
)
print(response)
# Alternatively, with agent object
agent_obj = client.agent(agent_id)
response = agent_obj.prompt_completion(
"Explain the main functionality of my project"
)
print(response)
Deleting an Agent
Async Example
async def delete_agent():
async with aio_straico_client() as client:
# Get existing agents
agents = await client.agents()
agent_id = agents[0]['_id'] # Get ID of first agent
# Delete agent by ID
await client.agent_delete(agent_id)
# Or delete agent object directly
agent_obj = await client.agent(agent_id)
await agent_obj.delete()
Synchronous Example
def delete_agent():
with straico_client() as client:
# Get existing agents
agents = client.agents()
agent_id = agents[0]['_id'] # Get ID of first agent
# Delete agent by ID
client.agent_delete(agent_id)
# Or delete agent object directly
agent_obj = client.agent(agent_id)
agent_obj.delete()
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
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 aio_straico-0.1.0.tar.gz.
File metadata
- Download URL: aio_straico-0.1.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bc05afaaf8debc4fb6ad385f563c1d86816d16844435565fbcf5cfc8dfcb2bd
|
|
| MD5 |
d322b3dc6076cca46934fac1a4dc69c8
|
|
| BLAKE2b-256 |
6bb85b922c8522898327d080780bdc643c46adce95b2d942dabac59f2297732f
|
File details
Details for the file aio_straico-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aio_straico-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.5 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 |
369a5b328e3085b1478f0964d0ef8134610e54430d4c01197a3621ae70c7c847
|
|
| MD5 |
c9e7e3afe46075ec3c72f8110956d9a3
|
|
| BLAKE2b-256 |
933b6bd37a4248e74607a909a27f1a0f877c73eb88d4452fc99a366ee9a2a2e0
|