This commit is contained in:
2024-11-29 15:33:12 -05:00
parent 57f5564fe6
commit 6b62757dad
6 changed files with 230 additions and 35 deletions

View File

@@ -40,6 +40,7 @@ class AI(FastAPI):
"""
/ai/base/
AI BASE Request
(Requires key)
"""
if not self.util.check_key(request.url.path, request.headers.get('X-Authd-With')):
@@ -70,6 +71,7 @@ class AI(FastAPI):
"""
/ai/openai/
AI Request
(Requires key)
"""
if not self.util.check_key(request.url.path, request.headers.get('X-Authd-With')):
@@ -145,9 +147,16 @@ class AI(FastAPI):
await self.glob_state.increment_counter('claude_ai_requests')
response = await request.json()
print(f"Response: {response}")
result = {
'resp': response.get('content')[0].get('text').strip()
}
if response.get('type') == 'error':
error_type = response.get('error').get('type')
error_message = response.get('error').get('message')
result = {
'resp': f"{error_type} error ({error_message})"
}
else:
result = {
'resp': response.get('content')[0].get('text').strip()
}
return result
except Exception as e: # pylint: disable=broad-exception-caught
logging.error("Error: %s", e)