LingoSynth/lingosynth/app/api.py

22 lines
523 B
Python
Raw Normal View History

2023-05-11 21:48:16 +02:00
import flask
2023-05-11 23:28:39 +02:00
from . import ai, prompts
2023-05-11 21:48:16 +02:00
def register(app: flask.Flask):
@app.route('/api/rephrase', methods=['GET', 'POST'])
@app.rate_limiter.limit('2 per second')
def api_rephrase():
text = flask.request.args.get('text') or flask.request.json.get('text')
2023-05-11 23:28:39 +02:00
messages = prompts.MESSAGES
messages.append({
'role': 'user',
'content': text
})
2023-05-11 21:48:16 +02:00
return flask.jsonify(
{
2023-05-11 23:28:39 +02:00
'text': ai.generate(messages)
2023-05-11 21:48:16 +02:00
}
)