A monolithic Go web service that provides English translation using Large Language Models.
This project is licensed under the MIT License - see the LICENSE file for details.
- Project Structure - Directory layout and organization
- Configuration Guide - Detailed configuration options
- API Documentation - REST API endpoints and usage examples
- Code Documentation - Architecture and implementation details
- Deployment Guide - Instructions for deploying in various environments
- Performance Optimization - Guidelines for optimizing service performance
- User Guide - Comprehensive guide for using the service
- Clone the repository
- Run
go mod tidyto install dependencies - Start the service with
go run cmd/translator/main.go
The service will start on http://localhost:8080
The service can be configured using either environment variables or a YAML configuration file.
PORT- Server port (default: "8080")OPENAI_ENDPOINT- OpenAI API endpoint (default: "https://api.openai.com/v1")OPENAI_API_KEY- OpenAI API key for GPT modelsANTHROPIC_ENDPOINT- Anthropic API endpoint (default: "https://api.anthropic.com/v1")ANTHROPIC_API_KEY- Anthropic API key for Claude modelsDEBUG- Enable debug mode (default: false)TIMEOUT- Request timeout in seconds (default: 30)
You can also use a YAML configuration file:
go run cmd/translator/main.go -config=config.yamlExample config.yaml:
# Translation Service Configuration
server:
port: "8080"
llm:
openai_endpoint: "https://idealab.alibaba-inc.com/api/openai/v1"
openai_key: "your-openai-key"
anthropic_endpoint: "https://api.anthropic.com/v1"
anthropic_key: "your-anthropic-key"
timeout: 30
debug: falseEnvironment variables will override values from the configuration file.
Access the web interface at http://localhost:8080 to use the translation service through a browser.
Translate text using the REST API:
curl -X POST http://localhost:8080/api/translate \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, world!",
"model": "gpt-3.5"
}'Response:
{
"original": "Hello, world!",
"translation": "你好,世界!",
"model": "gpt-3.5"
}For more detailed API documentation, see API.md.
This project includes a Makefile with common development tasks:
make format- Format code with goimports and gofmtmake lint- Run golangci-lint for static analysismake build- Build the applicationmake run- Run the applicationmake clean- Clean build artifactsmake install-tools- Install development tools
This project uses pre-commit hooks to ensure code quality. Install and set up pre-commit:
- Install pre-commit:
pip install pre-commitorbrew install pre-commit - Install the hooks:
pre-commit install - The hooks will now run automatically on each commit
The pre-commit configuration includes:
- Trailing whitespace removal
- End-of-file fixer
- YAML validation
- Large file checks
- Go formatting (gofmt)
- Go imports formatting (goimports)
- Go linting (golangci-lint)
- Go unit tests