diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.zig | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/main.zig b/src/main.zig index 89c0bc4..48a1191 100644 --- a/src/main.zig +++ b/src/main.zig @@ -105,10 +105,35 @@ pub fn main() !void { @panic("No choices in response"); } - // You can use print statements as follows for debugging, they'll be visible when running tests. std.debug.print("Logs from your program will appear here!\n", .{}); - // TODO: Uncomment the lines below to pass the first stage - const content = choices.array.items[0].object.get("message").?.object.get("content").?.string; + const message = choices.array.items[0].object.get("message").?; + + // Check for tool_calls in the response + if (message.object.get("tool_calls")) |tool_calls_val| { + if (tool_calls_val != .null and tool_calls_val.array.items.len > 0) { + const tool_call = tool_calls_val.array.items[0]; + const func = tool_call.object.get("function").?; + const func_name = func.object.get("name").?.string; + const arguments_str = func.object.get("arguments").?.string; + + if (std.mem.eql(u8, func_name, "Read")) { + const args_parsed = try std.json.parseFromSlice(std.json.Value, allocator, arguments_str, .{}); + defer args_parsed.deinit(); + + const file_path = args_parsed.value.object.get("file_path").?.string; + std.debug.print("Reading file: {s}\n", .{file_path}); + + const file_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, std.math.maxInt(usize)); + defer allocator.free(file_contents); + + try std.fs.File.stdout().writeAll(file_contents); + return; + } + } + } + + // No tool call — print the text content directly + const content = message.object.get("content").?.string; try std.fs.File.stdout().writeAll(content); } |