Update.
This commit is contained in:
		
							parent
							
								
									13d50fcd13
								
							
						
					
					
						commit
						1ff0e9ed97
					
				
							
								
								
									
										59
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								main.c
									
									
									
									
									
								
							| @ -29,6 +29,46 @@ static void repl(void); | ||||
| static void init(void); | ||||
| static void handle_sigint(int sig); | ||||
| 
 | ||||
| char * get_env_string(){ | ||||
|     FILE *fp = popen("env", "r"); | ||||
|     if (fp == NULL) { | ||||
|         perror("popen failed"); | ||||
|         return NULL; | ||||
|     } | ||||
| 
 | ||||
|     size_t buffer_size = 1024; | ||||
|     size_t total_size = 0; | ||||
|     char *output = malloc(buffer_size); | ||||
|     if (output == NULL) { | ||||
|         perror("malloc failed"); | ||||
|         pclose(fp); | ||||
|         return NULL; | ||||
|     } | ||||
| 
 | ||||
|     size_t bytes_read; | ||||
|     while ((bytes_read = fread(output + total_size, 1, buffer_size - total_size, fp)) > 0) { | ||||
|         total_size += bytes_read; | ||||
|         if (total_size >= buffer_size) { | ||||
|             buffer_size *= 2; | ||||
|             char *temp = realloc(output, buffer_size); | ||||
|             if (temp == NULL) { | ||||
|                 perror("realloc failed"); | ||||
|                 free(output); | ||||
|                 pclose(fp); | ||||
|                 return NULL; | ||||
|             } | ||||
|             output = temp; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // Null-terminate the output
 | ||||
|     output[total_size] = '\0'; | ||||
| 
 | ||||
| 
 | ||||
|     pclose(fp); | ||||
|     return output; | ||||
| } | ||||
| 
 | ||||
| static char *get_prompt_from_stdin(char *prompt) { | ||||
|     int index = 0; | ||||
|     int c; | ||||
| @ -194,14 +234,20 @@ static void init(void) { | ||||
|     char *schema = db_get_schema(); | ||||
|     char payload[1024 * 1024] = {0}; | ||||
|     snprintf(payload, sizeof(payload), | ||||
|              "Your have a database that you can mutate using the query tool and " | ||||
|              "the get and set tool. This is the schema in json format: %s. " | ||||
|              "Dialect is sqlite.", | ||||
|             "# LOCAL DATABASE"  | ||||
|             "Your have a local database that you can mutate using the query tool and " | ||||
|              "the get and set tool." | ||||
|              "If you set a value using the tool, make sure that the key is stemmed and lowercased to prevent double entries." | ||||
|              "Dialect is sqlite. This is the schema in json format: %s. ", | ||||
|              schema); | ||||
|     free(schema); | ||||
| 
 | ||||
|     fprintf(stderr, "Loading... 📨"); | ||||
|     openai_system(payload); | ||||
|     char * env_system_message = get_env_system_message(); | ||||
|     if(env_system_message && *env_system_message){ | ||||
|         openai_system(env_system_message); | ||||
|         free(env_system_message); | ||||
|     } | ||||
|     if (!openai_include(".rcontext.txt")) { | ||||
|         openai_include("~/.rcontext.txt"); | ||||
|     } | ||||
| @ -228,6 +274,11 @@ int main(int argc, char *argv[]) { | ||||
|     signal(SIGINT, handle_sigint); | ||||
| 
 | ||||
|     init(); | ||||
|     char * env_string = get_env_string(); | ||||
|     if(env_string && *env_string){ | ||||
|         openai_system(env_string); | ||||
|         free(env_string); | ||||
|     } | ||||
|     if (try_prompt(argc, argv)) | ||||
|         return 0; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										7
									
								
								r.h
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								r.h
									
									
									
									
									
								
							| @ -32,6 +32,13 @@ char *_model = NULL; | ||||
| #define DB_FILE "~/.r.db" | ||||
| #define PROMPT_TEMPERATURE 0.1 | ||||
| 
 | ||||
| char * get_env_system_message(){ | ||||
|     if (getenv("R_SYSTEM_MESSAGE") != NULL) { | ||||
|         return strdup(getenv("R_SYSTEM_MESSAGE")); | ||||
|     } | ||||
|     return NULL; | ||||
| } | ||||
| 
 | ||||
| bool get_use_strict() { | ||||
|   if (getenv("R_USE_STRICT") != NULL) { | ||||
|     const char *value = getenv("R_USE_STRICT"); | ||||
|  | ||||
							
								
								
									
										3
									
								
								tools.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								tools.h
									
									
									
									
									
								
							| @ -66,7 +66,7 @@ struct json_object *tools_descriptions() { | ||||
|   json_object_array_add(root, tool_description_directory_glob()); | ||||
|   json_object_array_add(root, tool_description_read_file()); | ||||
|   json_object_array_add(root, tool_description_write_file()); | ||||
|   json_object_array_add(root, tool_description_directory_rglob()); | ||||
|   //json_object_array_add(root, tool_description_directory_rglob());
 | ||||
|   json_object_array_add(root, tool_description_linux_terminal_interactive()); | ||||
|   json_object_array_add(root, tool_description_index_source_directory()); | ||||
|   json_object_array_add(root, tool_description_chdir()); | ||||
| @ -672,6 +672,7 @@ struct json_object *tool_description_linux_terminal_interactive() { | ||||
| } | ||||
| 
 | ||||
| struct json_object *tool_description_directory_rglob() { | ||||
|      | ||||
|   struct json_object *root = json_object_new_object(); | ||||
|   json_object_object_add(root, "type", json_object_new_string("function")); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user