-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1154 from siiddhantt/feat/openapi-spec
feature: OpenAPI specification compliant endpoints
- Loading branch information
Showing
9 changed files
with
1,816 additions
and
1,224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,7 @@ | ||
from flask_restx import Api | ||
|
||
api = Api( | ||
version="1.0", | ||
title="DocsGPT API", | ||
description="API for DocsGPT", | ||
) |
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
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 |
---|---|---|
@@ -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 |
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
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
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