diff --git a/mindsdb/integrations/handlers/file_handler/file_handler.py b/mindsdb/integrations/handlers/file_handler/file_handler.py index 29620871182..7fde864b932 100644 --- a/mindsdb/integrations/handlers/file_handler/file_handler.py +++ b/mindsdb/integrations/handlers/file_handler/file_handler.py @@ -26,8 +26,8 @@ logger = log.getLogger(__name__) -DEFAULT_CHUNK_SIZE = 200 -DEFAULT_CHUNK_OVERLAP = 50 +DEFAULT_CHUNK_SIZE = 500 +DEFAULT_CHUNK_OVERLAP = 250 def clean_cell(val): diff --git a/mindsdb/integrations/handlers/langchain_handler/langchain_handler.py b/mindsdb/integrations/handlers/langchain_handler/langchain_handler.py index 8f2c0dab030..4680b49f52b 100644 --- a/mindsdb/integrations/handlers/langchain_handler/langchain_handler.py +++ b/mindsdb/integrations/handlers/langchain_handler/langchain_handler.py @@ -212,12 +212,22 @@ def create_agent(self, df: pd.DataFrame, args: Dict=None, pred_args: Dict=None) # Set up embeddings model if needed. if args.get('mode') == 'retrieval': - # get args for embeddings model + embeddings_args = args.pop('embedding_model_args', {}) + + # no embedding model args provided, use same provider as llm + if not embeddings_args: + logger.warning("'embedding_model_args' not found in input params, " + "Trying to use the same provider used for llm. " + f"provider: {args['provider']}" + ) + + # get args for embeddings model + embeddings_args['class'] = args['provider'] + # create embeddings model pred_args['embeddings_model'] = self._create_embeddings_model(embeddings_args) pred_args['llm'] = llm - pred_args['mindsdb_path'] = self.engine_storage.folder_get tools = setup_tools(llm, model_kwargs, @@ -291,8 +301,13 @@ def run_agent(self, df: pd.DataFrame, agent: AgentExecutor, args: Dict, pred_arg def _invoke_agent_executor_with_prompt(agent_executor, prompt): if not prompt: return '' - - answer = agent_executor.invoke(prompt) + try: + answer = agent_executor.invoke(prompt) + except Exception as e: + answer = str(e) + if not answer.startswith("Could not parse LLM output: `"): + raise e + answer = {'output': answer.removeprefix("Could not parse LLM output: `").removesuffix("`")} if 'output' not in answer: # This should never happen unless Langchain changes invoke output format, but just in case. diff --git a/mindsdb/integrations/handlers/langchain_handler/tools.py b/mindsdb/integrations/handlers/langchain_handler/tools.py index 90757e41e4e..37bafd75d76 100644 --- a/mindsdb/integrations/handlers/langchain_handler/tools.py +++ b/mindsdb/integrations/handlers/langchain_handler/tools.py @@ -19,6 +19,9 @@ from mindsdb.integrations.utilities.rag.rag_pipeline_builder import RAG from mindsdb.integrations.utilities.rag.settings import RAGPipelineModel from mindsdb.interfaces.skills.skill_tool import skill_tool, SkillType +from mindsdb.utilities import log + +logger = log.getLogger(__name__) # Individual tools # Note: all tools are defined in a closure to pass required args (apart from LLM input) through it, as custom tools don't allow custom field assignment. # noqa @@ -165,17 +168,11 @@ def _build_retrieval_tool(tool: dict, pred_args: dict): tools_config = tool['config'] - mindsdb_path = pred_args['mindsdb_path'] - # we update the config with the pred_args to allow for custom config tools_config.update(pred_args) rag_params = _get_rag_params(tools_config) - if 'vector_store_config' not in rag_params: - - rag_params['vector_store_config'] = {'persist_directory': mindsdb_path('persisted_chroma')} - rag_config = RAGPipelineModel(**rag_params) # build retriever @@ -188,6 +185,7 @@ def _build_retrieval_tool(tool: dict, pred_args: dict): description=tool['description'] ) + def langchain_tool_from_skill(skill, pred_args): # Makes Langchain compatible tools from a skill tool = skill_tool.get_tool_from_skill(skill) diff --git a/mindsdb/interfaces/skills/skill_tool.py b/mindsdb/interfaces/skills/skill_tool.py index db621b286f3..f8d44a976de 100644 --- a/mindsdb/interfaces/skills/skill_tool.py +++ b/mindsdb/interfaces/skills/skill_tool.py @@ -84,7 +84,7 @@ def _make_retrieval_tools(self, skill: db.Skills) -> dict: params = skill.params return dict( name=params.get('name', skill.name), - config=params.get('retriever_config', {}), + config=params.get('config', {}), description=f'You must use this tool to get more context or information ' f'to answer a question about {params["description"]}. ' f'The input should be the exact question the user is asking.',