// Written by retoor@molodetz.nl // This code defines functionality for creating and managing JSON-based chat prompts // using a specific AI model configuration, providing easy integration with message handling // and HTTP communication for dynamic applications. // Non-standard imports: json-c library for handling JSON objects. // MIT License // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #ifndef CALPACA_PROMPT_H #define CALPACA_PROMPT_H #include #include "messages.h" #include "http.h" char *prompt_model = "gpt-4o-mini"; int prompt_max_tokens = 100; double prompt_temperature = 0.5; json_object *_prompt = NULL; void chat_free() { if (_prompt == NULL) return; json_object_put(_prompt); _prompt = NULL; } char *chat_json(char *role, char *message) { chat_free(); message_add(role, message); struct json_object *root_object = json_object_new_object(); json_object_object_add(root_object, "model", json_object_new_string(prompt_model)); json_object_object_add(root_object, "messages", message_list()); json_object_object_add(root_object, "max_tokens", json_object_new_int(prompt_max_tokens)); json_object_object_add(root_object, "temperature", json_object_new_double(prompt_temperature)); return (char *)json_object_to_json_string_ext(root_object, JSON_C_TO_STRING_PRETTY); } #endif