Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chatbot-Backend-Setup

A lightweight, simple Python and Flask backend designed to handle OpenAI chat completions. This project is built for seamless "one-click" deployment on Render and serves as a flexible API endpoint for any custom frontend wrapper (whether built in TypeScript, HTML/JavaScript, or any other client framework).

Features

  • Simple API: Exposes a single /chat POST endpoint to process messaging arrays and handle conversation history.
  • OpenAI Integration: Utilizes the OpenAI Python SDK (v1.x) to generate responses via modern LLMs.
  • CORS Enabled: Cross-Origin Resource Sharing is enabled globally, allowing frontend clients to communicate directly with the API without browser restrictions.
  • Easily Customizable: Core AI behavior and model selection are controlled entirely via environment variables, requiring no code changes to update the bot's persona.

Deployment

This backend is specifically designed as a one-click deployment for Render. Local development environments are not officially tested or supported.

  1. Fork this repository to your GitHub account.

  2. Connect the forked repository to Render.

  3. The included render.yaml configuration will automatically handle the build command (pip install -r requirements.txt) and the start command (python main.py).

  4. Configure Environment Variables in your Render dashboard:

    • OPENAI_API_KEY: Your required OpenAI API authorization key.
    • SYSTEM_PROMPT: The custom instructions that define the AI's persona and specific job. Example: "You are a company onboarding bot named Atlas. Your job is to assist new hires with navigating HR policies and finding internal documentation."
    • CHAT_MODEL: The specified AI model to utilize. Recommended models include GPT-5.4-nano or GPT-5.5, depending on the user's speed and reasoning requirements.
  5. Once successfully deployed, Render will provide a live URL. Use this URL as the base for your frontend interface's API calls.

API Integration

To connect your custom frontend, send a POST request to the /chat endpoint of your live Render URL.

Request Format

The endpoint expects a JSON payload containing the current user message and an optional history array representing previous conversation turns.

{
  "message": "Hello! How can you help me today?",
  "history": [
    {"sender": "user", "text": "Hi"},
    {"sender": "assistant", "text": "Hello! I am ready to assist."}
  ]
}

Response Format

The server will process the context and return a JSON object containing the AI's generated reply.

{
  "reply": "I can help you onboard to the company. What do you need to know?"
}

License

This project is licensed under the MIT License.

About

A lightweight, simple Python and Flask backend designed to handle OpenAI chat completions. This project is built for seamless "one-click" deployment on Render and serves as a flexible API endpoint for any custom frontend wrapper

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages