Skip to content

Commit 7e56cf2

Browse files
committed
Make context reading resilient and refine responses default
1 parent 46956cb commit 7e56cf2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/adapters/openai.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ fn should_use_responses_api(config: &ModelConfig) -> bool {
169169
return flag;
170170
}
171171

172+
if let Some(base_url) = config.base_url.as_ref() {
173+
if !base_url.contains("openai.com") {
174+
return false;
175+
}
176+
}
177+
172178
!config.model_name.starts_with("gpt-3.5")
173179
}
174180

src/core/context.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl ContextFetcher {
3939

4040
let full_path = self.repo_path.join(file_path);
4141
if full_path.exists() {
42-
let content = tokio::fs::read_to_string(&full_path).await?;
42+
let content = read_file_lossy(&full_path).await?;
4343
let file_lines: Vec<&str> = content.lines().collect();
4444
let merged_ranges = merge_ranges(lines);
4545

@@ -100,7 +100,7 @@ impl ContextFetcher {
100100

101101
for path in matched_paths.into_iter().take(max_files) {
102102
let relative_path = path.strip_prefix(&self.repo_path).unwrap_or(&path);
103-
let content = tokio::fs::read_to_string(&path).await?;
103+
let content = read_file_lossy(&path).await?;
104104
let snippet = content
105105
.lines()
106106
.take(max_lines)
@@ -135,7 +135,7 @@ impl ContextFetcher {
135135
// Search for symbol definitions in the same file first
136136
let full_path = self.repo_path.join(file_path);
137137
if full_path.exists() {
138-
if let Ok(content) = tokio::fs::read_to_string(&full_path).await {
138+
if let Ok(content) = read_file_lossy(&full_path).await {
139139
let lines: Vec<&str> = content.lines().collect();
140140

141141
for symbol in symbols {
@@ -193,3 +193,13 @@ fn merge_ranges(lines: &[(usize, usize)]) -> Vec<(usize, usize)> {
193193

194194
merged
195195
}
196+
197+
async fn read_file_lossy(path: &Path) -> Result<String> {
198+
match tokio::fs::read_to_string(path).await {
199+
Ok(content) => Ok(content),
200+
Err(_) => {
201+
let bytes = tokio::fs::read(path).await?;
202+
Ok(String::from_utf8_lossy(&bytes).to_string())
203+
}
204+
}
205+
}

0 commit comments

Comments
 (0)