add base files, not working yet
This commit is contained in:
0
src/hawkiapi/__init__.py
Normal file
0
src/hawkiapi/__init__.py
Normal file
71
src/hawkiapi/api.py
Normal file
71
src/hawkiapi/api.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import httpx
|
||||
from typing import Optional, Dict, Any
|
||||
class HawkiAPI:
|
||||
def __init__(self, base_url: str, access_token: Optional[str] = None):
|
||||
self.base_url = base_url
|
||||
self.client = httpx.Client(base_url=self.base_url)
|
||||
if access_token is None:
|
||||
raise ValueError("Access token must be provided.")
|
||||
if access_token:
|
||||
self.client.headers["Authorization"] = f"Bearer {access_token}"
|
||||
self.client.headers["Accept"] = "application/json"
|
||||
self.client.headers["Content-Type"] = "application/json"
|
||||
|
||||
def chat(self, role:str="user", model:str = "gpt-4o", message:str = "")-> str:
|
||||
'''
|
||||
Sends a chat message to the Hawki API and returns the response.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
role : str, optional
|
||||
The role of the message sender, by default "user"
|
||||
model : str, optional
|
||||
The model to use for the chat, by default "gpt-4o"
|
||||
message : str, optional
|
||||
The content of the message to send, by default ""
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The response from the Hawki API.
|
||||
'''
|
||||
data = {
|
||||
"payload": {
|
||||
"model": model,
|
||||
"messages": [
|
||||
{
|
||||
"role": role,
|
||||
"content": {
|
||||
"text": message
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
response = self.client.post("/api/ai-req", json=data)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class HawkiAsyncAPI:
|
||||
def __init__(self, base_url: str):
|
||||
self.base_url = base_url
|
||||
self.client = httpx.AsyncClient(base_url=self.base_url)
|
||||
|
||||
async def get(self, endpoint: str, params: dict = None):
|
||||
response = await self.client.get(endpoint, params=params)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def post(self, endpoint: str, data: dict = None):
|
||||
response = await self.client.post(endpoint, json=data)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def close(self):
|
||||
await self.client.aclose()
|
||||
0
src/hawkiapi/py.typed
Normal file
0
src/hawkiapi/py.typed
Normal file
Reference in New Issue
Block a user