Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
# https://username-spaceName.hf.space/proxy/anthropic/v1
|
3 |
# Streaming is not supported
|
4 |
|
|
|
5 |
import logging
|
6 |
import json
|
7 |
from flask import Flask, request, Response
|
@@ -18,24 +19,37 @@ def relay_request(path):
|
|
18 |
|
19 |
relay_url = 'https://' + path
|
20 |
|
21 |
-
headers_ = {}
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
if __name__ == '__main__':
|
41 |
app.run(host='0.0.0.0', port=7860)
|
|
|
2 |
# https://username-spaceName.hf.space/proxy/anthropic/v1
|
3 |
# Streaming is not supported
|
4 |
|
5 |
+
|
6 |
import logging
|
7 |
import json
|
8 |
from flask import Flask, request, Response
|
|
|
19 |
|
20 |
relay_url = 'https://' + path
|
21 |
|
|
|
22 |
|
23 |
+
headers_ = dict()
|
24 |
+
|
25 |
+
|
26 |
+
if 'Content-Type' in request.headers:
|
27 |
+
headers_['Content-Type'] = request.headers['Content-Type']
|
28 |
+
if 'x-api-key' in request.headers:
|
29 |
+
headers_['Authorization'] = "Bearer " + request.headers['x-api-key']
|
30 |
+
if 'Authorization' in request.headers:
|
31 |
+
headers_['Authorization'] = request.headers['Authorization']
|
32 |
+
|
33 |
+
if request.method == 'POST':
|
34 |
+
response = requests.request(
|
35 |
+
method='POST',
|
36 |
+
url=relay_url,
|
37 |
+
headers=headers_,
|
38 |
+
json=json.loads(request.get_data()),
|
39 |
+
allow_redirects=False
|
40 |
+
)
|
41 |
+
else:
|
42 |
+
response = requests.request(
|
43 |
+
method=request.method,
|
44 |
+
url=relay_url,
|
45 |
+
headers=headers_,
|
46 |
+
allow_redirects=False
|
47 |
+
)
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
headers = [(name, value) for name, value in response.headers.items()]
|
52 |
+
return Response(response.content, response.status_code, headers)
|
53 |
|
54 |
if __name__ == '__main__':
|
55 |
app.run(host='0.0.0.0', port=7860)
|