Compare commits

...

2 Commits

Author SHA1 Message Date
b36990f550 Update readme. 2025-04-08 10:22:47 +02:00
01c941e29d Implemented strict mode. 2025-04-08 10:17:27 +02:00
5 changed files with 71 additions and 18 deletions

View File

@ -24,6 +24,8 @@ R Vibe Tool is a powerful Command-Line Interface (CLI) utility designed for Linu
### Environment Variables
TIP: create bash files containg these variables and make them easily accessable. For example by symlinking them to `~/.bash_aliases` or `~/.bash_profile`. Or even easier, make them executable and put them in /usr/local/bin.
#### Ollama Configuration
```bash
export R_MODEL="qwen2.5:3b"
@ -39,6 +41,22 @@ export R_KEY="sk-ant-[your-key]"
./r
```
#### OpenAI Configuration
```bash
export R_MODEL="gpt-4o-mini"
export R_BASE_URL="https://api.openai.com"
export R_KEY="sk-[your-key]"
./r
```
#### Grok Configuration
```bash
export R_MODEL="grok-2"
export R_BASE_URL="https://api.x.ai"
export R_USE_STRICT=false
export R_KEY="xai-gfh"
```
## Best Practices
1. Use `~/.rcontext.txt` to define specific behavioral instructions

View File

@ -59,12 +59,17 @@ struct json_object *message_add_tool_call(struct json_object *message) {
}
struct json_object *message_add_tool_result(const char *tool_call_id,
const char *tool_result) {
char *tool_result) {
struct json_object *messages = message_list();
struct json_object *message = json_object_new_object();
json_object_object_add(message, "tool_call_id",
json_object_new_string(tool_call_id));
if(strlen(tool_result) > 104000){
tool_result[104000] = '\0';
}
json_object_object_add(message, "tool_result",
json_object_new_string(tool_result));
@ -84,10 +89,18 @@ struct json_object *message_add(const char *role, const char *content) {
struct json_object *messages = message_list();
struct json_object *message = json_object_new_object();
json_object_object_add(message, "role", json_object_new_string(role));
json_object_object_add(message, "content", json_object_new_string(content));
if(content){
char * formatted_content = strdup(content);
if(strlen(formatted_content) > 1048570){
formatted_content[1048570] = '\0';
}
json_object_object_add(message, "content", json_object_new_string(formatted_content));
free(formatted_content);
}
if (!strcmp(role, "user")) {
json_object_object_add(message, "tools", tools_descriptions());
json_object_object_add(message, "parallel_tool_calls", json_object_new_boolean(true));
}
json_object_array_add(messages, message);

20
r.h
View File

@ -32,6 +32,26 @@ char *_model = NULL;
#define DB_FILE "~/.r.db"
#define PROMPT_TEMPERATURE 0.1
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;
}
char * get_completions_api_url() {
if(getenv("R_BASE_URL") != NULL) {
return joinpath(getenv("R_BASE_URL"), "v1/chat/completions");

BIN
rpylib.so

Binary file not shown.

32
tools.h
View File

@ -11,6 +11,8 @@
#ifndef R_TOOLS_H
#define R_TOOLS_H
#include "http_curl.h"
#include "r.h"
#include "utils.h"
@ -117,7 +119,7 @@ struct json_object *tool_description_web_search_news() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -171,7 +173,7 @@ struct json_object *tool_description_web_search() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -222,7 +224,7 @@ struct json_object *tool_description_db_get() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -272,7 +274,7 @@ struct json_object *tool_description_db_query() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -329,7 +331,7 @@ struct json_object *tool_description_db_set() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -468,7 +470,7 @@ struct json_object *tool_description_chdir() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -508,7 +510,7 @@ struct json_object *tool_description_index_source_directory() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -551,7 +553,7 @@ struct json_object *tool_description_linux_terminal_interactive() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -594,7 +596,7 @@ struct json_object *tool_description_directory_rglob() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -633,7 +635,7 @@ struct json_object *tool_description_read_file() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -685,7 +687,7 @@ struct json_object *tool_description_write_file() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -970,7 +972,7 @@ struct json_object *tool_description_http_get() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -1012,7 +1014,7 @@ struct json_object *tool_description_directory_glob() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -1051,7 +1053,7 @@ struct json_object *tool_description_linux_terminal() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);
@ -1097,7 +1099,7 @@ struct json_object *tool_description_mkdir() {
json_object_new_boolean(0));
json_object_object_add(function, "parameters", parameters);
json_object_object_add(function, "strict", json_object_new_boolean(1));
json_object_object_add(function, "strict", json_object_new_boolean(get_use_strict()));
json_object_object_add(root, "function", function);