-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.py
118 lines (100 loc) · 3.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import json
import search_service
import image_search
import quart
import quart_cors
from quart import request
import google_search_concurrent as gs
import requests
app = quart_cors.cors(quart.Quart(__name__), allow_origin="*")
# This key can be anything, though you will likely want a randomly generated sequence.
_SERVICE_AUTH_KEY = "0123456788abcdef"
# def assert_auth_header(req):
# assert req.headers.get(
# "Authorization", None) == f"Bearer {_SERVICE_AUTH_KEY}"
@app.get("/search/quick")
async def get_quicksearch():
level = "quick"
search_result = ""
try:
query = request.args.get("query")
print(f"level: {level}, query: {query}")
search_result = search_service.run_chat(query, level)
except:
traceback.print_exc()
return quart.Response(
response=json.dumps(
{
"response": search_result,
"credibility_definitions": {
"Official Source": "Source is a government agency.",
"Whitelisted Source": "Source is approved in your curation list.",
"Third-Party Source": "Source does not appear in your curation list and may have varying levels of reliability.",
"Blacklisted Source": "Source has been explicitly banned in your curation list.",
},
}
),
status=200,
)
@app.get("/search/full")
async def get_fullsearch():
level = "moderate"
search_result = ""
try:
query = request.args.get("query")
print(f"level: {level}, query: {query}")
search_result = search_service.run_chat(query, level)
except:
traceback.print_exc()
return quart.Response(
response=json.dumps(
{
"response": search_result,
"credibility_definitions": {
"Official Source": "Source is a government agency.",
"Whitelisted Source": "Source is approved in your curation list.",
"Third-Party Source": "Source does not appear in your curation list and may have varying levels of reliability.",
"Blacklisted Source": "Source has been explicitly banned in your curation list.",
},
}
),
status=200,
)
@app.get("/search/image")
async def get_image():
level = "moderate"
search_result = ""
try:
query = request.args.get("query")
print(f"level: {level}, query: {query}")
search_result = image_search.image_search(query)
except:
traceback.print_exc()
return quart.Response(
response=json.dumps(
{
"response": search_result,
}
),
status=200,
)
@app.get("/logo.png")
async def plugin_logo():
filename = "logo.png"
return await quart.send_file(filename, mimetype="image/png")
@app.get("/.well-known/ai-plugin.json")
async def plugin_manifest():
# host = request.headers['Host']
with open("./.well-known/ai-plugin.json") as f:
text = f.read()
return quart.Response(text, mimetype="text/json")
@app.get("/openapi.yaml")
async def openapi_spec():
# host = request.headers['Host']
with open("openapi.yaml") as f:
text = f.read()
return quart.Response(text, mimetype="text/yaml")
# def main():
# app.run(debug=True, host="0.0.0.0", port=443)
# if __name__ == "__main__":
# main()