Spaces:
Runtime error
Runtime error
update path and openapi 3 json
Browse files- app.py +31 -14
- openapi.json +166 -0
app.py
CHANGED
|
@@ -47,23 +47,42 @@ query_parser.add_argument(
|
|
| 47 |
|
| 48 |
|
| 49 |
@api.route(
|
| 50 |
-
"/
|
| 51 |
doc={
|
| 52 |
"description": (
|
| 53 |
"Get some related papers.\nYou should use schema here:\n\n"
|
| 54 |
"CREATE TABLE ArXiv (\n"
|
| 55 |
" `id` String,\n"
|
| 56 |
-
" `abstract` String,
|
| 57 |
" `pubdate` DateTime, \n"
|
| 58 |
-
" `title` String,
|
| 59 |
-
" `categories` Array(String), -- arxiv category
|
| 60 |
-
" `authors` Array(String),
|
| 61 |
-
" `comment` String,
|
| 62 |
"ORDER BY id\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
"CREATE TABLE Wikipedia (\n"
|
| 64 |
" `id` String,\n"
|
| 65 |
-
" `text` String,
|
| 66 |
-
" `title` String,
|
| 67 |
" `view` Float32,\n"
|
| 68 |
" `url` String, -- URL to this wiki page\n"
|
| 69 |
"ORDER BY id\n\n"
|
|
@@ -71,15 +90,13 @@ query_parser.add_argument(
|
|
| 71 |
),
|
| 72 |
},
|
| 73 |
)
|
| 74 |
-
|
| 75 |
-
class get_related_docs(Resource):
|
| 76 |
@api.expect(query_parser)
|
| 77 |
@api.marshal_with(query_result)
|
| 78 |
-
|
|
|
|
| 79 |
args = query_parser.parse_args()
|
| 80 |
-
kb = kb_list[
|
| 81 |
-
print(kb)
|
| 82 |
-
print(args.subject, args.where_str, args.limit)
|
| 83 |
docs, num_docs = kb(args.subject, args.where_str, args.limit)
|
| 84 |
return {"documents": docs, "num_retrieved": num_docs}
|
| 85 |
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
@api.route(
|
| 50 |
+
"/get_related_arxiv",
|
| 51 |
doc={
|
| 52 |
"description": (
|
| 53 |
"Get some related papers.\nYou should use schema here:\n\n"
|
| 54 |
"CREATE TABLE ArXiv (\n"
|
| 55 |
" `id` String,\n"
|
| 56 |
+
" `abstract` String, \n"
|
| 57 |
" `pubdate` DateTime, \n"
|
| 58 |
+
" `title` String, \n"
|
| 59 |
+
" `categories` Array(String), -- arxiv category\n"
|
| 60 |
+
" `authors` Array(String),\n"
|
| 61 |
+
" `comment` String,\n"
|
| 62 |
"ORDER BY id\n\n"
|
| 63 |
+
),
|
| 64 |
+
},
|
| 65 |
+
)
|
| 66 |
+
class get_related_arxiv(Resource):
|
| 67 |
+
@api.expect(query_parser)
|
| 68 |
+
@api.marshal_with(query_result)
|
| 69 |
+
@api.doc(id='get_related_arxiv')
|
| 70 |
+
def get(self):
|
| 71 |
+
args = query_parser.parse_args()
|
| 72 |
+
kb = kb_list['arxiv']()
|
| 73 |
+
docs, num_docs = kb(args.subject, args.where_str, args.limit)
|
| 74 |
+
return {"documents": docs, "num_retrieved": num_docs}
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
@api.route(
|
| 78 |
+
"/get_related_wiki",
|
| 79 |
+
doc={
|
| 80 |
+
"description": (
|
| 81 |
+
"Get some related wiki pages.\nYou should use schema here:\n\n"
|
| 82 |
"CREATE TABLE Wikipedia (\n"
|
| 83 |
" `id` String,\n"
|
| 84 |
+
" `text` String,\n"
|
| 85 |
+
" `title` String,\n"
|
| 86 |
" `view` Float32,\n"
|
| 87 |
" `url` String, -- URL to this wiki page\n"
|
| 88 |
"ORDER BY id\n\n"
|
|
|
|
| 90 |
),
|
| 91 |
},
|
| 92 |
)
|
| 93 |
+
class get_related_wiki(Resource):
|
|
|
|
| 94 |
@api.expect(query_parser)
|
| 95 |
@api.marshal_with(query_result)
|
| 96 |
+
@api.doc(id='get_related_wiki')
|
| 97 |
+
def get(self):
|
| 98 |
args = query_parser.parse_args()
|
| 99 |
+
kb = kb_list['wiki']()
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"openapi": "3.0.1",
|
| 3 |
+
"info": {
|
| 4 |
+
"title": "MyScale Open Knowledge Base",
|
| 5 |
+
"description": "An API to get relevant page from MyScale Open Knowledge Base",
|
| 6 |
+
"termsOfService": "https://myscale.com/terms/",
|
| 7 |
+
"version": "0.1"
|
| 8 |
+
},
|
| 9 |
+
"servers": [
|
| 10 |
+
{
|
| 11 |
+
"url": "https://myscale-gpts-myscale-backend.hf.space"
|
| 12 |
+
}
|
| 13 |
+
],
|
| 14 |
+
"tags": [
|
| 15 |
+
{
|
| 16 |
+
"name": "default",
|
| 17 |
+
"description": "Default namespace"
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"paths": {
|
| 21 |
+
"/get_related_arxiv": {
|
| 22 |
+
"get": {
|
| 23 |
+
"tags": [
|
| 24 |
+
"default"
|
| 25 |
+
],
|
| 26 |
+
"description": "Get some related papers.\nYou should use schema here:\n\nCREATE TABLE ArXiv (\n `id` String,\n `abstract` String, \n `pubdate` DateTime, \n `title` String, \n `categories` Array(String), -- arxiv category\n `authors` Array(String),\n `comment` String,\nORDER BY id",
|
| 27 |
+
"operationId": "get_related_arxiv",
|
| 28 |
+
"parameters": [
|
| 29 |
+
{
|
| 30 |
+
"name": "subject",
|
| 31 |
+
"in": "query",
|
| 32 |
+
"description": "a sentence or phrase describes the subject you want to query.",
|
| 33 |
+
"required": true,
|
| 34 |
+
"schema": {
|
| 35 |
+
"type": "string"
|
| 36 |
+
}
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"name": "where_str",
|
| 40 |
+
"in": "query",
|
| 41 |
+
"description": "a sql-like where string to build filter",
|
| 42 |
+
"required": true,
|
| 43 |
+
"schema": {
|
| 44 |
+
"type": "string"
|
| 45 |
+
}
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "limit",
|
| 49 |
+
"in": "query",
|
| 50 |
+
"description": "desired number of retrieved documents",
|
| 51 |
+
"schema": {
|
| 52 |
+
"type": "integer",
|
| 53 |
+
"default": 4
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"name": "X-Fields",
|
| 58 |
+
"in": "header",
|
| 59 |
+
"description": "An optional fields mask",
|
| 60 |
+
"schema": {
|
| 61 |
+
"type": "string",
|
| 62 |
+
"format": "mask"
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
],
|
| 66 |
+
"responses": {
|
| 67 |
+
"200": {
|
| 68 |
+
"description": "Success",
|
| 69 |
+
"content": {
|
| 70 |
+
"application/json": {
|
| 71 |
+
"schema": {
|
| 72 |
+
"$ref": "#/components/schemas/QueryResult"
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
},
|
| 80 |
+
"/get_related_wiki": {
|
| 81 |
+
"get": {
|
| 82 |
+
"tags": [
|
| 83 |
+
"default"
|
| 84 |
+
],
|
| 85 |
+
"description": "Get some related wiki pages.\nYou should use schema here:\n\nCREATE TABLE Wikipedia (\n `id` String,\n `text` String,\n `title` String,\n `view` Float32,\n `url` String, -- URL to this wiki page\nORDER BY id\n\nYou should avoid using LIKE on long text columns.",
|
| 86 |
+
"operationId": "get_related_wiki",
|
| 87 |
+
"parameters": [
|
| 88 |
+
{
|
| 89 |
+
"name": "subject",
|
| 90 |
+
"in": "query",
|
| 91 |
+
"description": "a sentence or phrase describes the subject you want to query.",
|
| 92 |
+
"required": true,
|
| 93 |
+
"schema": {
|
| 94 |
+
"type": "string"
|
| 95 |
+
}
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"name": "where_str",
|
| 99 |
+
"in": "query",
|
| 100 |
+
"description": "a sql-like where string to build filter",
|
| 101 |
+
"required": true,
|
| 102 |
+
"schema": {
|
| 103 |
+
"type": "string"
|
| 104 |
+
}
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"name": "limit",
|
| 108 |
+
"in": "query",
|
| 109 |
+
"description": "desired number of retrieved documents",
|
| 110 |
+
"schema": {
|
| 111 |
+
"type": "integer",
|
| 112 |
+
"default": 4
|
| 113 |
+
}
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"name": "X-Fields",
|
| 117 |
+
"in": "header",
|
| 118 |
+
"description": "An optional fields mask",
|
| 119 |
+
"schema": {
|
| 120 |
+
"type": "string",
|
| 121 |
+
"format": "mask"
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
],
|
| 125 |
+
"responses": {
|
| 126 |
+
"200": {
|
| 127 |
+
"description": "Success",
|
| 128 |
+
"content": {
|
| 129 |
+
"application/json": {
|
| 130 |
+
"schema": {
|
| 131 |
+
"$ref": "#/components/schemas/QueryResult"
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
},
|
| 140 |
+
"components": {
|
| 141 |
+
"schemas": {
|
| 142 |
+
"QueryResult": {
|
| 143 |
+
"type": "object",
|
| 144 |
+
"properties": {
|
| 145 |
+
"documents": {
|
| 146 |
+
"type": "string"
|
| 147 |
+
},
|
| 148 |
+
"num_retrieved": {
|
| 149 |
+
"type": "integer"
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
},
|
| 154 |
+
"responses": {
|
| 155 |
+
"ParseError": {
|
| 156 |
+
"description": "When a mask can't be parsed",
|
| 157 |
+
"content": {}
|
| 158 |
+
},
|
| 159 |
+
"MaskError": {
|
| 160 |
+
"description": "When any error occurs on mask",
|
| 161 |
+
"content": {}
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
},
|
| 165 |
+
"x-original-swagger-version": "2.0"
|
| 166 |
+
}
|