Skip to content

Commit

Permalink
plam client, initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Qewertyy committed Jul 24, 2023
1 parent 577e78b commit 4047ac3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
10 changes: 10 additions & 0 deletions openapi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2023 Qewertyy, MIT License

import os
from openapi.core import Client

__all__ = [
"Client"
]
__version__ = "0.0.1"
__author__ = "Qewertyy <[email protected]>"
6 changes: 6 additions & 0 deletions openapi/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BASE_URL = "https://api.qewertyy.me"

SESSION_HEADERS = {
"Host": "api.qewertyy.me",
"Content-Type": "application/json",
}
51 changes: 51 additions & 0 deletions openapi/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from openapi.constansts import *
from httpx import AsyncClient

class Client:
"""
OpenApi Package for interacting with OpenAPI `api.qewertyy.me`
"""

def __init__(
self,
self.url = BASE_URL,
self.timeout = 30,
):
"""
Initialize the client instance
"""
self.session = AsyncClient(
http2=True,
headers=SESSION_HEADERS
)

async def palm(self, prompt: str) -> dict:
"""
Get an answer from Palm 2 for the given prompt
Example:
>>> client = Client()
>>> response = client.palm("Hello, Who are you?")
>>> print(response['content'])
Args:
prompt (str): Input text for the query.
Returns:
dict: Answer from the Open API in the following format:
{
"status": str,
"content": str
}
"""
params = {
"model_id": 0,
"prompt":prompt
}
try:
resp = await self.session.post(
f"{self.url}/models",
params=params,
timeout=self.timeout
)
except Exception as e:
print(f"Request failed: {e}")

0 comments on commit 4047ac3

Please sign in to comment.