Implemented strict mode.
This commit is contained in:
		
							parent
							
								
									d2f57931a1
								
							
						
					
					
						commit
						01c941e29d
					
				
							
								
								
									
										19
									
								
								messages.h
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								messages.h
									
									
									
									
									
								
							| @ -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
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								r.h
									
									
									
									
									
								
							| @ -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"); | ||||
|  | ||||
							
								
								
									
										32
									
								
								tools.h
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								tools.h
									
									
									
									
									
								
							| @ -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); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user