feat(z3ed): Complete Phase 2 - Gemini AI service enhancement
Phase 2 Implementation Summary: - Enhanced GeminiAIService with production-ready features - Added GeminiConfig struct for flexible configuration - Implemented health check system with graceful degradation - Updated to Gemini v1beta API format - Added robust JSON parsing with markdown stripping fallbacks - Switched default model to gemini-1.5-flash (faster, cheaper) - Enhanced error messages with actionable guidance - Integrated into service factory with health checks - Added comprehensive test infrastructure Files Modified: - src/cli/service/gemini_ai_service.h (added config struct) - src/cli/service/gemini_ai_service.cc (rewritten for v1beta) - src/cli/handlers/agent/general_commands.cc (factory update) - docs/z3ed/LLM-IMPLEMENTATION-CHECKLIST.md (progress tracking) Files Created: - scripts/test_gemini_integration.sh (test suite) - docs/z3ed/PHASE2-COMPLETE.md (implementation summary) - docs/z3ed/LLM-PROGRESS-UPDATE.md (overall progress) Build Status: ✅ SUCCESS (macOS ARM64) Test Status: ✅ Graceful fallback validated Pending: Real API key validation See docs/z3ed/PHASE2-COMPLETE.md for details.
This commit is contained in:
@@ -6,89 +6,106 @@
|
||||
|
||||
> 📋 **Main Guide**: See [LLM-INTEGRATION-PLAN.md](LLM-INTEGRATION-PLAN.md) for detailed implementation instructions.
|
||||
|
||||
## Phase 1: Ollama Local Integration (4-6 hours) 🎯 START HERE
|
||||
## Phase 1: Ollama Local Integration (4-6 hours) ✅ COMPLETE
|
||||
|
||||
### Prerequisites
|
||||
- [ ] Install Ollama: `brew install ollama` (macOS)
|
||||
- [ ] Start Ollama server: `ollama serve`
|
||||
- [ ] Pull recommended model: `ollama pull qwen2.5-coder:7b`
|
||||
- [ ] Test connectivity: `curl http://localhost:11434/api/tags`
|
||||
- [x] Install Ollama: `brew install ollama` (macOS)
|
||||
- [x] Start Ollama server: `ollama serve`
|
||||
- [x] Pull recommended model: `ollama pull qwen2.5-coder:7b`
|
||||
- [x] Test connectivity: `curl http://localhost:11434/api/tags`
|
||||
|
||||
### Implementation Tasks
|
||||
|
||||
#### 1.1 Create OllamaAIService Class
|
||||
- [ ] Create `src/cli/service/ollama_ai_service.h`
|
||||
- [ ] Define `OllamaConfig` struct
|
||||
- [ ] Declare `OllamaAIService` class with `GetCommands()` override
|
||||
- [ ] Add `CheckAvailability()` and `ListAvailableModels()` methods
|
||||
- [ ] Create `src/cli/service/ollama_ai_service.cc`
|
||||
- [ ] Implement constructor with config
|
||||
- [ ] Implement `BuildSystemPrompt()` with z3ed command documentation
|
||||
- [ ] Implement `CheckAvailability()` with health check
|
||||
- [ ] Implement `GetCommands()` with Ollama API call
|
||||
- [ ] Add JSON parsing for command extraction
|
||||
- [ ] Add error handling for connection failures
|
||||
- [x] Create `src/cli/service/ollama_ai_service.h`
|
||||
- [x] Define `OllamaConfig` struct
|
||||
- [x] Declare `OllamaAIService` class with `GetCommands()` override
|
||||
- [x] Add `CheckAvailability()` and `ListAvailableModels()` methods
|
||||
- [x] Create `src/cli/service/ollama_ai_service.cc`
|
||||
- [x] Implement constructor with config
|
||||
- [x] Implement `BuildSystemPrompt()` with z3ed command documentation
|
||||
- [x] Implement `CheckAvailability()` with health check
|
||||
- [x] Implement `GetCommands()` with Ollama API call
|
||||
- [x] Add JSON parsing for command extraction
|
||||
- [x] Add error handling for connection failures
|
||||
|
||||
#### 1.2 Update CMake Configuration
|
||||
- [ ] Add `YAZE_WITH_HTTPLIB` option to `CMakeLists.txt`
|
||||
- [ ] Add httplib detection (vcpkg or bundled)
|
||||
- [ ] Add compile definition `YAZE_WITH_HTTPLIB`
|
||||
- [ ] Update z3ed target to link httplib when available
|
||||
- [x] Add `YAZE_WITH_HTTPLIB` option to `CMakeLists.txt`
|
||||
- [x] Add httplib detection (vcpkg or bundled)
|
||||
- [x] Add compile definition `YAZE_WITH_HTTPLIB`
|
||||
- [x] Update z3ed target to link httplib when available
|
||||
|
||||
#### 1.3 Wire into Agent Commands
|
||||
- [ ] Update `src/cli/handlers/agent/general_commands.cc`
|
||||
- [ ] Add `#include "cli/service/ollama_ai_service.h"`
|
||||
- [ ] Create `CreateAIService()` helper function
|
||||
- [ ] Implement provider selection logic (env vars)
|
||||
- [ ] Add health check with fallback to MockAIService
|
||||
- [ ] Update `HandleRunCommand()` to use service factory
|
||||
- [ ] Update `HandlePlanCommand()` to use service factory
|
||||
- [x] Update `src/cli/handlers/agent/general_commands.cc`
|
||||
- [x] Add `#include "cli/service/ollama_ai_service.h"`
|
||||
- [x] Create `CreateAIService()` helper function
|
||||
- [x] Implement provider selection logic (env vars)
|
||||
- [x] Add health check with fallback to MockAIService
|
||||
- [x] Update `HandleRunCommand()` to use service factory
|
||||
- [x] Update `HandlePlanCommand()` to use service factory
|
||||
|
||||
#### 1.4 Testing & Validation
|
||||
- [ ] Create `scripts/test_ollama_integration.sh`
|
||||
- [ ] Check Ollama server availability
|
||||
- [ ] Verify model is pulled
|
||||
- [ ] Test `z3ed agent run` with simple prompt
|
||||
- [ ] Verify proposal creation
|
||||
- [ ] Review generated commands
|
||||
- [ ] Run end-to-end test
|
||||
- [ ] Document any issues encountered
|
||||
- [x] Create `scripts/test_ollama_integration.sh`
|
||||
- [x] Check Ollama server availability
|
||||
- [x] Verify model is pulled
|
||||
- [x] Test `z3ed agent run` with simple prompt
|
||||
- [x] Verify proposal creation
|
||||
- [x] Review generated commands
|
||||
- [x] Run end-to-end test
|
||||
- [x] Document any issues encountered
|
||||
|
||||
### Success Criteria
|
||||
- [ ] `z3ed agent run --prompt "Validate ROM"` generates correct command
|
||||
- [ ] Health check reports clear errors when Ollama unavailable
|
||||
- [ ] Service fallback to MockAIService works correctly
|
||||
- [ ] Test script passes without manual intervention
|
||||
- [x] `z3ed agent run --prompt "Validate ROM"` generates correct command
|
||||
- [x] Health check reports clear errors when Ollama unavailable
|
||||
- [x] Service fallback to MockAIService works correctly
|
||||
- [x] Test script passes without manual intervention
|
||||
|
||||
**Status:** ✅ Complete - See [PHASE1-COMPLETE.md](PHASE1-COMPLETE.md)
|
||||
|
||||
---
|
||||
|
||||
## Phase 2: Improve Gemini Integration (2-3 hours)
|
||||
## Phase 2: Improve Gemini Integration (2-3 hours) ✅ COMPLETE
|
||||
|
||||
### Implementation Tasks
|
||||
|
||||
#### 2.1 Fix GeminiAIService
|
||||
- [ ] Update `src/cli/service/gemini_ai_service.cc`
|
||||
- [ ] Fix system instruction format
|
||||
- [ ] Update to use `gemini-1.5-flash` model
|
||||
- [ ] Add generation config (temperature, maxOutputTokens)
|
||||
- [ ] Add safety settings
|
||||
- [ ] Implement markdown code block stripping
|
||||
- [ ] Improve error messages with actionable guidance
|
||||
- [x] Update `src/cli/service/gemini_ai_service.h`
|
||||
- [x] Add `GeminiConfig` struct with model, temperature, max_tokens
|
||||
- [x] Add health check methods
|
||||
- [x] Update constructor signature
|
||||
- [x] Update `src/cli/service/gemini_ai_service.cc`
|
||||
- [x] Fix system instruction format (separate field in v1beta API)
|
||||
- [x] Update to use `gemini-1.5-flash` model
|
||||
- [x] Add generation config (temperature, maxOutputTokens)
|
||||
- [x] Add `responseMimeType: application/json` for structured output
|
||||
- [x] Implement markdown code block stripping
|
||||
- [x] Add `CheckAvailability()` with API key validation
|
||||
- [x] Improve error messages with actionable guidance
|
||||
|
||||
#### 2.2 Wire into Service Factory
|
||||
- [ ] Update `CreateAIService()` to check for `GEMINI_API_KEY`
|
||||
- [ ] Add Gemini as provider option
|
||||
- [ ] Test with real API key
|
||||
- [x] Update `CreateAIService()` to use `GeminiConfig`
|
||||
- [x] Add Gemini health check with fallback
|
||||
- [x] Add `GEMINI_MODEL` environment variable support
|
||||
- [x] Test with graceful fallback
|
||||
|
||||
#### 2.3 Testing
|
||||
- [ ] Test with various prompts
|
||||
- [ ] Verify JSON array parsing
|
||||
- [ ] Test error handling (invalid key, network issues)
|
||||
- [x] Create `scripts/test_gemini_integration.sh`
|
||||
- [x] Test graceful fallback without API key
|
||||
- [x] Test error handling (invalid key, network issues)
|
||||
- [ ] Test with real API key (pending)
|
||||
- [ ] Verify JSON array parsing (pending)
|
||||
- [ ] Test various prompts (pending)
|
||||
|
||||
### Success Criteria
|
||||
- [ ] Gemini generates valid command arrays
|
||||
- [ ] Markdown stripping works reliably
|
||||
- [ ] Error messages guide user to API key setup
|
||||
- [x] Gemini service compiles and builds
|
||||
- [x] Service factory integration works
|
||||
- [x] Graceful fallback to MockAIService
|
||||
- [ ] Gemini generates valid command arrays (pending API key)
|
||||
- [ ] Markdown stripping works reliably (pending API key)
|
||||
- [x] Error messages guide user to API key setup
|
||||
|
||||
**Status:** ✅ Complete (build & integration) - See [PHASE2-COMPLETE.md](PHASE2-COMPLETE.md)
|
||||
**Pending:** Real API key validation
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user