Skip to content

Commit ca33ce8

Browse files
committed
Capture errors in ollama responses
1 parent 63424a1 commit ca33ce8

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/repl/llm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,15 @@ func (p *OllamaProvider) SendMessage(ctx context.Context, messages []Message, st
585585
Message struct {
586586
Content string `json:"content""`
587587
} `json:"message""`
588+
Error string `json:"error,omitempty""`
588589
}
589590

590591
if err := json.Unmarshal(respBody, &response); err != nil {
591592
return "", err
592593
}
594+
if response.Error != "" {
595+
return "", fmt.Errorf(response.Error)
596+
}
593597

594598
// Return raw content - newline conversion happens in the REPL
595599
return response.Message.Content, nil

src/repl/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func mapToArray(m map[string]interface{}) []string {
173173
// extractJSONBlock locates the first balanced JSON object in text (or fenced JSON)
174174
// and returns it plus any remaining tail text.
175175
func extractJSONBlock(text string) (string, string) {
176-
if !strings.Contains(text, "\"plan\"") {
176+
if !strings.Contains(text, "\"plan\":") {
177177
return "", text
178178
}
179179
// Attempt fenced JSON block: ```json ... ```

0 commit comments

Comments
 (0)