diff --git a/examples/getting_started/agent/step04_using_function_tools_with_approvals/main.go b/examples/getting_started/agent/step04_using_function_tools_with_approvals/main.go index 086e612a..e4821c30 100644 --- a/examples/getting_started/agent/step04_using_function_tools_with_approvals/main.go +++ b/examples/getting_started/agent/step04_using_function_tools_with_approvals/main.go @@ -54,11 +54,10 @@ func main() { var userResponses []message.Content var approvedRequests bool - for req := range resp.UserInputRequests() { + for c := range resp.Contents() { // Ask the user to approve each function call request. - request, ok := req.(*message.FunctionApprovalRequestContent) + request, ok := c.(*message.FunctionApprovalRequestContent) if !ok { - demo.Panicf("unexpected request type: %T", req) continue } approved := demo.UserInputRequest(request) diff --git a/examples/getting_started/azure_openai/step04_using_function_tools_with_approvals/main.go b/examples/getting_started/azure_openai/step04_using_function_tools_with_approvals/main.go index d8640920..3ff89be7 100644 --- a/examples/getting_started/azure_openai/step04_using_function_tools_with_approvals/main.go +++ b/examples/getting_started/azure_openai/step04_using_function_tools_with_approvals/main.go @@ -62,11 +62,10 @@ func main() { var userResponses []message.Content var approvedRequests bool - for req := range resp.UserInputRequests() { + for c := range resp.Contents() { // Ask the user to approve each function call request. - request, ok := req.(*message.FunctionApprovalRequestContent) + request, ok := c.(*message.FunctionApprovalRequestContent) if !ok { - demo.Panicf("unexpected request type: %T", req) continue } approved := demo.UserInputRequest(request) diff --git a/message/content.go b/message/content.go index 7aae8be0..36298dde 100644 --- a/message/content.go +++ b/message/content.go @@ -9,7 +9,6 @@ import ( "encoding/json" "errors" "fmt" - "iter" "maps" "reflect" "slices" @@ -92,19 +91,6 @@ func (cs Contents) Usage() UsageDetails { return usage } -func (cs Contents) UserInputRequests() iter.Seq[Content] { - return func(yield func(Content) bool) { - for _, c := range cs { - switch c := c.(type) { - case *FunctionApprovalRequestContent: - if !yield(c) { - return - } - } - } - } -} - // TextContent represents plain text content. type TextContent struct { ContentHeader diff --git a/message/message.go b/message/message.go index abc0c61d..807b083b 100644 --- a/message/message.go +++ b/message/message.go @@ -57,10 +57,6 @@ func (m *Message) Usage() UsageDetails { return m.Contents.Usage() } -func (m Message) UserInputRequests() iter.Seq[Content] { - return m.Contents.UserInputRequests() -} - // Clone creates a shallow copy of the message. func (m *Message) Clone() *Message { if m == nil { @@ -89,18 +85,12 @@ func (resp *Response) String() string { return sb.String() } -func (resp *Response) Usage() UsageDetails { - var usage UsageDetails - for _, msg := range resp.Messages { - usage.Add(msg.Usage()) - } - return usage -} - -func (resp *Response) UserInputRequests() iter.Seq[Content] { +// Contents returns a sequence of all the contents in the response, across all messages. +// The contents are returned in the order they were added to the response. +func (resp *Response) Contents() iter.Seq[Content] { return func(yield func(Content) bool) { for _, msg := range resp.Messages { - for c := range msg.UserInputRequests() { + for _, c := range msg.Contents { if !yield(c) { return } @@ -109,6 +99,14 @@ func (resp *Response) UserInputRequests() iter.Seq[Content] { } } +func (resp *Response) Usage() UsageDetails { + var usage UsageDetails + for _, msg := range resp.Messages { + usage.Add(msg.Usage()) + } + return usage +} + func (resp *Response) Coalesce() { for _, msg := range resp.Messages { msg.Contents = CoalesceContents(msg.Contents) @@ -214,7 +212,3 @@ func (r *ResponseUpdate) String() string { func (m ResponseUpdate) Usage() UsageDetails { return m.Contents.Usage() } - -func (r *ResponseUpdate) UserInputRequests() iter.Seq[Content] { - return r.Contents.UserInputRequests() -}