Skip to content

Commit

Permalink
Merge pull request #1154 from siiddhantt/feat/openapi-spec
Browse files Browse the repository at this point in the history
feature: OpenAPI specification compliant endpoints
  • Loading branch information
dartpain authored Oct 1, 2024
2 parents dc4c539 + c997602 commit 872b390
Show file tree
Hide file tree
Showing 9 changed files with 1,816 additions and 1,224 deletions.
620 changes: 353 additions & 267 deletions application/api/answer/routes.py

Large diffs are not rendered by default.

2,353 changes: 1,413 additions & 940 deletions application/api/user/routes.py

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions application/app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import platform

import dotenv
from application.celery_init import celery
from flask import Flask, request, redirect
from application.core.settings import settings
from application.api.user.routes import user
from flask import Flask, redirect, request

from application.api.answer.routes import answer
from application.api.internal.routes import internal
from application.api.user.routes import user
from application.celery_init import celery
from application.core.logging_config import setup_logging
from application.core.settings import settings
from application.extensions import api

if platform.system() == "Windows":
import pathlib

pathlib.PosixPath = pathlib.WindowsPath

dotenv.load_dotenv()
Expand All @@ -23,16 +27,19 @@
UPLOAD_FOLDER="inputs",
CELERY_BROKER_URL=settings.CELERY_BROKER_URL,
CELERY_RESULT_BACKEND=settings.CELERY_RESULT_BACKEND,
MONGO_URI=settings.MONGO_URI
MONGO_URI=settings.MONGO_URI,
)
celery.config_from_object("application.celeryconfig")
api.init_app(app)


@app.route("/")
def home():
if request.remote_addr in ('0.0.0.0', '127.0.0.1', 'localhost', '172.18.0.1'):
return redirect('http://localhost:5173')
if request.remote_addr in ("0.0.0.0", "127.0.0.1", "localhost", "172.18.0.1"):
return redirect("http://localhost:5173")
else:
return 'Welcome to DocsGPT Backend!'
return "Welcome to DocsGPT Backend!"


@app.after_request
def after_request(response):
Expand All @@ -41,6 +48,6 @@ def after_request(response):
response.headers.add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS")
return response


if __name__ == "__main__":
app.run(debug=settings.FLASK_DEBUG_MODE, port=7091)

7 changes: 7 additions & 0 deletions application/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask_restx import Api

api = Api(
version="1.0",
title="DocsGPT API",
description="API for DocsGPT",
)
1 change: 1 addition & 0 deletions application/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ esprima==4.0.1
esutils==1.0.1
Flask==3.0.3
faiss-cpu==1.8.0.post1
flask-restx==1.3.0
gunicorn==23.0.0
html2text==2024.2.26
javalang==0.13.0
Expand Down
21 changes: 20 additions & 1 deletion application/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import tiktoken
from flask import jsonify, make_response

_encoding = None


def get_encoding():
global _encoding
if _encoding is None:
_encoding = tiktoken.get_encoding("cl100k_base")
return _encoding


def num_tokens_from_string(string: str) -> int:
encoding = get_encoding()
num_tokens = len(encoding.encode(string))
return num_tokens


def count_tokens_docs(docs):
docs_content = ""
for doc in docs:
docs_content += doc.page_content

tokens = num_tokens_from_string(docs_content)
return tokens
return tokens


def check_required_fields(data, required_fields):
missing_fields = [field for field in required_fields if field not in data]
if missing_fields:
return make_response(
jsonify(
{
"success": False,
"message": f"Missing fields: {', '.join(missing_fields)}",
}
),
400,
)
return None
4 changes: 2 additions & 2 deletions frontend/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ function Dropdown({
}`}
>
{typeof selectedValue === 'string' ? (
<span className="overflow-hidden text-ellipsis dark:text-bright-gray">
<span className="truncate dark:text-bright-gray">
{selectedValue}
</span>
) : (
<span
className={`truncate overflow-hidden dark:text-bright-gray ${
className={`truncate dark:text-bright-gray ${
!selectedValue && 'text-silver dark:text-gray-400'
} ${contentSize}`}
>
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/modals/CreateAPIKeyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ export default function CreateAPIKeyModal({
<div className="my-4">
<Dropdown
placeholder={t('modals.createAPIKey.sourceDoc')}
selectedValue={sourcePath}
selectedValue={sourcePath ? sourcePath.name : null}
onSelect={(selection: {
name: string;
id: string;
type: string;
}) => {
setSourcePath(selection);
console.log(selection);
}}
options={extractDocPaths()}
size="w-full"
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/settings/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ export default function Analytics() {
border="border"
/>
</div>
<div className="mt-8 w-full flex flex-col sm:flex-row gap-3">
<div className="h-[345px] sm:w-1/2 w-full px-6 py-5 border rounded-2xl border-silver dark:border-silver/40">
<div className="mt-8 w-full flex flex-col [@media(min-width:1080px)]:flex-row gap-3">
<div className="h-[345px] [@media(min-width:1080px)]:w-1/2 w-full px-6 py-5 border rounded-2xl border-silver dark:border-silver/40">
<div className="flex flex-row items-center justify-start gap-3">
<p className="font-bold text-jet dark:text-bright-gray">
Messages
Expand Down Expand Up @@ -227,7 +227,7 @@ export default function Analytics() {
/>
</div>
</div>
<div className="h-[345px] sm:w-1/2 w-full px-6 py-5 border rounded-2xl border-silver dark:border-silver/40">
<div className="h-[345px] [@media(min-width:1080px)]:w-1/2 w-full px-6 py-5 border rounded-2xl border-silver dark:border-silver/40">
<div className="flex flex-row items-center justify-start gap-3">
<p className="font-bold text-jet dark:text-bright-gray">
Token Usage
Expand Down

0 comments on commit 872b390

Please sign in to comment.