Spaces:
Runtime error
Runtime error
Upload 6 files
Browse files- Dockerfile +10 -10
- api_call.py +15 -0
- api_info.py +1 -1
- app.py +32 -12
- requirements.txt +4 -5
Dockerfile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
FROM python:3.10
|
| 2 |
-
|
| 3 |
-
WORKDIR /code
|
| 4 |
-
|
| 5 |
-
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
-
|
| 7 |
-
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
-
|
| 9 |
-
COPY . .
|
| 10 |
-
|
| 11 |
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "7860"]
|
api_call.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
def generate_request(conversation_history):
|
| 4 |
+
url = "https://devsdocode-bing.hf.space/generate"
|
| 5 |
+
params = {
|
| 6 |
+
"conversation_history": conversation_history,
|
| 7 |
+
}
|
| 8 |
+
response = requests.get(url, params=params)
|
| 9 |
+
return response.text
|
| 10 |
+
|
| 11 |
+
if __name__ == "__main__":
|
| 12 |
+
# Example usage:
|
| 13 |
+
query = [{"role": "user", "content": "Who is Devs Do Code"}]
|
| 14 |
+
response = generate_request(query)
|
| 15 |
+
print(response)
|
api_info.py
CHANGED
|
@@ -24,7 +24,7 @@ endpoint = {
|
|
| 24 |
"temperature": "[]",
|
| 25 |
"system_prompt": "[]"
|
| 26 |
},
|
| 27 |
-
'url_demo' : '/generate?
|
| 28 |
}
|
| 29 |
|
| 30 |
available_models = {
|
|
|
|
| 24 |
"temperature": "[]",
|
| 25 |
"system_prompt": "[]"
|
| 26 |
},
|
| 27 |
+
'url_demo' : '/generate?conversation_history=[{"role": "user", "content": "Who is Devs Do Code"}]'
|
| 28 |
}
|
| 29 |
|
| 30 |
available_models = {
|
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
import bingChat
|
| 3 |
import api_info
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
|
@@ -20,19 +21,38 @@ def endpoints():
|
|
| 20 |
def developer_info():
|
| 21 |
return jsonify(api_info.developer_info)
|
| 22 |
|
| 23 |
-
@app.route('/generate', methods=['GET'])
|
| 24 |
def generate():
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
if __name__ == '__main__':
|
| 38 |
app.run(debug=True)
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
import bingChat
|
| 3 |
import api_info
|
| 4 |
+
import json
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
|
|
|
| 21 |
def developer_info():
|
| 22 |
return jsonify(api_info.developer_info)
|
| 23 |
|
| 24 |
+
@app.route('/generate', methods=['GET', 'POST'])
|
| 25 |
def generate():
|
| 26 |
+
try:
|
| 27 |
+
if request.method == 'POST':
|
| 28 |
+
data = request.get_json(force=True)
|
| 29 |
+
conversation_history = data.get('conversation_history')
|
| 30 |
+
realtime = data.get('realtime', False)
|
| 31 |
+
md_format = data.get('md_format', True)
|
| 32 |
+
else: # GET request
|
| 33 |
+
conversation_history = request.args.get('conversation_history')
|
| 34 |
+
realtime = request.args.get('realtime', 'false').lower() == 'true'
|
| 35 |
+
md_format = request.args.get('md_format', 'true').lower() == 'true'
|
| 36 |
+
|
| 37 |
+
if conversation_history:
|
| 38 |
+
# Parse the conversation_history as JSON if it's a string
|
| 39 |
+
if isinstance(conversation_history, str):
|
| 40 |
+
try:
|
| 41 |
+
conversation_history = json.loads(conversation_history)
|
| 42 |
+
except json.JSONDecodeError:
|
| 43 |
+
conversation_history = [{"role": "user", "content": conversation_history}]
|
| 44 |
+
|
| 45 |
+
response = bingChat.ddc_bing_converse(
|
| 46 |
+
conv_history=conversation_history,
|
| 47 |
+
realtime=realtime,
|
| 48 |
+
md_format=md_format
|
| 49 |
+
)
|
| 50 |
+
return jsonify(response), 200
|
| 51 |
+
else:
|
| 52 |
+
return jsonify(api_info.error_message), 400
|
| 53 |
+
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return jsonify({"error": str(e)}), 400
|
| 56 |
|
| 57 |
if __name__ == '__main__':
|
| 58 |
app.run(debug=True)
|
requirements.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
fastapi==0.110.2
|
| 2 |
-
Flask==3.0.3
|
| 3 |
-
Requests==2.31.0
|
| 4 |
-
uvicorn==0.29.0
|
| 5 |
-
python-dotenv==1.0.1
|
|
|
|
| 1 |
+
fastapi==0.110.2
|
| 2 |
+
Flask==3.0.3
|
| 3 |
+
Requests==2.31.0
|
| 4 |
+
uvicorn==0.29.0
|
|
|