Add a python client library

We still don't have any documentation and things are in flux, but you can report your OpenAI API calls to OpenPipe now.
This commit is contained in:
Kyle Corbitt
2023-08-11 16:54:50 -07:00
parent d9db6d80ea
commit 8ed47eb4dd
32 changed files with 2698 additions and 85 deletions

View File

@@ -0,0 +1,56 @@
from openpipe.api_client.api.default import external_api_report
from openpipe.api_client.client import AuthenticatedClient
from openpipe.api_client.models.external_api_report_json_body_tags import (
ExternalApiReportJsonBodyTags,
)
import toml
version = toml.load("pyproject.toml")["tool"]["poetry"]["version"]
configured_client = AuthenticatedClient(
base_url="https://app.openpipe.ai/api/v1", token=""
)
def _get_tags(openpipe_options):
tags = openpipe_options.get("tags") or {}
tags["$sdk"] = "python"
tags["$sdk_version"] = version
return ExternalApiReportJsonBodyTags.from_dict(tags)
def report(
openpipe_options={},
**kwargs,
):
try:
external_api_report.sync_detailed(
client=configured_client,
json_body=external_api_report.ExternalApiReportJsonBody(
**kwargs,
tags=_get_tags(openpipe_options),
),
)
except Exception as e:
# We don't want to break client apps if our API is down for some reason
print(f"Error reporting to OpenPipe: {e}")
print(e)
async def report_async(
openpipe_options={},
**kwargs,
):
try:
await external_api_report.asyncio_detailed(
client=configured_client,
json_body=external_api_report.ExternalApiReportJsonBody(
**kwargs,
tags=_get_tags(openpipe_options),
),
)
except Exception as e:
# We don't want to break client apps if our API is down for some reason
print(f"Error reporting to OpenPipe: {e}")
print(e)