Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a reasoning model that can be called via a post request #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions reasoning_flask_app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask import Flask, request, jsonify
import openai # Using OpenAI model for reasoning
import os
from dotenv import load_dotenv
from openai import OpenAI
# Load environment variables
load_dotenv()

app = Flask(__name__)

@app.route("/reason", methods=["POST"])
def reason():
try:
data = request.get_json()
if not data or "query" not in data:
return jsonify({"error": "Missing 'query' in request"}), 400

query = data["query"]
openai.api_key = os.getenv("OPENAI_API_KEY") # Use API key from environment
client = OpenAI()
response = client.chat.completions.create(
model="o1-mini",
messages=[
{"role": "developer", "content": "You are a helpful assistant."},
{"role": "user", "content": query}
]
max_completion_tokens=150
)

return jsonify({"response": response.choices[0].message.content})
except Exception as e:
return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
app.run(host="0.0.0.0", port=5050, debug=True)