mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 23:43:57 +01:00
Compare commits
No commits in common. "abb18ad1bfea830b2e2e83512a0646e721d2de41" and "d870281540b4899185a0ad25904408c3b9a668a7" have entirely different histories.
abb18ad1bf
...
d870281540
|
@ -4,7 +4,7 @@ import os
|
|||
import json
|
||||
import fastapi
|
||||
|
||||
from db.users import UserManager
|
||||
from users import UserManager
|
||||
|
||||
from dhooks import Webhook, Embed
|
||||
from dotenv import load_dotenv
|
||||
|
|
|
@ -9,7 +9,7 @@ from motor.motor_asyncio import AsyncIOMotorClient
|
|||
|
||||
load_dotenv()
|
||||
|
||||
with open('config/config.yml', encoding='utf8') as f:
|
||||
with open('config/credits.yml', encoding='utf8') as f:
|
||||
credits_config = yaml.safe_load(f)
|
||||
|
||||
## MONGODB Setup
|
||||
|
|
|
@ -9,7 +9,7 @@ from dotenv import load_dotenv
|
|||
import streaming
|
||||
import moderation
|
||||
|
||||
from db.users import UserManager
|
||||
from users import UserManager
|
||||
from helpers import tokens, errors
|
||||
|
||||
load_dotenv()
|
||||
|
@ -34,10 +34,7 @@ async def handle(incoming_request):
|
|||
if method not in allowed_methods:
|
||||
return await errors.error(405, f'Method "{method}" is not allowed.', 'Change the request method to the correct one.')
|
||||
|
||||
try:
|
||||
payload = await incoming_request.json()
|
||||
except json.decoder.JSONDecodeError:
|
||||
payload = {}
|
||||
|
||||
try:
|
||||
input_tokens = await tokens.count_for_messages(payload.get('messages', []))
|
||||
|
|
|
@ -33,7 +33,7 @@ def test_server():
|
|||
"""Tests if the API server is running."""
|
||||
|
||||
try:
|
||||
return httpx.get(f'{api_endpoint.replace("/v1", "")}').json()['status'] == 'ok'
|
||||
return httpx.get(f'{api_endpoint}').json()['status'] == 'ok'
|
||||
except httpx.ConnectError as exc:
|
||||
raise ConnectionError(f'API is not running on port {api_endpoint}.') from exc
|
||||
|
||||
|
@ -69,7 +69,7 @@ def test_library():
|
|||
return completion['choices'][0]['message']['content']
|
||||
|
||||
def test_library_moderation():
|
||||
return closedai.Moderation.create('I wanna kill myself, I wanna kill myself; It\'s all I hear right now, it\'s all I hear right now')
|
||||
return closedai.Moderation.create("I wanna kill myself, I wanna kill myself; It's all I hear right now, it's all I hear right now")
|
||||
|
||||
def test_models():
|
||||
response = httpx.get(
|
||||
|
@ -80,7 +80,25 @@ def test_models():
|
|||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def test_api_moderation() -> dict:
|
||||
def test_all():
|
||||
"""Runs all tests."""
|
||||
|
||||
print("Running test on API server to check if its running..")
|
||||
print(test_server())
|
||||
|
||||
print("Running a api endpoint to see if requests can go through...")
|
||||
print(test_api())
|
||||
|
||||
print("Checking if the API works with the python library...")
|
||||
print(test_library())
|
||||
|
||||
print("Checking if the moderation endpoint works...")
|
||||
print(test_library_moderation())
|
||||
|
||||
print("Checking if all models can be GET")
|
||||
print(test_models())
|
||||
|
||||
def test_api_moderation(model: str=MODEL, messages: List[dict]=None) -> dict:
|
||||
"""Tests an API api_endpoint."""
|
||||
|
||||
response = httpx.get(
|
||||
|
@ -92,26 +110,6 @@ def test_api_moderation() -> dict:
|
|||
|
||||
return response.text
|
||||
|
||||
# ==========================================================================================
|
||||
|
||||
def test_all():
|
||||
"""Runs all tests."""
|
||||
|
||||
print('Running test on API server to check if its running..')
|
||||
print(test_server())
|
||||
|
||||
print('Running a api endpoint to see if requests can go through...')
|
||||
print(test_api())
|
||||
|
||||
print('Checking if the API works with the python library...')
|
||||
print(test_library())
|
||||
|
||||
print('Checking if the moderation endpoint works...')
|
||||
print(test_library_moderation())
|
||||
|
||||
print('Checking if all models can be GET')
|
||||
print(test_models())
|
||||
|
||||
if __name__ == '__main__':
|
||||
api_endpoint = 'https://alpha-api.nova-oss.com/v1'
|
||||
closedai.api_base = api_endpoint
|
||||
|
|
Loading…
Reference in a new issue