Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor tweaks to retrieval skill and file ingestion #9093

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions mindsdb/integrations/handlers/file_handler/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
tmichaeldb marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
10 changes: 4 additions & 6 deletions mindsdb/integrations/handlers/langchain_handler/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mindsdb/interfaces/skills/skill_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down