Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solver support Sonnet via OpenRouter #657

Open
AtlantisPleb opened this issue Feb 1, 2025 · 1 comment
Open

Solver support Sonnet via OpenRouter #657

AtlantisPleb opened this issue Feb 1, 2025 · 1 comment

Comments

@AtlantisPleb
Copy link
Contributor

Related to #609

We'll use local for some things and heavy-hitter models on occasion via OpenRouter

We have an existing OpenRouter service

Let's modify the flow specified in docs/solver.md to have Sonnet do the initial selection of files from the repomap and reasons we want to see each one

@AtlantisPleb
Copy link
Contributor Author

Implementation plan for Sonnet support via OpenRouter:

  1. Modify src/bin/solver_impl/planning.rs to use OpenRouter's Sonnet model for initial file selection:
// Add to existing constants
const SONNET_MODEL: &str = "anthropic/claude-3-sonnet";

// Modify handle_planning to use OpenRouter for initial file selection
fn handle_planning(context: &PlanningContext) -> Result<Plan> {
    let openrouter = OpenRouterService::new()?;
    
    // First pass: Use Sonnet to select relevant files
    let file_selection_prompt = format!(
        "Given this issue:\n{}\n\nAnalyze this repository map and select the most relevant files we need to examine, with reasoning for each:\n{}", 
        context.issue.body,
        context.repomap
    );

    let (files_response, _) = openrouter.chat(
        file_selection_prompt,
        SONNET_MODEL,
        true  // Use reasoning mode
    )?;

    // Parse file selections and reasons
    let selected_files = parse_file_selections(&files_response)?;

    // Second pass: Generate detailed implementation plan using local model
    let plan_prompt = format!(
        "Given these selected files:\n{}\n\nGenerate a detailed implementation plan for:\n{}", 
        selected_files,
        context.issue.body
    );

    // Use local model for detailed planning
    let plan = generate_local_plan(context, &plan_prompt)?;

    Ok(plan)
}
  1. Add new types in src/solver/types.rs:
#[derive(Debug, Deserialize)]
pub struct FileSelection {
    pub path: String,
    pub reason: String,
}

#[derive(Debug, Deserialize)]
pub struct FileSelections {
    pub files: Vec<FileSelection>,
}
  1. Add parsing function in src/solver/changes/parsing.rs:
pub fn parse_file_selections(response: &str) -> Result<FileSelections> {
    // Extract JSON from markdown response
    let json = extract_json_from_markdown(response)?;
    
    // Parse into FileSelections struct
    let selections: FileSelections = serde_json::from_str(&json)?;
    
    // Validate paths exist
    validate_file_paths(&selections)?;
    
    Ok(selections)
}
  1. Update OpenRouter service in src/server/services/openrouter/service.rs:
impl OpenRouterService {
    pub fn chat(
        &self,
        prompt: String,
        model: &str,
        use_reasoner: bool
    ) -> Result<(String, Option<String>)> {
        let messages = self.prepare_messages(prompt, use_reasoner);
        
        let response = self.make_request(messages, model)?;
        
        Ok((
            response.choices[0].message.content.clone(),
            if use_reasoner {
                Some(response.choices[0].message.reasoning.clone())
            } else {
                None
            }
        ))
    }
}

This implementation:

  1. Uses Sonnet via OpenRouter for the initial smart file selection
  2. Leverages Sonnet's reasoning capabilities to explain why each file is relevant
  3. Uses local model for detailed implementation planning
  4. Maintains existing solver architecture while adding Sonnet integration
  5. Provides structured file selection with reasoning

The flow will be:

  1. Issue received → Sonnet analyzes and selects relevant files with reasoning
  2. Selected files → Local model generates detailed implementation plan
  3. Plan → Local model generates specific code changes
  4. Changes → PR created

This approach:

  • Uses Sonnet's strengths for high-level analysis
  • Keeps local model for detailed implementation
  • Provides clear reasoning for file selections
  • Maintains existing solver architecture
  • Allows for future model flexibility

(Comment from OpenAgents)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant