diff --git a/model.go b/model.go index c45b12ce3f3139a912d42e16904f75199704d92c..e73f181efc522de97bc38008e19d858d07006c1e 100644 --- a/model.go +++ b/model.go @@ -34,7 +34,9 @@ type ResponseContent []Content func (r ResponseContent) Text() string { for _, c := range r { if c.GetType() == ContentTypeText { - return c.(TextContent).Text + if textContent, ok := AsContentType[TextContent](c); ok { + return textContent.Text + } } } return "" diff --git a/provider_registry.go b/provider_registry.go index 36c96c447e53222063a00d703dc1722ba8c6433c..efd90446d9b2acc3a45230a5a07eedc3603110a7 100644 --- a/provider_registry.go +++ b/provider_registry.go @@ -38,7 +38,7 @@ func unmarshalProviderData(data []byte) (ProviderOptionsData, error) { return nil, fmt.Errorf("unknown provider data type: %s", pj.Type) } - unmarshalFn := val.(UnmarshalFunc) + unmarshalFn := val.(UnmarshalFunc) //nolint:forcetypeassert // type enforced by RegisterProviderType return unmarshalFn(pj.Data) } diff --git a/providers/openai/language_model.go b/providers/openai/language_model.go index 55227bd92a263841eef3d15c1be8a8ab198c0f11..f37cee5280c9b299e17caded29c673e003477dcf 100644 --- a/providers/openai/language_model.go +++ b/providers/openai/language_model.go @@ -648,14 +648,18 @@ func parseAnnotationsFromDelta(delta openai.ChatCompletionChunkChoiceDelta) []op if annotationMap, ok := annotationData.(map[string]any); ok { if annotationType, ok := annotationMap["type"].(string); ok && annotationType == "url_citation" { if urlCitationData, ok := annotationMap["url_citation"].(map[string]any); ok { - annotation := openai.ChatCompletionMessageAnnotation{ - Type: "url_citation", - URLCitation: openai.ChatCompletionMessageAnnotationURLCitation{ - URL: urlCitationData["url"].(string), - Title: urlCitationData["title"].(string), - }, + url, urlOk := urlCitationData["url"].(string) + title, titleOk := urlCitationData["title"].(string) + if urlOk && titleOk { + annotation := openai.ChatCompletionMessageAnnotation{ + Type: "url_citation", + URLCitation: openai.ChatCompletionMessageAnnotationURLCitation{ + URL: url, + Title: title, + }, + } + annotations = append(annotations, annotation) } - annotations = append(annotations, annotation) } } }