opperai 0.0.4__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opperai/__init__.py +1 -0
- opperai/client.py +42 -0
- opperai/functions.py +35 -0
- opperai/types/__init__.py +34 -0
- opperai-0.0.4.dist-info/METADATA +45 -0
- opperai-0.0.4.dist-info/RECORD +7 -0
- opperai-0.0.4.dist-info/WHEEL +5 -0
opperai/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .client import AsyncClient, Client
|
opperai/client.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from .functions import Functions, AsyncFunctions
|
|
3
|
+
|
|
4
|
+
DEFAULT_API_URL = "https://api.opper.ai"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AsyncClient:
|
|
8
|
+
def __init__(self, api_key: str, api_url: str = DEFAULT_API_URL):
|
|
9
|
+
self.http_client = _async_http_client(api_key, api_url)
|
|
10
|
+
self.functions = AsyncFunctions(self.http_client)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Client:
|
|
14
|
+
def __init__(self, api_key: str, api_url: str = DEFAULT_API_URL):
|
|
15
|
+
self.http_client = _http_client(api_key, api_url)
|
|
16
|
+
self.functions = Functions(self.http_client)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class _async_http_client:
|
|
20
|
+
def __init__(self, api_key: str, api_url):
|
|
21
|
+
self.session = httpx.AsyncClient(
|
|
22
|
+
base_url=api_url, headers={"X-OPPER-API-KEY": f"{api_key}"}
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
async def do_request(self, method: str, path: str, **kwargs):
|
|
26
|
+
response = await self.session.request(method, path, **kwargs)
|
|
27
|
+
if response.status_code != 200:
|
|
28
|
+
raise Exception(f"Request failed with status {response.status_code}")
|
|
29
|
+
return response.json()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _http_client:
|
|
33
|
+
def __init__(self, api_key: str, api_url: str):
|
|
34
|
+
self.session = httpx.Client(
|
|
35
|
+
base_url=api_url, headers={"X-OPPER-API-KEY": f"{api_key}"}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def do_request(self, method: str, path: str, **kwargs):
|
|
39
|
+
response = self.session.request(method, path, **kwargs)
|
|
40
|
+
if response.status_code != 200:
|
|
41
|
+
raise Exception(f"Request failed with status {response.status_code}")
|
|
42
|
+
return response.json()
|
opperai/functions.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from .types import ChatPayload, FunctionResponse
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Functions:
|
|
5
|
+
def __init__(self, http_client):
|
|
6
|
+
self.http_client = http_client
|
|
7
|
+
|
|
8
|
+
def chat(self, function_path, data: ChatPayload, stream=False) -> FunctionResponse:
|
|
9
|
+
serialized_data = data.model_dump()
|
|
10
|
+
|
|
11
|
+
data = self.http_client.do_request(
|
|
12
|
+
"POST",
|
|
13
|
+
f"/v1/chat/{function_path}",
|
|
14
|
+
json=serialized_data,
|
|
15
|
+
params={"stream": "true"} if stream else None,
|
|
16
|
+
)
|
|
17
|
+
return FunctionResponse(**data)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AsyncFunctions:
|
|
21
|
+
def __init__(self, http_client):
|
|
22
|
+
self.http_client = http_client
|
|
23
|
+
|
|
24
|
+
async def chat(
|
|
25
|
+
self, function_path, data: ChatPayload, stream=False
|
|
26
|
+
) -> FunctionResponse:
|
|
27
|
+
serialized_data = data.model_dump()
|
|
28
|
+
|
|
29
|
+
data = await self.http_client.do_request(
|
|
30
|
+
"POST",
|
|
31
|
+
f"/v1/chat/{function_path}",
|
|
32
|
+
json=serialized_data,
|
|
33
|
+
params={"stream": "true"} if stream else None,
|
|
34
|
+
)
|
|
35
|
+
return FunctionResponse(**data)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Message(BaseModel):
|
|
6
|
+
role: str
|
|
7
|
+
content: str
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ChatPayload(BaseModel):
|
|
11
|
+
messages: List[Message]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ContextData(BaseModel):
|
|
15
|
+
embeddings_id: str
|
|
16
|
+
embeddings_table: str
|
|
17
|
+
dataset_id: int
|
|
18
|
+
content: str
|
|
19
|
+
score: Optional[float]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class DebugData(BaseModel):
|
|
23
|
+
context: List[ContextData]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class StreamingChunk(BaseModel):
|
|
27
|
+
delta: str
|
|
28
|
+
error: Optional[str] = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class FunctionResponse(BaseModel):
|
|
32
|
+
message: str
|
|
33
|
+
error: Optional[str] = None
|
|
34
|
+
debug: Optional[DebugData] = None
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: opperai
|
|
3
|
+
Version: 0.0.4
|
|
4
|
+
Summary: Opper Python client
|
|
5
|
+
Project-URL: Homepage, https://opper.ai
|
|
6
|
+
Project-URL: Documentation, https://docs.opper.ai
|
|
7
|
+
Project-URL: Platform, https://platform.opper.ai
|
|
8
|
+
Author-email: Opper <opper@opper.ai>
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Dist: httpx
|
|
13
|
+
Requires-Dist: pydantic
|
|
14
|
+
Provides-Extra: test
|
|
15
|
+
Requires-Dist: pytest; extra == 'test'
|
|
16
|
+
Requires-Dist: pytest-asyncio; extra == 'test'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# [Opper](https//opper.ai) Python SDK
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install opperai
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Functions
|
|
28
|
+
|
|
29
|
+
To call a function you created at [https://platform.opper.ai](https://platform.opper.ai) you can use the following code:
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from opper import Client
|
|
34
|
+
from opper.types import ChatPayload, Message
|
|
35
|
+
|
|
36
|
+
# Use AsyncClient for async operations
|
|
37
|
+
client = Client(api_key="your-api-key")
|
|
38
|
+
response = client.functions.chat("your-function-path",
|
|
39
|
+
ChatPayload(messages=[Message(role="user", content="hello")])
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
print(response)
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
opperai/__init__.py,sha256=FRzbO1SjaKqzpMMeMLLNAXqzp9ljnwiGgHfhQCnGKS4,40
|
|
2
|
+
opperai/client.py,sha256=4sRgGa_1woZEqeE1F3sF2m07podxsyYml6HyfhJunmQ,1474
|
|
3
|
+
opperai/functions.py,sha256=rOQLwzGY3G8yZU5NTgmLyCgJ0xgYJYmdh8SxOF59ggo,1034
|
|
4
|
+
opperai/types/__init__.py,sha256=KGTlAHgDRAzvLqSpHWFo_1OcDIMdRUoE8fLcoQ9iVys,603
|
|
5
|
+
opperai-0.0.4.dist-info/METADATA,sha256=Fm0xxkVYZGnuHugYoZVkzSczqll2Lf9ARnpo_zlqFhE,1121
|
|
6
|
+
opperai-0.0.4.dist-info/WHEEL,sha256=VYAwk8D_V6zmIA2XKK-k7Fem_KAtVk3hugaRru3yjGc,105
|
|
7
|
+
opperai-0.0.4.dist-info/RECORD,,
|