From f9f1955748a3b369f0a015405af131c9b6e3285c Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 4 Oct 2025 16:53:57 +0200 Subject: namespace for logger, strops, locales --- src/ai_providers/openAI.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/ai_providers/openAI.cpp') diff --git a/src/ai_providers/openAI.cpp b/src/ai_providers/openAI.cpp index 415d8ce..340359e 100644 --- a/src/ai_providers/openAI.cpp +++ b/src/ai_providers/openAI.cpp @@ -23,7 +23,7 @@ #define CPPHTTPLIB_OPENSSL_SUPPORT #include "httplib.h" #include "strops.hpp" -#include "log.hpp" +#include "logger.hpp" #include "importer.hpp" static bool _openAI_query_with_file(char* query, size_t query_length, char* file_id, char** response) @@ -34,7 +34,7 @@ static bool _openAI_query_with_file(char* query, size_t query_length, char* file httplib::SSLClient cli("api.openai.com", 443); //cli.enable_server_certificate_verification(false); - char* query_escaped = strops_prep_str_for_json(query, query_length); + char* query_escaped = strops::prep_str_for_json(query, query_length); free(query); size_t body_size = query_length + 200; @@ -50,8 +50,8 @@ static bool _openAI_query_with_file(char* query, size_t query_length, char* file free(body); if (!res || res->status != 200) { - log_error("ERROR Failed to query API."); - log_error(res->body.c_str()); + logger::error("ERROR Failed to query API."); + logger::error(res->body.c_str()); return 0; } @@ -60,12 +60,12 @@ static bool _openAI_query_with_file(char* query, size_t query_length, char* file memset(*response, 0, 100000); strncpy(*response, response_body, 100000); - strops_get_json_value(*response, "text", *response, 100000); - *response = strops_unprep_str_from_json(*response); + strops::get_json_value(*response, "text", *response, 100000); + *response = strops::unprep_str_from_json(*response); #else *response = (char*)malloc(100000); memset(*response, 0, 100000); - strops_copy(*response, " urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 492043632 2024-09-01 2024-09-01 380 USD Final invoice do:team:67840ecb-44e2-472e-bc45-801bd4e1f1fe DigitalOcean LLC 101 Avenue of the Americas 2nd Floor New York 10013 NY US EU528002224 VAT DigitalOcean LLC My Team Keerderstraat 81 Maastricht 6226 XW LI NL VAT aldrikboy@gmail.com 492043632 3.49 15.60 3.28 VAT 1.00 0.21 VAT 16.60 16.60 20.09 20.09 1 16.60 false Discount Product Usage Charges Internal Tax Rate ID VAT ", 100000); + strops::copy(*response, " urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 492043632 2024-09-01 2024-09-01 380 USD Final invoice do:team:67840ecb-44e2-472e-bc45-801bd4e1f1fe DigitalOcean LLC 101 Avenue of the Americas 2nd Floor New York 10013 NY US EU528002224 VAT DigitalOcean LLC My Team Keerderstraat 81 Maastricht 6226 XW LI NL VAT aldrikboy@gmail.com 492043632 3.49 15.60 3.28 VAT 1.00 0.21 VAT 16.60 16.60 20.09 20.09 1 16.60 false Discount Product Usage Charges Internal Tax Rate ID VAT ", 100000); #endif return 1; @@ -74,11 +74,11 @@ static bool _openAI_query_with_file(char* query, size_t query_length, char* file static bool _openAI_upload_file(char* file_path, char* file_id, size_t file_id_len) { const char *api_key = administration_get_ai_service().api_key_public; - const char *filename = strops_get_filename(file_path); + const char *filename = strops::get_filename(file_path); FILE* orig_file = fopen(file_path, "rb"); if (orig_file == NULL) { - log_error("ERROR: file to upload could not be opened."); + logger::error("ERROR: file to upload could not be opened."); return 0; } @@ -97,16 +97,16 @@ static bool _openAI_upload_file(char* file_path, char* file_id, size_t file_id_l httplib::Result res = cli.Post("/v1/uploads", headers, body, "application/json"); if (!res || res->status != 200) { - log_error("ERROR Failed to create upload."); - log_error(res->body.c_str()); + logger::error("ERROR Failed to create upload."); + logger::error(res->body.c_str()); fclose(orig_file); return 0; } char upload_id[128]; - strops_get_json_value(res->body.c_str(), "id", upload_id, sizeof(upload_id)); + strops::get_json_value(res->body.c_str(), "id", upload_id, sizeof(upload_id)); size_t part_size = 64000000; // 64mb - log_info("Created upload %s with part size %zu.", upload_id, part_size); + logger::info("Created upload %s with part size %zu.", upload_id, part_size); char *buffer = (char*)malloc(part_size); @@ -133,20 +133,20 @@ static bool _openAI_upload_file(char* file_path, char* file_id, size_t file_id_l httplib::Result part_res = cli.Post(path, part_headers, items); if (!part_res || part_res->status != 200) { - log_error("Failed to upload part %d.", part_number); - log_error(part_res->body.c_str()); + logger::error("Failed to upload part %d.", part_number); + logger::error(part_res->body.c_str()); free(buffer); fclose(orig_file); return 0; } else { char part_id[128]; - strops_get_json_value(part_res->body.c_str(), "id", part_id, sizeof(part_id)); + strops::get_json_value(part_res->body.c_str(), "id", part_id, sizeof(part_id)); if (part_number == 0) snprintf(completion_body+strlen(completion_body), sizeof(completion_body)-strlen(completion_body), "\"%s\"", part_id); if (part_number != 0) snprintf(completion_body+strlen(completion_body), sizeof(completion_body)-strlen(completion_body), ", \"%s\"", part_id); } - log_info("Uploaded part %d\n", part_number); + logger::info("Uploaded part %d\n", part_number); part_number++; } @@ -162,13 +162,13 @@ static bool _openAI_upload_file(char* file_path, char* file_id, size_t file_id_l if (!complete_res || complete_res->status != 200) { - log_error("ERROR Failed to complete upload."); - log_error(complete_res->body.c_str()); + logger::error("ERROR Failed to complete upload."); + logger::error(complete_res->body.c_str()); return 0; } char* completion_body_response = (char*)complete_res->body.c_str(); - strops_get_json_value(completion_body_response, "id", file_id, file_id_len, 1); + strops::get_json_value(completion_body_response, "id", file_id, file_id_len, 1); return 1; } -- cgit v1.2.3-70-g09d2