diff --git a/README.md b/README.md index a5444a2..703c880 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # openai-c -This is a pure c implementation of a clien the openai api using libcurl +This is a pure c implementation of a client for openai gpt3 api using libcurl ## License MIT do the Hell you want with it diff --git a/TODO b/TODO index e545023..aa707c6 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ code: implement duphandle split with proper name or foldering figure out proper name for a good api - add option to set model max_tokens and temperature maybe use some void thing on Openai ?? add suport for stream diff --git a/easy.c b/easy.c index c5b359a..8b9d052 100644 --- a/easy.c +++ b/easy.c @@ -1,5 +1,4 @@ #include "easy.h" -#include const char *format = "{\"prompt\":\"%s\",\"max_tokens\": %d,\"stop\":\"\"," "\"model\": \"%s\",\"temperature\": %f}"; @@ -9,6 +8,7 @@ struct Openai_easy { char *model; char **stop; int max_tokens; + char *template_prompt; double temperature; }; @@ -39,6 +39,16 @@ OpenAI *openai_easy_init(char *api_key) { return openai; } +OpenAI *openai_easy_duphandle(OpenAI *openai) { + OpenAI *openai_dup = (OpenAI *)malloc(sizeof(OpenAI)); + openai_dup->curl = curl_easy_duphandle(openai->curl); + openai_dup->model = openai->model; + openai_dup->max_tokens = OPENAI_DEFAULT_MAX_TOKENS; + openai_dup->temperature = OPENAI_DEFAULT_TEMPERATURE; + + return openai_dup; +} + CURLcode openai_easy_setopt(OpenAI *openai, OpenAIOption option, ...) { va_list args; diff --git a/easy.h b/easy.h index 45139f4..42a06f0 100644 --- a/easy.h +++ b/easy.h @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -15,6 +14,7 @@ typedef enum { OPENAI_MODEL, OPENAI_MAX_TOKENS, OPENAI_TEMPERATURE, + OPENAI_TEMPLATE_PROMPT, } OpenAIOption; typedef struct Openai_easy OpenAI; diff --git a/main.c b/main.c index 002493c..fa4b342 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,6 @@ #include "easy.h" -char *openai_main_getinput() { +char *openai_main_getinput(void) { char *request; printf("You: "); size_t size = 0; @@ -16,9 +16,7 @@ int main(int argc, char *argv[]) { return 1; } - OpenAI *openai; - openai = openai_easy_init(openai_api_key); - openai_easy_setopt(openai, OPENAI_MAX_TOKENS, 12); + OpenAI *openai = openai_easy_init(openai_api_key); while (1) { char *request = openai_main_getinput();