A lightweight Go application to connect to OpenAI's API, featuring three simple yet powerful endpoints: status/
, stream/
, and chat/
. Built with a focus on clarity, performance, and ease of use.
- Status Endpoint: Quickly verify the service health.
- Stream Endpoint: Stream OpenAI responses for real-time interaction.
- Chat Endpoint: Send messages and receive responses from OpenAI.
- Minimalistic and Efficient: Built with the Gin framework for fast API handling.
- Environment Friendly: Easy configuration with
.env
support. - Ready for Scale: Clean structure for future extensibility.
-
Clone the repository:
git clone https://github.com/your-repo/go-bot.git cd go-bot
-
Install Depenencies
go mod tidy
-
Set your.env
OPENAI_API_KEY=your_openai_api_key PORT=8080
Run the Application
go run ./cmd/server
Access the API at http://localhost:8080.
GET /status: Health check endpoint to verify API connectivity and service status
POST /chat: Standard chat endpoint for single request-response interactions, returning complete responses
POST /stream: Real-time streaming endpoint for receiving continuous AI responses
Example Usage
Chat
curl -X POST http://localhost:8080/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello, how are you?"}'