404 error with insomnia any help greatly appreciated

We are reviving a 404 error with http://127.0.0.1:5000/chat we access “hello world” from http://127.0.0.1:5000 our web browser. We seem to have tried everything, any insight would be greatly appreciated, thx

from flask import Flask, request, jsonify, send_from_directory, Response
from flask_cors import CORS
import openai
import os
from dotenv import load_dotenv
from typing import Union
from openai import OpenAIError, RateLimitError
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

# Load environment variables from .env file
load_dotenv()

# Get the OpenAI API key from the environment variable
openai.api_key = os.getenv('OPENAI_API_KEY')

# Initialize Flask app
app = Flask(__name__)
CORS(app)

# Explicitly setting debug and environment
app.config['ENV'] = 'development'
app.config['DEBUG'] = True

# Set up the database configuration
app.config['SQLALCHEMY_DATABASE_URI'] = (
    'mysql+mysqlconnector://osric_user:Temporal1!@localhost/osric_db'
)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# Initialize the database and migration modules
db = SQLAlchemy(app)
migrate = Migrate(app, db)

# Define campaign state
campaign_state = {
    "characters": [],
    "sessions": []
}

# Generate response using OpenAI API
def generate_response(input_text: str) -> str:
    prompt = f"OSRIC campaign response: {input_text}"
    try:
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": prompt}
            ],
            max_tokens=150
        )
        return response['choices'][0]['message']['content'].strip()
    except OpenAIError as e:
        return f"Error occurred: {str(e)}"
    except RateLimitError:
        return "Rate limit error: You have exceeded your quota."
    except Exception as e:
        return f"An error occurred: {str(e)}"

# Flask route for chat endpoint
@app.route('/chat', methods=['POST'])
def chat() -> Union[Response, tuple[Response, int]]:
    if request.json is None:
        app.logger.error("Invalid input: request.json is None")
        return jsonify({"error": "Invalid input"}), 400

    user_input: str = request.json.get('input')
    if not user_input or not isinstance(user_input, str):
        app.logger.error(f"Invalid input: {user_input}")
        return jsonify({"error": "Invalid input"}), 400

    try:
        response_text: str = generate_response(input_text=user_input)
        return jsonify({"response": response_text})
    except Exception as e:
        app.logger.error(f"Error processing request: {e}")
        return jsonify(
            {"error": "An error occurred while processing the request"}
        ), 500

# Flask route for adding a character
@app.route('/add_character', methods=['POST'])
def add_character():
    if request.json is None:
        return jsonify({"error": "Invalid character data"}), 400

    character = request.json.get('character')
    if not character:
        return jsonify({"error": "Invalid character data"}), 400

    campaign_state["characters"].append(character)
    return jsonify({"message": "Character added", "character": character})

# Flask route for getting characters
@app.route('/get_characters', methods=['GET'])
def get_characters() -> Response:
    return jsonify({"characters": campaign_state["characters"]})

# Serve the index.html file
@app.route('/')
def serve_index() -> Response:
    return send_from_directory(directory='.', path='index.html')

# Serve the favicon.ico file
@app.route('/favicon.ico')
def favicon() -> Response:
    return send_from_directory(
        directory=os.path.join(app.root_path, 'static'),
        path='favicon.ico'
    )

# Additional route to display a simple message
@app.route('/home')
def home():
    return "Hello World"

# Main entry point
if __name__ == '__main__':
    app.run(debug=True, host="127.0.0.1", port=5000)


we set our firewall rules to port 5000 we tried rewriting the code, but we still are not connecting

New contributor

joah moat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật