meta-introspector / https-streamlit.io-community-llm-hackathon-2023

hackathon
Apache License 2.0
0 stars 1 forks source link

Flask app that can process multiple bots on hosted server #43

Open Deadsg opened 9 months ago

Deadsg commented 9 months ago

from flask import Flask, request, jsonify import openai

app = Flask(name)

Set up your OpenAI API key

openai.api_key = 'YOUR_API_KEY'

def generate_response(issue): prompt = f"Agent, there's a new ticket with the following issue:\n\n{issue}\n\nPlease take appropriate action." response = openai.Completion.create( engine="davinci", prompt=prompt, max_tokens=100, n=1, stop=None ) return response.choices[0].text.strip()

@app.route('/submit_ticket', methods=['POST']) def submit_ticket(): agent_name = request.json.get('agent_name') issue = request.json.get('issue')

if agent_name and issue:
    # Generate response from GPT
    response = generate_response(issue)

    # Process the ticket (e.g., store it in a database)
    # Here, we're just printing it for demonstration purposes
    print(f"Agent Name: {agent_name}")
    print(f"Issue: {issue}")
    print(f"GPT Response: {response}")

    return jsonify({"message": "Ticket submitted successfully."}), 200
else:
    return jsonify({"error": "Invalid request, agent_name and issue are required."}), 400

if name == 'main': app.run(debug=True)