commit ab9bbeb3d14b6f3b559ffbf11d1382d09437b778 Author: ed Date: Sun Jun 18 11:06:26 2023 +0200 main.py added diff --git a/main.py b/main.py new file mode 100644 index 0000000..f739496 --- /dev/null +++ b/main.py @@ -0,0 +1,73 @@ +from flask import Flask, request, jsonify +from dotenv import load_dotenv +load_dotenv() +from langchain.chat_models import ChatOpenAI +from langchain.schema import HumanMessage + +app = Flask(__name__) +# set fixed port for app +app.config['SERVER_NAME'] = 'localhost:5000' + +@app.route('/openai', methods=['POST']) +def openai(): + content_type = request.headers.get('Content-Type') + prompt = None + temperature = 0.9 + model_name = 'gpt-3.5-turbo' + if content_type == 'application/json': + json_payload = request.json + prompt = json_payload['prompt'] + else: + return jsonify({'error': 'Invalid content type'}), 400 + + llm = ChatOpenAI(temperature = temperature, model_name = model_name) + resp = llm([HumanMessage(content=prompt)]) + + return { + 'statusCode': 200, + 'body': resp.content + } + +""" +curl test: +curl -XPOST --header "Content-Type: application/json" -d "{\"prompt\":\"What is the best way to learn a language?\"}" http://localhost:5000/openai + +curl -XPOST --header "Content-Type: application/json" -d "{\"prompt\":\"What is a good name for a company that makes funny socks?\"}" http://localhost:5000/openai +""" + + +@app.route('/') +def home(): + return """ + + + + This is not for human, gtfo + + + + + +

You have no business being here.

+ + +""" + + + +if __name__ == '__main__': + app.run(debug=True) + \ No newline at end of file