119 lines
2.8 KiB
C
Raw Normal View History

2025-03-22 03:15:49 +01:00
#ifndef R_H
#define R_H
2025-03-28 06:56:36 +01:00
#include "auth.h"
#include "utils.h"
2025-03-22 03:15:49 +01:00
#include <stdbool.h>
2025-03-28 01:55:04 +01:00
#include <string.h>
2025-04-02 15:37:59 +02:00
bool is_verbose = true;
2025-03-22 03:15:49 +01:00
2025-03-28 20:50:10 +01:00
char *models_api_url = "https://api.openai.com/v1/models";
char *completions_api_url = "https://api.openai.com/v1/chat/completions";
char *advanced_model = "gpt-4o-mini";
char *fast_model = "gpt-3.5-turbo";
2025-03-28 21:38:50 +01:00
2025-05-05 14:33:08 +02:00
// char *models_api_url = "https://api.openai.com/v1/models";
// char *completions_api_url = "https://api.anthropic.com/v1/chat/completions";
// char *advanced_model = "claude-3-5-haiku-20241022";
// char *advanced_model = "meta-llama/Meta-Llama-3.1-8B-Instruct";
// char *advanced_model = "google/gemini-1.5-flash";
// char *fast_model = "claude-3-5-haiku-20241022";
2025-03-28 21:38:50 +01:00
2025-05-05 14:33:08 +02:00
// #endif
// #ifdef OLLAMA
// char *models_api_url = "https://ollama.molodetz.nl/v1/models";
// char *completions_api_url = "https://ollama.molodetz.nl/v1/chat/completions";
// char *advanced_model = "qwen2.5:3b";
// char *advanced_model = "qwen2.5-coder:0.5b";
// char *fast_model = "qwen2.5:0.5b";
// #endif
2025-03-28 20:50:10 +01:00
2025-03-28 06:56:36 +01:00
char *_model = NULL;
2025-03-28 01:55:04 +01:00
2025-03-28 06:55:22 +01:00
#define DB_FILE "~/.r.db"
#define PROMPT_TEMPERATURE 0.1
2025-05-29 02:40:09 +02:00
bool use_tools(){
if(getenv("R_USE_TOOLS") != NULL){
const char *value = getenv("R_USE_TOOLS");
if (!strcmp(value, "true")) {
return true;
}
if (!strcmp(value, "false")) {
return false;
}
if (!strcmp(value, "1")) {
return true;
}
if (!strcmp(value, "0")) {
return false;
}
}
return true;
}
2025-05-24 15:21:13 +02:00
char * get_env_system_message(){
if (getenv("R_SYSTEM_MESSAGE") != NULL) {
return strdup(getenv("R_SYSTEM_MESSAGE"));
}
return NULL;
}
2025-05-05 14:33:08 +02:00
bool get_use_strict() {
if (getenv("R_USE_STRICT") != NULL) {
const char *value = getenv("R_USE_STRICT");
if (!strcmp(value, "true")) {
return true;
}
if (!strcmp(value, "false")) {
return false;
}
if (!strcmp(value, "1")) {
return true;
}
if (!strcmp(value, "0")) {
return false;
}
}
return true;
2025-04-08 10:17:27 +02:00
}
2025-05-05 14:33:08 +02:00
char *get_completions_api_url() {
if (getenv("R_BASE_URL") != NULL) {
return joinpath(getenv("R_BASE_URL"), "v1/chat/completions");
}
return completions_api_url;
2025-04-03 02:18:41 +02:00
}
2025-05-05 14:33:08 +02:00
char *get_models_api_url() {
if (getenv("R_BASE_URL") != NULL) {
return joinpath(getenv("R_BASE_URL"), "v1/models");
}
return models_api_url;
2025-04-03 02:18:41 +02:00
}
2025-03-28 01:55:04 +01:00
void set_prompt_model(const char *model) {
2025-03-28 06:56:36 +01:00
if (_model != NULL) {
free(_model);
}
_model = strdup(model);
2025-03-28 01:55:04 +01:00
}
2025-03-28 06:56:36 +01:00
const char *get_prompt_model() {
2025-05-05 14:33:08 +02:00
if (_model == NULL && getenv("R_MODEL") != NULL) {
2025-05-14 02:43:33 +02:00
_model = strdup(getenv("R_MODEL"));
2025-04-03 02:18:41 +02:00
}
2025-05-05 14:33:08 +02:00
if (_model) {
return _model;
2025-04-03 02:18:41 +02:00
}
2025-03-28 06:56:36 +01:00
if (auth_type != AUTH_TYPE_API_KEY) {
if (_model == NULL) {
2025-03-28 20:50:10 +01:00
_model = strdup(fast_model);
2025-03-28 01:55:04 +01:00
}
2025-03-28 06:56:36 +01:00
} else if (_model == NULL) {
2025-03-28 20:50:10 +01:00
_model = strdup(advanced_model);
2025-03-28 06:56:36 +01:00
}
return _model;
2025-03-28 01:55:04 +01:00
}
2025-03-28 06:56:36 +01:00
#endif