mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-26 00:43:57 +01:00
Compare commits
No commits in common. "f01b8e5ecc297d42078f711a5706759b4aefe330" and "c4137a9eab6c10f74c9c04cb845ab4ef2ffe117c" have entirely different histories.
f01b8e5ecc
...
c4137a9eab
|
@ -52,8 +52,6 @@ async def get_users(discord_id: int, incoming_request: fastapi.Request):
|
|||
if not user:
|
||||
return await errors.error(404, 'Discord user not found in the API database.', 'Check the `discord_id` parameter.')
|
||||
|
||||
print(type(user))
|
||||
print(user)
|
||||
return user
|
||||
|
||||
async def new_user_webhook(user: dict) -> None:
|
||||
|
@ -130,8 +128,7 @@ async def run_checks(incoming_request: fastapi.Request):
|
|||
|
||||
try:
|
||||
chat = await checks.client.test_chat()
|
||||
except Exception as exc:
|
||||
print(exc)
|
||||
except Exception:
|
||||
chat = None
|
||||
|
||||
try:
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
"""FastAPI setup."""
|
||||
|
||||
import fastapi
|
||||
import pydantic
|
||||
|
||||
from rich import print
|
||||
from dotenv import load_dotenv
|
||||
from bson.objectid import ObjectId
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
import core
|
||||
import transfer
|
||||
|
||||
|
@ -28,8 +25,6 @@ app.include_router(core.router)
|
|||
@app.on_event('startup')
|
||||
async def startup_event():
|
||||
"""Runs when the API starts up."""
|
||||
# https://stackoverflow.com/a/74529009
|
||||
pydantic.json.ENCODERS_BY_TYPE[ObjectId]=str
|
||||
|
||||
@app.get('/')
|
||||
async def root():
|
||||
|
|
|
@ -106,21 +106,21 @@ async def stream(
|
|||
# We haven't done any requests as of right now, everything until now was just preparation
|
||||
# Here, we process the request
|
||||
async with aiohttp.ClientSession(connector=proxies.get_proxy().connector) as session:
|
||||
# try:
|
||||
# async with session.get(
|
||||
# url='https://checkip.amazonaws.com',
|
||||
# timeout=aiohttp.ClientTimeout(
|
||||
# connect=0.4,
|
||||
# total=0.7
|
||||
# )
|
||||
# ) as response:
|
||||
# for actual_ip in os.getenv('ACTUAL_IPS', '').split(' '):
|
||||
# if actual_ip in await response.text():
|
||||
# raise ValueError(f'Proxy {response.text()} is transparent!')
|
||||
try:
|
||||
async with session.get(
|
||||
url='https://checkip.amazonaws.com',
|
||||
timeout=aiohttp.ClientTimeout(
|
||||
connect=3,
|
||||
total=float(os.getenv('TRANSFER_TIMEOUT', '5'))
|
||||
)
|
||||
) as response:
|
||||
for actual_ip in os.getenv('ACTUAL_IPS', '').split(' '):
|
||||
if actual_ip in await response.text():
|
||||
raise ValueError(f'Proxy {response.text()} is transparent!')
|
||||
|
||||
# except Exception as exc:
|
||||
# print(f'[!] proxy {proxies.get_proxy()} error - ({type(exc)} {exc})')
|
||||
# continue
|
||||
except Exception as exc:
|
||||
print(f'[!] proxy {proxies.get_proxy()} error - ({type(exc)} {exc})')
|
||||
continue
|
||||
|
||||
try:
|
||||
async with session.request(
|
||||
|
@ -175,10 +175,6 @@ async def stream(
|
|||
print('[!] aiohttp came up with a dumb excuse to not work again ("cOnNeCtIoN rEsEt")')
|
||||
continue
|
||||
|
||||
except aiohttp.client_exceptions.ClientConnectionError:
|
||||
print('[!] aiohttp came up with a dumb excuse to not work again ("cOnNeCtIoN cLosEd")')
|
||||
continue
|
||||
|
||||
if is_chat and is_stream:
|
||||
yield await chat.create_chat_chunk(chat_id=chat_id, model=model, content=chat.CompletionStop)
|
||||
yield 'data: [DONE]\n\n'
|
||||
|
|
|
@ -10,11 +10,10 @@ import streaming
|
|||
import moderation
|
||||
|
||||
from db.users import UserManager
|
||||
from helpers import tokens, errors, network
|
||||
from helpers import tokens, errors
|
||||
|
||||
load_dotenv()
|
||||
|
||||
users = UserManager()
|
||||
models_list = json.load(open('models.json', encoding='utf8'))
|
||||
|
||||
with open('config/config.yml', encoding='utf8') as f:
|
||||
|
@ -26,11 +25,9 @@ async def handle(incoming_request):
|
|||
Takes the request from the incoming request to the target endpoint.
|
||||
Checks method, token amount, auth and cost along with if request is NSFW.
|
||||
"""
|
||||
users = UserManager()
|
||||
path = incoming_request.url.path.replace('v1/v1', 'v1').replace('//', '/')
|
||||
|
||||
ip_address = await network.get_ip(incoming_request)
|
||||
print(f'[{ip_address}] {path}')
|
||||
|
||||
if '/models' in path:
|
||||
return fastapi.responses.JSONResponse(content=models_list)
|
||||
|
||||
|
@ -72,10 +69,7 @@ async def handle(incoming_request):
|
|||
policy_violation = await moderation.is_policy_violated(inp)
|
||||
|
||||
if policy_violation:
|
||||
return await errors.error(
|
||||
400, f'The request contains content which violates this model\'s policies for "{policy_violation}".',
|
||||
'We currently don\'t support any NSFW models.'
|
||||
)
|
||||
return await errors.error(400, f'The request contains content which violates this model\'s policies for "{policy_violation}".', 'We currently don\'t support any NSFW models.')
|
||||
|
||||
role = user.get('role', 'default')
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ MESSAGES = [
|
|||
}
|
||||
]
|
||||
|
||||
api_endpoint = os.getenv('CHECKS_ENDPOINT', 'http://localhost:2332/v1')
|
||||
api_endpoint = 'http://localhost:2332/v1'
|
||||
|
||||
async def test_server():
|
||||
"""Tests if the API server is running."""
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Script to start the production server
|
||||
|
||||
# Commit to the production branch
|
||||
# git commit -am "Auto-trigger - Production server started" && git push origin Production
|
||||
git commit -am "Auto-trigger - Production server started" && git push origin Production
|
||||
|
||||
# Copy files to production
|
||||
cp -r * /home/nova-prod
|
||||
|
|
Loading…
Reference in a new issue