feat: Initial commit with full deployment architecture and scripts

This commit is contained in:
super committed 2026-02-24 16:45:11 +08:00
commit abb3efe114
96 files changed
+16789

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
import time
import json
from flask import Flask, request, Response, stream_with_context
app = Flask(__name__)
@app.route('/v1/chat-messages', methods=['POST'])
def chat_messages():
print(f"Received request: {request.json}")
auth = request.headers.get('Authorization')
print(f"Authorization: {auth}")
# Check API Key if needed
if 'Bearer app-xdiejQibWQy8ZQWXcdxJjS9I' not in auth:
print("Invalid API Key")
# return {"code": "unauthorized", "message": "Invalid API Key"}, 401
def generate():
# Yield 'message' events
response_text = "这是来自人事规章助手的回复。根据公司规定,年假天数取决于工龄。"
# Initial chunk
yield f"data: {json.dumps({'event': 'message', 'answer': ''})}\n\n"
for char in response_text:
time.sleep(0.05)
data = {
'event': 'message',
'answer': char,
'conversation_id': 'conv-123',
'task_id': 'task-123'
}
yield f"data: {json.dumps(data)}\n\n"
# Message end
data = {
'event': 'message_end',
'conversation_id': 'conv-123',
'metadata': {
'usage': {'total_tokens': 100}
}
}
yield f"data: {json.dumps(data)}\n\n"
return Response(stream_with_context(generate()), mimetype='text/event-stream')
if __name__ == '__main__':
print("Starting Mock Dify Server on port 5001...")
app.run(host='127.0.0.1', port=5001, debug=True)