openai-go icon indicating copy to clipboard operation
openai-go copied to clipboard

resp.OutputText() is a great helper, but not very useful with Web Search (request for resp.GetAnnotations()

Open qhenkart opened this issue 7 months ago • 2 comments

I love this helper

func (r Response) OutputText() string {
	var outputText strings.Builder
	for _, item := range r.Output {
		for _, content := range item.Content {
			if content.Type == "output_text" {
				outputText.WriteString(content.Text)
			}
		}
	}
	return outputText.String()
}

offered in both the chat completions and response api.

The problem is if the consumer uses web search, then we can almost never use that convenience helper. Because we have to loop through all of the outputs and content arrays to look for annotations anyway.

It would be great to add a helper to getAnnotations(), or improve the outputText helper to also include either annotations, a struct of various output options or even the index to get it ourselves

qhenkart avatar Apr 24 '25 05:04 qhenkart