OpenAI Backend (Stub)
The OpenAIBackend is a placeholder for ChatGPT / GPT-4 prompt compilation. It is scheduled for Phase 2 expansion.Status
Implementation: NOT YET IMPLEMENTEDPriority: Scheduled for Phase 2 expansion
Reference: See
anthropic_backend.py for implementation pattern
Planned Design
Target API
OpenAI Chat Completions API:https://platform.openai.com/docs/api-reference/chat/create Models: GPT-4, GPT-4 Turbo, GPT-3.5, future models
Key Differences from Anthropic
- Message Roles: OpenAI uses
system/user/assistantroles - Tool Calls: Uses
function_call/toolsarray format - JSON Mode: Structured output via
response_format: {"type": "json_object"} - Thinking: No extended thinking blocks (requires prompt engineering)
Stub Implementation
Planned Features
System Message Format
Expected structure for OpenAI’ssystem role:
Tool Declaration Format
OpenAI function_call format:JSON Mode for Structured Output
Implementation Roadmap
Phase 1: Core Compilation
- Implement
compile_system_prompt()with persona + anchors - Implement
compile_step()for IRStep, IRIntent, IRProbe - Add message role wrapping (
system,user)
Phase 2: Advanced Features
- Implement
compile_tool_spec()for function calling - Add IRReason compilation with chain-of-thought framing
- Implement IRWeave compilation for synthesis
Phase 3: Optimization
- Tune prompt engineering for GPT-4’s reasoning style
- Add context window management (8k / 32k / 128k)
- Implement JSON schema validation for structured output
How to Implement
1. Study the Reference
Readanthropic_backend.py to understand:
- System prompt structure
- Step compilation dispatch
- Tool specification format
2. Adapt for OpenAI
Key changes:3. Test with Mock Client
Contributing
Interested in implementing the OpenAI backend?- Fork the repository
- Create a feature branch:
git checkout -b feature/openai-backend - Implement
OpenAIBackendfollowing theBaseBackendinterface - Add tests in
tests/test_openai_backend.py - Submit a PR with:
- Implementation of all abstract methods
- Unit tests for each compilation method
- Integration test with MockModelClient
- Documentation updates
Next Steps
Anthropic Reference
Study the reference implementation
Backend Overview
Review backend architecture principles
