dyadic
The official Python SDK for the Dyadic API: use Iris from Python with streaming, function calling, images and typed errors. Requests use your Dyadic credits.
pip install dyadic
from dyadic import Dyadic
client = Dyadic() # reads DYADIC_API_KEY
print(client.ask("Hello!", model="iris"))
Keep your key on the server
A Dyadic API key is a long-lived secret that spends your credits. Use it only in server-side code; never put it in a mobile app, a desktop app you ship, or anything that runs in someone else's browser. Front-end code should call your own server, which calls Dyadic.
request() only ever sends the key to the API you configured: a relative path
joins base_url, and an absolute URL on any other host, port or scheme (or with
credentials in it) raises DyadicError instead of being sent. Redirects are not
followed. Plain http:// is accepted only for a local or private-network API
(localhost, a private IP, or a single-label name such as dyadic-api).
Retries
GET, HEAD, DELETE and OPTIONS are retried on busy or failing servers. Anything
else (a completion, an upload, a run) may already have run, and been billed,
when it fails, so it is retried only if it provably never started: the
connection was never made, or Dyadic refused it with rate_limit_exceeded or
concurrency_limit. Every attempt of one call carries the same
Idempotency-Key; pass idempotency_key= to choose it, or idempotent=True to
request() for a call that is safe to send twice.
Runs: your own agent, Dyadic's tools, your functions
An application brings its own agent (name and instructions), lets it use
Dyadic's built-in tools, and gives it functions it runs itself. runs.run
calls your functions whenever the agent asks and returns the finished run.
def lookup_order(order_id):
"""Look up an order by id."""
return {"order_id": order_id, "status": "shipped"}
lookup_order.schema = {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]}
run = client.runs.run(
agent={"id": "helpdesk", "name": "Helpdesk", "instructions": "You answer customers of a small shop."},
messages=[{"role": "user", "content": "Where is order 1042? Also, what's the weather in Lisbon today?"}],
builtin_tools=["data.web_search", "data.web_fetch"],
functions={"lookup_order": lookup_order},
end_user="customer-17", # your own id for who asked, kept with the run's usage
conversation_id="ticket-88",
)
print(run.output_text, run.credits)
runs.create(..., stream=True) streams events (run.started, status,
tool.started, tool.completed, sources, image.generated, delta,
requires_action, run.completed).
Connected apps: saving into a person's Workspace
With the person's approval, an application can save into their Dyadic Workspace, naming them by the Discord account linked to their Dyadic account.
from dyadic import DyadicError
status = client.connections.discord(discord_id)
if not status.authorized:
print("Allow this app:", status.authorize_url) # show the person this link
try:
saved = client.workspace.saves.create(discord_id=discord_id, kind="message", title="From #general",
text="Worth keeping", url="https://discord.com/channels/1/2/3")
print(saved.url)
except DyadicError as error:
if error.code == "authorization_required":
print("Allow this app:", error.body["authorize_url"])
kind is message, conversation (with messages, saved as a chat the
person can continue unless as_chat=False), image or file (with files:
base64, up to 10 of 8 MB).
See https://dyadic.app/developers/ for the full guide.
Metadata
Release files for dyadic 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dyadic-1.2.0.tar.gz | 22.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dyadic-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.5 kB
Release files / dyadic-1.2.0.tar.gz
| Download URL | dyadic-1.2.0.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c56929f8616461daf8b44c187181e325477c9d0026144b20b7d481eb3fb2b942
|
|
BLAKE2b-256 checksum How to use checksums |
cee407d11e281721228519949ff429252b02f5a9c52fa175cfe304b0c1875ed8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / dyadic-1.2.0-py3-none-any.whl
| Download URL | dyadic-1.2.0-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0effc03fcced85b1eb202f1e4754b53d46c8b8e067c243b3c4d6015670c084b1
|
|
BLAKE2b-256 checksum How to use checksums |
4e175027445ffd47a5e87048720623217ba12923ca2b4eb7c0d4e03bde4a5345
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|