forked from Qewertyy/LexicaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |