diff --git a/lollms/app.py b/lollms/app.py index 3f8ae0e..3f5841b 100644 --- a/lollms/app.py +++ b/lollms/app.py @@ -1360,29 +1360,31 @@ Answer directly with the reformulation of the last prompt. for fc in self.config.mounted_function_calls: if fc["selected"]: dr = Path(fc["dir"]) - with open(dr/"config.yaml", "r") as f: - fc_dict = yaml.safe_load(f.read()) - # Step 1: Construct the full path to the function.py module - module_path = dr / "function.py" - module_name = "function" # Name for the loaded module + try: + with open(dr/"config.yaml", "r") as f: + fc_dict = yaml.safe_load(f.read()) + # Step 1: Construct the full path to the function.py module + module_path = dr / "function.py" + module_name = "function" # Name for the loaded module - # Step 2: Use importlib.util to load the module from the file path - spec = importlib.util.spec_from_file_location(module_name, module_path) - if spec is None: - raise ImportError(f"Could not load module from {module_path}") - - module = importlib.util.module_from_spec(spec) - sys.modules[module_name] = module # Add the module to sys.modules - spec.loader.exec_module(module) # Execute the module - - # Step 3: Retrieve the class from the module using the class name - class_name = fc_dict["class_name"] - class_ = getattr(module, class_name) - - # Step 4: Create an instance of the class and store it in fc_dict["class"] - fc_dict["class"] = class_(self, client) - function_calls.append(fc_dict) + # Step 2: Use importlib.util to load the module from the file path + spec = importlib.util.spec_from_file_location(module_name, module_path) + if spec is None: + raise ImportError(f"Could not load module from {module_path}") + + module = importlib.util.module_from_spec(spec) + sys.modules[module_name] = module # Add the module to sys.modules + spec.loader.exec_module(module) # Execute the module + # Step 3: Retrieve the class from the module using the class name + class_name = fc_dict["class_name"] + class_ = getattr(module, class_name) + + # Step 4: Create an instance of the class and store it in fc_dict["class"] + fc_dict["class"] = class_(self, client) + function_calls.append(fc_dict) + except Exception as ex: + trace_exception(ex) # Calculate the total number of tokens between conditionning, documentation, and knowledge total_tokens = n_cond_tk + n_isearch_tk + n_doc_tk + n_user_description_tk + n_positive_boost + n_negative_boost + n_fun_mode + n_think_first_mode diff --git a/lollms/function_call.py b/lollms/function_call.py index c18fff2..64cd5c4 100644 --- a/lollms/function_call.py +++ b/lollms/function_call.py @@ -33,6 +33,10 @@ class FunctionCall: raise NotImplementedError("Subclasses must implement the update_context method for AI_FIRST_CALL functions.") elif self.function_type == FunctionType.POST_GENERATION: raise NotImplementedError("Subclasses must implement the update_context method for POST_GENERATION functions.") + + def process_output(self, context, llm_output:str): + if self.function_type == FunctionType.CONTEXT_UPDATE: + raise NotImplementedError("Subclasses must implement the process_output for CONTEXT_UPDATE functions.") diff --git a/lollms/server/endpoints/lollms_function_calls.py b/lollms/server/endpoints/lollms_function_calls.py index 44c696f..1293838 100644 --- a/lollms/server/endpoints/lollms_function_calls.py +++ b/lollms/server/endpoints/lollms_function_calls.py @@ -139,9 +139,6 @@ async def mount_function_call(request: Request): # Check if already mounted for fc in lollmsElfServer.config.mounted_function_calls: if fc["name"] == function_name: - if fc["mounted"]: - return {"status": False, "message": "Function already mounted"} - fc["mounted"] = True lollmsElfServer.config.save_config() return {"status": True, "message": "Function mounted"} @@ -190,10 +187,6 @@ async def toggle_function_call(request: Request): function_name = data.get("name") if not check_access(lollmsElfServer, client_id): raise HTTPException(status_code=403, detail="Access denied") - p_dir = Path(fn_dir) - if not p_dir.exists() or not (p_dir / "config.yaml").exists() or not (p_dir / "function.py").exists(): - raise HTTPException(status_code=404, detail="Function not found") - # Add new entry for entry in lollmsElfServer.config.mounted_function_calls: