diff options
Diffstat (limited to 'libpanto/src/conversation.zig')
| -rw-r--r-- | libpanto/src/conversation.zig | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/libpanto/src/conversation.zig b/libpanto/src/conversation.zig index 1fc5016..a436378 100644 --- a/libpanto/src/conversation.zig +++ b/libpanto/src/conversation.zig @@ -292,15 +292,11 @@ pub const Conversation = struct { }); } - /// Append an assistant message. Ownership of the blocks is transferred - /// to the conversation; the caller must not deinit them after this call. - pub fn addAssistantMessage(self: *Conversation, blocks: []const ContentBlock) !void { - return self.addAssistantMessageWithUsage(blocks, null); - } - - /// Append an assistant message tagged with its provider-reported - /// `usage`. Ownership of the blocks is transferred to the conversation. - pub fn addAssistantMessageWithUsage( + /// Append an assistant message, optionally tagged with its + /// provider-reported `usage` (pass `null` for none). Ownership of the + /// blocks is transferred to the conversation; the caller must not + /// deinit them after this call. + pub fn addAssistantMessage( self: *Conversation, blocks: []const ContentBlock, usage: ?Usage, @@ -415,7 +411,7 @@ test "Conversation - add messages and verify content" { try conv.addUserMessage("Hello!"); try conv.addAssistantMessage(&.{ .{ .Text = try textualBlockFromSlice(allocator, "Hi there!") }, - }); + }, null); try std.testing.expectEqual(@as(usize, 3), conv.messages.items.len); @@ -455,7 +451,7 @@ test "Conversation - deinit frees without leaks" { try conv.addUserMessage("user message"); try conv.addAssistantMessage(&.{ .{ .Text = try textualBlockFromSlice(allocator, "response") }, - }); + }, null); conv.deinit(); } @@ -468,7 +464,7 @@ test "ContentBlock - Thinking variant" { try conv.addAssistantMessage(&.{ .{ .Thinking = .{ .text = try textualBlockFromSlice(allocator, "hmm...") } }, .{ .Text = try textualBlockFromSlice(allocator, "answer") }, - }); + }, null); try std.testing.expectEqual(@as(usize, 2), conv.messages.items[0].content.items.len); try std.testing.expectEqualStrings("hmm...", conv.messages.items[0].content.items[0].Thinking.text.items); @@ -574,7 +570,7 @@ test "latestCompactionIndex - null when never compacted" { try conv.addUserMessage("hi"); try conv.addAssistantMessage(&.{ .{ .Text = try textualBlockFromSlice(allocator, "hello") }, - }); + }, null); try std.testing.expect(latestCompactionIndex(conv.messages.items) == null); } |
