mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 01:25:53 -04:00
telemetry: remove allocation for llm event
The model length is limited to 23 char in DB.
This commit is contained in:
16
src/main.zig
16
src/main.zig
@@ -198,7 +198,6 @@ fn run(allocator: Allocator, main_arena: Allocator) !void {
|
||||
{
|
||||
var worker_thread = try std.Thread.spawn(.{}, agentThread, .{
|
||||
allocator,
|
||||
main_arena,
|
||||
app,
|
||||
opts,
|
||||
&failed,
|
||||
@@ -219,7 +218,6 @@ fn run(allocator: Allocator, main_arena: Allocator) !void {
|
||||
|
||||
fn agentThread(
|
||||
allocator: std.mem.Allocator,
|
||||
arena: std.mem.Allocator,
|
||||
app: *App,
|
||||
opts: Config.Agent,
|
||||
failed: *bool,
|
||||
@@ -243,15 +241,13 @@ fn agentThread(
|
||||
defer sig_bridge.detach();
|
||||
|
||||
if (agent_instance.ai_client) |cli| {
|
||||
app.telemetry.record(.{ .llm = .{
|
||||
.provider = @tagName(cli),
|
||||
.model = arena.dupe(u8, agent_instance.model) catch null,
|
||||
} });
|
||||
app.telemetry.record(.{
|
||||
.llm = app.telemetry.llm_init(@tagName(cli), agent_instance.model),
|
||||
});
|
||||
} else {
|
||||
app.telemetry.record(.{ .llm = .{
|
||||
.provider = "nollm",
|
||||
.model = null,
|
||||
} });
|
||||
app.telemetry.record(.{
|
||||
.llm = app.telemetry.llm_init("nollm", null),
|
||||
});
|
||||
}
|
||||
|
||||
if (!agent_instance.run()) {
|
||||
|
||||
@@ -60,6 +60,10 @@ fn TelemetryT(comptime P: type) type {
|
||||
log.warn(.telemetry, "record error", .{ .err = err, .type = @tagName(std.meta.activeTag(event)) });
|
||||
};
|
||||
}
|
||||
|
||||
pub fn llm_init(_: *Self, provider: [:0]const u8, model: ?[]const u8) Event.LLM {
|
||||
return Event.LLM.init(provider, model);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,7 +121,36 @@ pub const Event = union(enum) {
|
||||
|
||||
const LLM = struct {
|
||||
provider: [:0]const u8,
|
||||
model: ?[]const u8,
|
||||
model: ?Model,
|
||||
|
||||
const Model = struct {
|
||||
len: u8,
|
||||
buffer: [32]u8,
|
||||
|
||||
pub fn wrap(_s: ?[]const u8) ?Model {
|
||||
if (_s == null) return null;
|
||||
|
||||
const l = @min(_s.?.len, 32);
|
||||
var m: Model = .{
|
||||
.len = l,
|
||||
.buffer = undefined,
|
||||
};
|
||||
@memcpy(m.buffer[0..l], _s.?[0..l]);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
pub fn jsonStringify(self: *const Model, writer: anytype) !void {
|
||||
try writer.write(self.buffer[0..self.len]);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn init(provider: [:0]const u8, _model: ?[]const u8) LLM {
|
||||
return .{
|
||||
.provider = provider,
|
||||
.model = Model.wrap(_model),
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user