File size: 1,089 Bytes
8fac83c db6e2f8 8fac83c |
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 |
from flask import Flask, request, jsonify
from chat import generate_response
app = Flask(__name__)
@app.route('/openai/v1/chat/completions', methods=['POST'])
def chat_completions():
data = request.get_json()
message = data['messages'][0]['content']
history = data.get('history', [])
response = generate_response(message, history)
return jsonify({
'id': 'chat_completion_id',
'object': 'chat.completion',
'created': 1234567890,
'model': 'Samanthav3-MIXTRALDOLPHIN-LORA',
'choices': [
{
'index': 0,
'message': {
'role': 'assistant',
'content': response
},
'finish_reason': 'stop'
}
],
'usage': {
'prompt_tokens': len(tokenizer.encode(message)),
'completion_tokens': len(tokenizer.encode(response)),
'total_tokens': len(tokenizer.encode(message)) + len(tokenizer.encode(response))
}
})
if __name__ == '__main__':
app.run() |