ref: 838fda0aba94e2a6235c3c7cfe35430ed5104c06
parent: dff0176ccca8f8ad2a917b864a805ee57f548d27
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Feb 27 17:22:39 EST 2026
moves model from request to library
--- a/oai.c
+++ b/oai.c
@@ -354,9 +354,8 @@
char *url = nil;
char *key = nil;
+ char *model = nil;
- req.model = nil;
-
if (!(access("/dist/9front", AEXIST) && access("/dist/plan9front", AEXIST))) {/* 9front system */
sysprompt = frontprompt;
@@ -372,7 +371,7 @@
key = EARGF(usage());
break;
case 'm':
- req.model = EARGF(usage());
+ model = EARGF(usage());
break;
case 'u':
url = EARGF(usage());
@@ -397,7 +396,7 @@
if (bflag > 1)
trusted = 1;
- if (!initoai(url, key))
+ if (!initoai(url, key, model))
usage();
bin = Bfdopen(0, OREAD);
--- a/oai.h
+++ b/oai.h
@@ -23,7 +23,6 @@
};
struct ORequest {- char *model;
OPrompt *prompts;
OTool *tools;
};
@@ -55,9 +54,9 @@
/*
* initoai returns 1 on success. If baseurl or apikey is nil, it'll try to fetch the data
- * from the environment variables $oaiurl and $oaikey. Key is optional.
+ * from the environment variables $oaiurl, $oaikey and $oaimodel.
*/
-int initoai(char *baseurl, char *apikey);
+int initoai(char *baseurl, char *apikey, char *model);
/*
* makerequest to make the request.
--- a/oailib.c
+++ b/oailib.c
@@ -6,6 +6,7 @@
static char *baseurl = nil;
static char *apikey = nil;
+static char *model = nil;
int oaidebug = 0;
@@ -27,7 +28,7 @@
}
int
-initoai(char *url, char *key)
+initoai(char *url, char *key, char *imodel)
{if (!url)
url = getenv("oaiurl");@@ -41,6 +42,10 @@
key = getenv("oaikey");apikey = key;
+ if (!imodel)
+ imodel = getenv("oaimodel");+ model = imodel;
+
JSONfmtinstall();
return 1;
@@ -200,8 +205,8 @@
el = el->next;
}
- if (req->model) {- tel->next = mkstrjson("model", req->model);+ if (model) {+ tel->next = mkstrjson("model", model);}
return j;
--- a/ocomplete.c
+++ b/ocomplete.c
@@ -65,9 +65,9 @@
char *toks[2];
Biobuf *bodyin, *selout;
char *url = nil;
+ char *model = nil;
req.prompts = nil;
- req.model = nil;
ARGBEGIN{case 'h':
@@ -76,7 +76,7 @@
key = EARGF(usage());
break;
case 'm':
- req.model = EARGF(usage());
+ model = EARGF(usage());
break;
case 'u':
url = EARGF(usage());
@@ -92,7 +92,7 @@
readfilename();
- if (!initoai(url, key))
+ if (!initoai(url, key, model))
sysfatal("initoai: %r");/* get addr */
--
⑨