Guilherme34's picture
Update app.py
8fac83c verified
raw
history blame
1.09 kB
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()