Ouro
  • Docs
  • Blog
Join for freeSign in
  • Teams
  • Search
Assets
  • Quests
  • Posts
  • APIs
  • Data
  • Teams
  • Search
Assets
  • Quests
  • Posts
  • APIs
  • Data
4mo
249 views

On this page

  • Route use from Ouro's Python SDK
  • Loading a route to use
    • Uploading and using files
    • Using the route with a file input
Loading compatible actions...

Route use from Ouro's Python SDK

Finally got to adding route and service functionalities to the Python SDK. Previously, users could make simple HTTP request to use the Water layer.

Now, it should be much more user friendly. To get started, install or upgrade your ouro-py package:

bash
pip install -U ouro-py

Loading a route to use

Loading a route to use is the primary use case here. This will allow you to easily use the external functionalities added by other users while Ouro handles things like rate limiting and monetization automatically.

First, initialize the Ouro client. You can find or generate an API key in your account settings.

python
from ouro import Ouro
import dotenv

dotenv.load_dotenv()

api_key = os.getenv("OURO_API_KEY")
ouro = Ouro(api_key=api_key)

Now you have access to an authenticated ouro client from which you can do everything else.

Let's load up a route:

python
route = ouro.routes.retrieve("hermes/post-magnetism-curie-temperature")

You can find a route you want to use here and copy the name (username/route_name) like above, or copy the ID and load it that way:

python
route = ouro.routes.retrieve("daf42af4-a3e4-4f9e-af65-6ecaafc26334")

You'll find the ID to copy in the settings (Cog icon) menu in the header of the route page.

Now, you have a route instance we can start using!

This particular route actually takes in a file as input. Let me show you how you can use the SDK to upload and use files too.

Uploading and using files

You can upload a file from your local file system by setting the file_path parameter, like so:

python
file = ouro.files.create(
    name="Iron",
    description="CIF file for BCC Rron",
    visibility="public",
    file_path="./Fe.cif",
)

You will get a file instance back that you can now work with. If you're working from Python, you'll always be able to track your work and what you've done from the web interface too. You should see the file show up in /datasets.

Using the route with a file input

To use this file as input to the route, the easier approach looks like the following:

python
# Send the request with our file in the body
res = route.use(
    input_asset={
        "assetId": file.id,
        "assetType": file.asset_type
    },
)

And that's about it! If you have a route that takes other parameters beyond a file (or any other asset type) input, it may look like the following:

python
route = ouro.routes.retrieve("openai/post-images-analyze")
res = route.use(
    body={
        "prompt": "What do you see in this image?"
    },
    input_asset={
        "assetId": "fb4d4556-a48e-4b23-b1d3-51e975b9f5bd",
        "assetType": "file"
    },
)

Let me know if you have any questions! I'll be working on the public docs for these updates soon. Happy building.

Loading comments...