diff --git a/llms/anthropic/anthropicllm.go b/llms/anthropic/anthropicllm.go index 2d236ebe5..cddb7ce05 100644 --- a/llms/anthropic/anthropicllm.go +++ b/llms/anthropic/anthropicllm.go @@ -152,6 +152,9 @@ func generateMessagesContent(ctx context.Context, o *LLM, messages []llms.Messag } return nil, fmt.Errorf("anthropic: failed to create message: %w", err) } + if result == nil { + return nil, ErrEmptyResponse + } choices := make([]*llms.ContentChoice, len(result.Content)) for i, content := range result.Content { diff --git a/llms/anthropic/internal/anthropicclient/messages.go b/llms/anthropic/internal/anthropicclient/messages.go index 10a0ca400..3cdd22af5 100644 --- a/llms/anthropic/internal/anthropicclient/messages.go +++ b/llms/anthropic/internal/anthropicclient/messages.go @@ -135,7 +135,7 @@ func (m *MessageResponsePayload) UnmarshalJSON(data []byte) error { } m.Content = append(m.Content, tuc) default: - return fmt.Errorf("unknown content type: %s", typeStruct.Type) + return fmt.Errorf("unknown content type: %s\n%v", typeStruct.Type, string(raw)) } } @@ -268,8 +268,10 @@ func processStreamEvent(ctx context.Context, event map[string]interface{}, paylo eventChan <- MessageEvent{Response: &response, Err: nil} case "ping": // Nothing to do here + case "error": + eventChan <- MessageEvent{Response: nil, Err: fmt.Errorf("received error event: %v", event)} default: - log.Printf("unknown event type: %s", eventType) + log.Printf("unknown event type: %s - %v", eventType, event) } return response, nil }