Metadata-Version: 2.4
Name: dyadic
Version: 1.1.0
Summary: The official Python SDK for the Dyadic API: runs with your own agents and functions, plus the OpenAI-compatible API.
Author: Dyadic
License: MIT
Project-URL: Homepage, https://dyadic.app/developers/
Project-URL: Documentation, https://dyadic.app/developers/
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: httpx<1,>=0.25

# dyadic

The official Python SDK for the [Dyadic API](https://dyadic.app/developers/): use Iris
from Python with streaming, function calling, images and typed errors. Requests use your Dyadic credits.

```sh
pip install dyadic
```

```python
from dyadic import Dyadic

client = Dyadic()  # reads DYADIC_API_KEY
print(client.ask("Hello!", model="iris"))
```

## 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.

```python
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.

```python
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.
