summaryrefslogtreecommitdiff
path: root/libpanto/src/openai_chat_json.zig
diff options
context:
space:
mode:
Diffstat (limited to 'libpanto/src/openai_chat_json.zig')
-rw-r--r--libpanto/src/openai_chat_json.zig30
1 files changed, 20 insertions, 10 deletions
diff --git a/libpanto/src/openai_chat_json.zig b/libpanto/src/openai_chat_json.zig
index b30b424..8af939f 100644
--- a/libpanto/src/openai_chat_json.zig
+++ b/libpanto/src/openai_chat_json.zig
@@ -535,6 +535,16 @@ fn emptyTools() tool_registry_mod.ToolRegistry {
return tool_registry_mod.ToolRegistry.init(testing.allocator);
}
+/// Test helper: append a single-text user message. `addUserMessage` now
+/// takes a block slice (symmetric with `addAssistantMessage`); this wraps
+/// the common plain-text case the tests below use.
+fn addUserText(conv: *conversation.Conversation, text: []const u8) !void {
+ const tb = try conversation.textualBlockFromSlice(conv.allocator, text);
+ var block: conversation.ContentBlock = .{ .Text = tb };
+ errdefer block.deinit(conv.allocator);
+ try conv.addUserMessage(&.{block});
+}
+
test "serializeRequest - system + user" {
const allocator = testing.allocator;
@@ -542,7 +552,7 @@ test "serializeRequest - system + user" {
defer conv.deinit();
try conv.addSystemMessage("You are helpful.");
- try conv.addUserMessage("Hello!");
+ try addUserText(&conv, "Hello!");
const cfg = testConfig("gpt-4o");
var tools = emptyTools();
@@ -576,9 +586,9 @@ test "serializeRequest - multiple system blocks hoisted as separate leading mess
defer conv.deinit();
try conv.addSystemMessage("seed");
- try conv.addUserMessage("Hello!");
+ try addUserText(&conv, "Hello!");
try conv.addSystemMessage("mid-conversation append");
- try conv.addUserMessage("again");
+ try addUserText(&conv, "again");
const cfg = testConfig("gpt-4o");
var tools = emptyTools();
@@ -611,7 +621,7 @@ test "serializeRequest - replace-mode system block wipes prior system messages"
try conv.addSystemMessage("original");
try conv.replaceSystemMessage("fresh seed");
try conv.addSystemMessage("fresh append");
- try conv.addUserMessage("Hi");
+ try addUserText(&conv, "Hi");
const cfg = testConfig("gpt-4o");
var tools = emptyTools();
@@ -663,7 +673,7 @@ test "serializeRequest - reasoning effort level included when set" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("Hi");
+ try addUserText(&conv, "Hi");
var cfg = testConfig("gpt-4o");
cfg.reasoning = .high;
@@ -687,7 +697,7 @@ test "serializeRequest - reasoning .off sends \"none\"" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("Hi");
+ try addUserText(&conv, "Hi");
var cfg = testConfig("gpt-4o");
cfg.reasoning = .off;
@@ -798,7 +808,7 @@ test "serializeRequest - emits tools array when registry non-empty" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("call something");
+ try addUserText(&conv, "call something");
var tools = emptyTools();
defer tools.deinit();
@@ -833,7 +843,7 @@ test "serializeRequest - dotted tool name is wire-encoded with __" {
var conv = conversation.Conversation.init(allocator);
defer conv.deinit();
- try conv.addUserMessage("go");
+ try addUserText(&conv, "go");
var tools = emptyTools();
defer tools.deinit();
@@ -1050,14 +1060,14 @@ test "serializeRequest - compaction summary trims superseded prefix" {
// System prompt survives compaction.
try conv.addSystemMessage("you are helpful");
// Old prefix that must be dropped.
- try conv.addUserMessage("ancient question");
+ try addUserText(&conv, "ancient question");
try conv.addAssistantMessage(&.{
.{ .Text = try conversation.textualBlockFromSlice(allocator, "ancient answer") },
}, null);
// Compaction summary resets conversation context.
try conv.addCompactionSummary("summary of the ancient exchange");
// Kept-verbatim suffix replayed after the summary.
- try conv.addUserMessage("recent question");
+ try addUserText(&conv, "recent question");
var tools = emptyTools();
defer tools.deinit();