Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

<div align="center">
<a href="https://codespaces.new/livepeer/livepeer-ai-python.git/tree/main"><img src="https://github.com/codespaces/badge.svg" /></a>
</div>
<br>

> **Remember to shutdown a GitHub Codespace when it is not in use!**

# Dev Containers Quick Start
Expand All @@ -20,11 +25,11 @@ The speakeasy CLI allows you to generate more usage snippets. Here's how:
- To generate a sample for a specific operation by providing an operation ID, use:

```
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json -l python -i {INPUT_OPERATION_ID} -o ./samples
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.yaml -l python -i {INPUT_OPERATION_ID} -o ./samples
```

- To generate samples for an entire namespace (like a tag or group name), use:

```
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json -l python -n {INPUT_TAG_NAME} -o ./samples
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.yaml -l python -n {INPUT_TAG_NAME} -o ./samples
```
2 changes: 1 addition & 1 deletion .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ python -m pip install --upgrade pip
pip install -e .

# Generate starter usage sample with speakeasy
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json -l python -o samples/root.py
speakeasy generate usage -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.yaml -l python -o samples/root.py
10 changes: 5 additions & 5 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
lockVersion: 2.0.0
id: 2d5dbf5a-62be-411a-9c7b-bc7b6dc79e13
management:
docChecksum: c222ffbf28e5f62770dc8cbd99010f96
docChecksum: cd6c43d2e31a6a23e22275e50c38d52e
docVersion: v0.1.2
speakeasyVersion: 1.377.0
generationVersion: 2.404.0
releaseVersion: 0.1.4
configChecksum: a4b1b6e1d971710b6648986f1a937812
speakeasyVersion: 1.379.0
generationVersion: 2.404.3
releaseVersion: 0.1.5
configChecksum: 35690181912086c4003337e1ec0bd202
repoURL: https://github.com/livepeer/livepeer-ai-python.git
installationURL: https://github.com/livepeer/livepeer-ai-python.git
features:
Expand Down
4 changes: 2 additions & 2 deletions .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ configVersion: 2.0.0
generation:
devContainers:
enabled: true
schemaPath: https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json
schemaPath: https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.yaml
sdkClassName: LivepeerAI
maintainOpenAPIOrder: true
usageSnippets:
Expand All @@ -15,7 +15,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
python:
version: 0.1.4
version: 0.1.5
additionalDependencies:
dev: {}
main: {}
Expand Down
17 changes: 8 additions & 9 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
speakeasyVersion: 1.377.0
speakeasyVersion: 1.379.0
sources:
livepeer_ai-OAS:
sourceNamespace: livepeer-ai-oas
sourceRevisionDigest: sha256:eaa66566d7629ca0b84b572f39576e8b38b87667aaa688ea98cf87629f7647ea
sourceBlobDigest: sha256:88b77186fc98fe193435d3069ab2e85fe4d404e802e4e23761979e984649ff70
sourceRevisionDigest: sha256:6bd4223c4f6c0a9963663242f118035124c716e7c436049608219d24717cf099
sourceBlobDigest: sha256:a025967b0b9169763c785bb89478cb7716f70241d4e11d762734f3655b7fb0e5
tags:
- latest
- main
targets:
livepeer-ai:
source: livepeer_ai-OAS
Expand All @@ -17,18 +16,18 @@ targets:
livepeer-ai-python:
source: livepeer_ai-OAS
sourceNamespace: livepeer-ai-oas
sourceRevisionDigest: sha256:eaa66566d7629ca0b84b572f39576e8b38b87667aaa688ea98cf87629f7647ea
sourceBlobDigest: sha256:88b77186fc98fe193435d3069ab2e85fe4d404e802e4e23761979e984649ff70
sourceRevisionDigest: sha256:6bd4223c4f6c0a9963663242f118035124c716e7c436049608219d24717cf099
sourceBlobDigest: sha256:a025967b0b9169763c785bb89478cb7716f70241d4e11d762734f3655b7fb0e5
codeSamplesNamespace: code-samples-python-livepeer-python
codeSamplesRevisionDigest: sha256:4b4d5d53563acb0a29f44c857bb3b87e8455831c298a17c1b3d02a7f235caca0
outLocation: /github/workspace/repo
codeSamplesRevisionDigest: sha256:901ab5f5b4d211b224c6482b451f186affa42c56cdf08c25f191f875146987d5
outLocation: /home/ricks/development/livepeer/ai/livepeer-ai-python
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
sources:
livepeer_ai-OAS:
inputs:
- location: https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json
- location: https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.yaml
registry:
location: registry.speakeasyapi.dev/livepeer-8mq/livepeer-ai/livepeer-ai-oas
targets:
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ speakeasyVersion: latest
sources:
livepeer_ai-OAS:
inputs:
- location: https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.json
- location: https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/gateway.openapi.yaml
registry:
location: registry.speakeasyapi.dev/livepeer-8mq/livepeer-ai/livepeer-ai-oas
targets:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Welcome to the [Livepeer AI](https://livepeer.ai/) Python! This library offers a

PIP
```bash
pip install git+<UNSET>.git
pip install git+https://github.com/livepeer/livepeer-ai-python.git
```

Poetry
```bash
poetry add git+<UNSET>.git
poetry add git+https://github.com/livepeer/livepeer-ai-python.git
```
<!-- End SDK Installation [installation] -->

Expand Down
12 changes: 6 additions & 6 deletions codeSamples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ info:
title: CodeSamples overlay for python target
version: 0.0.0
actions:
- target: $["paths"]["/audio-to-text"]["post"]
update:
"x-codeSamples":
- "lang": "python"
"label": "audio_to_text"
"source": "from livepeer_ai import LivepeerAI\n\ns = LivepeerAI(\n http_bearer=\"<YOUR_BEARER_TOKEN_HERE>\",\n)\n\n\nres = s.audio_to_text(request={\n \"audio\": {\n \"file_name\": \"your_file_here\",\n \"content\": open(\"<file_path>\", \"rb\"),\n },\n})\n\nif res.text_response is not None:\n # handle response\n pass"
- target: $["paths"]["/text-to-image"]["post"]
update:
"x-codeSamples":
Expand All @@ -27,9 +33,3 @@ actions:
- "lang": "python"
"label": "upscale"
"source": "from livepeer_ai import LivepeerAI\n\ns = LivepeerAI(\n http_bearer=\"<YOUR_BEARER_TOKEN_HERE>\",\n)\n\n\nres = s.upscale(request={\n \"prompt\": \"<value>\",\n \"image\": {\n \"file_name\": \"your_file_here\",\n \"content\": open(\"<file_path>\", \"rb\"),\n },\n})\n\nif res.image_response is not None:\n # handle response\n pass"
- target: $["paths"]["/audio-to-text"]["post"]
update:
"x-codeSamples":
- "lang": "python"
"label": "audio_to_text"
"source": "from livepeer_ai import LivepeerAI\n\ns = LivepeerAI(\n http_bearer=\"<YOUR_BEARER_TOKEN_HERE>\",\n)\n\n\nres = s.audio_to_text(request={\n \"audio\": {\n \"file_name\": \"your_file_here\",\n \"content\": open(\"<file_path>\", \"rb\"),\n },\n})\n\nif res.text_response is not None:\n # handle response\n pass"
4 changes: 3 additions & 1 deletion docs/models/apierror.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# APIError

API error response model.


## Fields

| Field | Type | Required | Description |
| ------------------ | ------------------ | ------------------ | ------------------ |
| `msg` | *str* | :heavy_check_mark: | N/A |
| `msg` | *str* | :heavy_check_mark: | The error message. |
10 changes: 6 additions & 4 deletions docs/models/chunk.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Chunk

A chunk of text with a timestamp.


## Fields

| Field | Type | Required | Description |
| ------------------ | ------------------ | ------------------ | ------------------ |
| `timestamp` | List[*Any*] | :heavy_check_mark: | N/A |
| `text` | *str* | :heavy_check_mark: | N/A |
| Field | Type | Required | Description |
| --------------------------- | --------------------------- | --------------------------- | --------------------------- |
| `timestamp` | List[*Any*] | :heavy_check_mark: | The timestamp of the chunk. |
| `text` | *str* | :heavy_check_mark: | The text of the chunk. |
4 changes: 2 additions & 2 deletions docs/models/httperror.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# HTTPError

Bad Request
HTTP error response model.


## Fields

| Field | Type | Required | Description |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `detail` | [models.APIError](../models/apierror.md) | :heavy_check_mark: | N/A |
| `detail` | [models.APIError](../models/apierror.md) | :heavy_check_mark: | Detailed error information. |
4 changes: 3 additions & 1 deletion docs/models/imageresponse.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# ImageResponse

Response model for image generation.


## Fields

| Field | Type | Required | Description |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `images` | List[[models.Media](../models/media.md)] | :heavy_check_mark: | N/A |
| `images` | List[[models.Media](../models/media.md)] | :heavy_check_mark: | The generated images. |
12 changes: 7 additions & 5 deletions docs/models/media.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Media

A media object containing information about the generated media.


## Fields

| Field | Type | Required | Description |
| ------------------ | ------------------ | ------------------ | ------------------ |
| `url` | *str* | :heavy_check_mark: | N/A |
| `seed` | *int* | :heavy_check_mark: | N/A |
| `nsfw` | *bool* | :heavy_check_mark: | N/A |
| Field | Type | Required | Description |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `url` | *str* | :heavy_check_mark: | The URL where the media can be accessed. |
| `seed` | *int* | :heavy_check_mark: | The seed used to generate the media. |
| `nsfw` | *bool* | :heavy_check_mark: | Whether the media was flagged as NSFW. |
6 changes: 4 additions & 2 deletions docs/models/textresponse.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# TextResponse

Response model for text generation.


## Fields

| Field | Type | Required | Description |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `text` | *str* | :heavy_check_mark: | N/A |
| `chunks` | List[[models.Chunk](../models/chunk.md)] | :heavy_check_mark: | N/A |
| `text` | *str* | :heavy_check_mark: | The generated text. |
| `chunks` | List[[models.Chunk](../models/chunk.md)] | :heavy_check_mark: | The generated text chunks. |
4 changes: 3 additions & 1 deletion docs/models/videoresponse.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# VideoResponse

Response model for image generation.


## Fields

| Field | Type | Required | Description |
| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
| `images` | List[[models.Media](../models/media.md)] | :heavy_check_mark: | N/A |
| `images` | List[[models.Media](../models/media.md)] | :heavy_check_mark: | The generated images. |
10 changes: 5 additions & 5 deletions docs/sdks/livepeerai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Livepeer AI Runner: An application to run AI pipelines

## text_to_image

Text To Image
Generate images from text prompts.

### Example Usage

Expand Down Expand Up @@ -58,7 +58,7 @@ if res.image_response is not None:

## image_to_image

Image To Image
Apply image transformations to a provided image.

### Example Usage

Expand Down Expand Up @@ -106,7 +106,7 @@ if res.image_response is not None:

## image_to_video

Image To Video
Generate a video from a provided image.

### Example Usage

Expand Down Expand Up @@ -153,7 +153,7 @@ if res.video_response is not None:

## upscale

Upscale
Upscale an image by increasing its resolution.

### Example Usage

Expand Down Expand Up @@ -201,7 +201,7 @@ if res.image_response is not None:

## audio_to_text

Audio To Text
Transcribe audio files to text.

### Example Usage

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[tool.poetry]
name = "livepeer-ai"
version = "0.1.4"
version = "0.1.5"
description = "Python Client SDK for the Livepeer AI API."
authors = ["Livepeer",]
readme = "README-PYPI.md"
repository = "https://github.com/livepeer/livepeer-ai-python.git"
packages = [
{ include = "livepeer_ai", from = "src" }
]
Expand Down
30 changes: 27 additions & 3 deletions scripts/prepare-readme.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

import re
import shutil

try:
shutil.copyfile('README.md', 'README-PYPI.md')
with open("README.md", "r") as rh:
readme_contents = rh.read()
GITHUB_URL = "https://github.com/livepeer/livepeer-ai-python.git"
GITHUB_URL = (
GITHUB_URL[: -len(".git")] if GITHUB_URL.endswith(".git") else GITHUB_URL
)
# links on PyPI should have absolute URLs
readme_contents = re.sub(
r"(\[[^\]]+\]\()((?!https?:)[^\)]+)(\))",
lambda m: m.group(1)
+ GITHUB_URL
+ "/blob/master/"
+ m.group(2)
+ m.group(3),
readme_contents,
)

with open("README-PYPI.md", "w") as wh:
wh.write(readme_contents)
except Exception as e:
print("Failed to copy README.md to README-PYPI.md")
print(e)
try:
print("Failed to rewrite README.md to README-PYPI.md, copying original instead")
print(e)
shutil.copyfile("README.md", "README-PYPI.md")
except Exception as e:
print("Failed to copy README.md to README-PYPI.md")
print(e)
1 change: 1 addition & 0 deletions src/livepeer_ai/_hooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

from .sdkhooks import *
from .types import *
from .registration import *
13 changes: 13 additions & 0 deletions src/livepeer_ai/_hooks/registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .types import Hooks


# This file is only ever generated once on the first generation and then is free to be modified.
# Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
# in this file or in separate files in the hooks folder.


def init_hooks(hooks: Hooks):
# pylint: disable=unused-argument
"""Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
with an instance of a hook that implements that specific Hook interface
Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
2 changes: 2 additions & 0 deletions src/livepeer_ai/_hooks/sdkhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import httpx
from .types import SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks
from .registration import init_hooks
from typing import List, Optional, Tuple
from livepeer_ai.httpclient import HttpClient

Expand All @@ -11,6 +12,7 @@ def __init__(self) -> None:
self.before_request_hooks: List[BeforeRequestHook] = []
self.after_success_hooks: List[AfterSuccessHook] = []
self.after_error_hooks: List[AfterErrorHook] = []
init_hooks(self)

def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
self.sdk_init_hooks.append(hook)
Expand Down
Loading