shithub: oai

Download patch

ref: 584040ed6f329d180f03c374474fb9dc321e88e3
parent: 1559dbd7dbc128db9ad7c7f3a389cd38a978b6cc
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Feb 24 14:14:29 EST 2026

fixes asprompt for assistant messages

--- a/oai.c
+++ b/oai.c
@@ -39,6 +39,23 @@
 	return s;
 }
 
+static char*
+read_file(OToolcall toolcall, void*)
+{
+	fprint(2, "toolcall: %s\n", toolcall.name);
+	fprint(2, " args: %s\n", toolcall.arguments);
+	return strdup("not implemented yet");
+}
+
+static char *readfileargs = "{"
+"	\"type\": \"object\","
+"	\"properties\": {"
+"		\"file\": {"
+"			\"type\": \"string\""
+"		}"
+"	}"
+"}";
+
 OTool *tools = nil;
 
 static void
@@ -45,15 +62,7 @@
 inittools(void)
 {
 	tools = maketool(tools, Function, "list_files", "list all files in the current directory, similar to `ls` on unix systems.", nil, list_files, nil);
-}
-
-static char*
-toolcall(OToolcall tc)
-{
-	if (strcmp(tc.name, "list_files") == 0) {
-		return list_files(tc, nil);
-	}
-	return strdup("");
+	maketool(tools, Function, "read_file", "read in a specific file, similar to the `cat` unix command.", readfileargs, read_file, nil);
 }
 
 char *plan9prompt = "You are a helpful AI assistant on a Plan 9 system. Your name is Glenda. Your tone is serious. Be friendly and concise.";
--- a/oailib.c
+++ b/oailib.c
@@ -468,6 +468,7 @@
 	OResult ret;
 	JSON *jreq;
 	JSON *jres;
+	OPrompt *pr;
 	
 	jreq = req2json(req);
 	
@@ -527,7 +528,8 @@
 	jsonfree(jreq);
 	jsonfree(jres);
 	
-	ret.asprompt = nil;
+	ret.asprompt = makeprompt(ret.role);
+	ret.asprompt->content = strdup(ret.message);
 	return ret;
 }
 
--