How can i pass the variable prompt in place of the userinput and also modify the code to…
- User
How can i pass the variable prompt in place of the user_input and also modify the code to take values from frontend for method and generate_text.
method = "casual" generate_text = "long" prompt = f"hi ai please form {generate_text} with a {method} style for the topic formula 1"
Generate response
@app.route("/chat", methods=["POST"]) @cross_origin(supports_credentials=True) def chat(): data = request.json thread_id = data.get("thread_id") user_input = data.get("message", "")
codeif not thread_id: print("Error: Missing thread_id") return jsonify({"error": "Missing thread_id"}), 400 print(f"Received message: {user_input} for thread ID: {thread_id}") # Add the user's message to the thread client.beta.threads.messages.create( thread_id=thread_id, role="user", content=user_input ) run = client.beta.threads.runs.create( thread_id=thread_id, assistant_id=assistant_id ) # Check if the Run requires action while True: run_status = client.beta.threads.runs.retrieve( thread_id=thread_id, run_id=run.id ) print(f"Run status: {run_status.status}") if run_status.status == "completed": break sleep(1) messages = client.beta.threads.messages.list(thread_id=thread_id) response = messages.data[0].content[0].text.value print(f"Assistant response: {response}") return jsonify({"response": response}) - Assistant