summaryrefslogtreecommitdiff
path: root/libawl/src/config.zig
diff options
context:
space:
mode:
authorT <t@tjp.lol>2026-04-26 11:09:37 -0600
committerT <t@tjp.lol>2026-05-25 11:48:47 -0700
commit52b2ca78aed7950af27d4865aee65da781514a99 (patch)
tree24f512e67afd677b6c0d8a8064819e8f5332d28d /libawl/src/config.zig
parentd3d5a6295a67bdc99e35e5bfd77359d98a850c3f (diff)
Initial work, and name change to pantograph
Diffstat (limited to 'libawl/src/config.zig')
-rw-r--r--libawl/src/config.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/libawl/src/config.zig b/libawl/src/config.zig
new file mode 100644
index 0000000..8b6f147
--- /dev/null
+++ b/libawl/src/config.zig
@@ -0,0 +1,37 @@
+const std = @import("std");
+
+pub const Config = struct {
+ api_key: []const u8,
+ base_url: []const u8,
+ model: []const u8,
+
+ pub const Error = error{MissingApiKey};
+
+ pub fn fromEnv() Error!Config {
+ const api_key_z = std.c.getenv("PANTO_API_KEY") orelse return Error.MissingApiKey;
+ const api_key = std.mem.sliceTo(api_key_z, 0);
+
+ const base_url_z = std.c.getenv("PANTO_BASE_URL") orelse "https://api.openai.com/v1";
+ const base_url = std.mem.sliceTo(base_url_z, 0);
+
+ const model_z = std.c.getenv("PANTO_MODEL") orelse "gpt-4o";
+ const model = std.mem.sliceTo(model_z, 0);
+
+ return Config{
+ .api_key = api_key,
+ .base_url = base_url,
+ .model = model,
+ };
+ }
+};
+
+test "Config - defaults" {
+ const cfg = Config{
+ .api_key = "test-key",
+ .base_url = "https://api.openai.com/v1",
+ .model = "gpt-4o",
+ };
+ try std.testing.expectEqualStrings("test-key", cfg.api_key);
+ try std.testing.expectEqualStrings("https://api.openai.com/v1", cfg.base_url);
+ try std.testing.expectEqualStrings("gpt-4o", cfg.model);
+}