Add conversation pkg
This commit is contained in:
@@ -548,6 +548,37 @@ func (m *Message) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateToolCall replaces the call identified by callId, keeping its
|
||||
// position in ToolCalls. The replacement must have the same ID: the
|
||||
// corresponding tool response carries it in Message.ToolCallID.
|
||||
func (m *Message) UpdateToolCall(call ToolCall) error {
|
||||
if err := call.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid tool call: %w", err)
|
||||
}
|
||||
for i := range m.ToolCalls {
|
||||
if m.ToolCalls[i].ID == call.ID {
|
||||
m.ToolCalls[i] = call
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("not found: call %q", call.ID)
|
||||
}
|
||||
|
||||
// AddToolCall appends call to the message's ToolCalls. The call must be
|
||||
// valid and its ID must not already appear in the message.
|
||||
func (m *Message) AddToolCall(call ToolCall) error {
|
||||
if err := call.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid tool call: %w", err)
|
||||
}
|
||||
for _, existing := range m.ToolCalls {
|
||||
if existing.ID == call.ID {
|
||||
return fmt.Errorf("duplicate call id %q", call.ID)
|
||||
}
|
||||
}
|
||||
m.ToolCalls = append(m.ToolCalls, call)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes a message while normalizing a string-valued content
|
||||
// field to one text ContentPart. An array-valued content field is decoded in
|
||||
// order. If reasoning_content is absent, reasoning is copied into
|
||||
|
||||
Reference in New Issue
Block a user