Does dolphin-mixtral just not work with Crew or am I not prompting right?
Searching I do not see much and what I find appears that others are also struggling with issues, etc.
My outputs when reading in files are the LLM trying to follow instructions in them instead of following the prompts, ignores part of the instructions for example.
In this case it ignored the part of the instructions “If there are tags in the document already ignore them.”
from crewai import Agent, Task, Crew
from langchain_community.llms import Ollama
from crewai_tools import FileReadTool
from pathlib import Path
import os
os.environ["OPENAI_API_KEY"] = "NA"
# LLM setup
llm = Ollama(
model="dolphin-mixtral:8x7b",
base_url="http://localhost:11434"
)
# File path
file_path = "mysqldump by tables.md"
# Read the file contents
file_contents = FileReadTool(file_path)
# Agent definition
file_processor_agent = Agent(
role="File Tagger",
goal="Process file contents and generate relevant tags that capture key technologies, languages, and core functions.",
backstory="You are an expert file analyzer specializing in identifying core technologies and functionalities within markdown files. You excel at distilling complex content into concise, meaningful tags.",
allow_delegation=False,
verbose=True,
llm=llm
)
# Task definition with output format guidance
file_processing_task = Task(
description="""
Analyze the provided file content and generate 5 tags that best represent its key elements.
Focus on:
Primary programming languages used
Key technologies or libraries involved
Main functionalities or operations performed
If there are tags in the document already ignore them.
Your output should be in this format: [ #tag1, #tag2, #tag3, #camelCaseTag4, #camelCaseTag5 ]
""",
agent=file_processor_agent,
expected_output="5 camel case tags separated by commas only with the template [ #tag1, #tag2, #tag3 ]",
tools=[file_contents]
)
# Function to read the contents of a file
def read_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
# Crew setup and execution
crew = Crew(
agents=[file_processor_agent],
tasks=[file_processing_task],
verbose=True
)
# Kick off the process by passing the file contents as input
print("The file contents are:")
print(read_file(file_path))
print("\n\n")
result = crew.kickoff()
print(result)
The file contents are:
Dump mysql database one table at a time use this script below, there are two versions one with pymysql and one without.
With pymysql
```python
import argparse
import subprocess
import pymysql
import getpass
def get_db_tables(host, user, password, database):
connection = pymysql.connect(host=host, user=user, password=password, db=database)
try:
with connection.cursor() as cursor:
cursor.execute("SHOW TABLES;")
return [table[0] for table in cursor.fetchall()]
finally:
connection.close()
def main():
parser = argparse.ArgumentParser(description="Export tables from a MySQL database.")
parser.add_argument('-u', '--user', required=True, help="Username for the MySQL database")
parser.add_argument('-p', '--password', help="Password for the MySQL database")
parser.add_argument('-d', '--database', required=True, help="Name of the database")
parser.add_argument('-H', '--host', required=True, help="Host of the MySQL server")
args = parser.parse_args()
# Prompt for password if not provided
if args.password is None:
args.password = getpass.getpass(prompt="Enter MySQL password: ")
tables = get_db_tables(args.host, args.user, args.password, args.database)
# Loop through each table and dump it
for table in tables:
print(f"Exporting table: {table}")
# Ensuring the password isn't visible in the process list
dump_command = f"mysqldump -h {args.host} -u {args.user} --single-transaction {args.database} {table}"
subprocess.run(['echo', args.password, '|', dump_command], shell=True)
if __name__ == "__main__":
main()
```
Without pymysql
```python
import argparse
import subprocess
import getpass
def get_db_tables(host, user, password, database):
# Constructing the MySQL command
mysql_command = f"mysql -h {host} -u {user} -p{password} -e 'SHOW TABLES IN {database}'"
try:
# Running the MySQL command
output = subprocess.check_output(mysql_command, shell=True, text=True)
# Parsing the output to get the table names
return [line.strip() for line in output.splitlines() if line.strip() and not line.startswith('Tables_in')]
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e}")
return []
def main():
parser = argparse.ArgumentParser(description="Export tables from a MySQL database.")
parser.add_argument('-u', '--user', required=True, help="Username for the MySQL database")
parser.add_argument('-p', '--password', help="Password for the MySQL database")
parser.add_argument('-d', '--database', required=True, help="Name of the database")
parser.add_argument('-H', '--host', required=True, help="Host of the MySQL server")
args = parser.parse_args()
# Prompt for password if not provided
if args.password is None:
args.password = getpass.getpass(prompt="Enter MySQL password: ")
tables = get_db_tables(args.host, args.user, args.password, args.database)
# Loop through each table and dump it
for table in tables:
print(f"Exporting table: {table}")
dump_command = f"mysqldump -h {args.host} -u {args.user} -p{args.password} --single-transaction {args.database} {table} > {table}.sql"
subprocess.run(dump_command, shell=True)
if __name__ == "__main__":
main()
```
Tags
#mysql #python #pymysql #python3
Example output while debuging:
[2024-09-18 22:26:17][DEBUG]: == Working Agent: File Tagger
[2024-09-18 22:26:17][INFO]: == Starting Task:
Analyze the provided file content and generate 5 tags that best represent its key elements.
Focus on:
Primary programming languages used
Key technologies or libraries involved
Main functionalities or operations performed
If there are tags in the document already ignore them.
Your output should be in this format: [ #tag1, #tag2, #tag3, #camelCaseTag4, #camelCaseTag5 ]
> Entering new CrewAgentExecutor chain...
I should read the file's content first.
Action: Read a file's content
Action Input: {"file_path": "tables.md"}
Dump mysql database one table at a time use this script below, there are two versions one with pymysql and one without.
With pymysql
```python
import argparse
import subprocess
import pymysql
import getpass
def get_db_tables(host, user, password, database):
connection = pymysql.connect(host=host, user=user, password=password, db=database)
try:
with connection.cursor() as cursor:
cursor.execute("SHOW TABLES;")
return [table[0] for table in cursor.fetchall()]
finally:
connection.close()
def main():
parser = argparse.ArgumentParser(description="Export tables from a MySQL database.")
parser.add_argument('-u', '--user', required=True, help="Username for the MySQL database")
parser.add_argument('-p', '--password', help="Password for the MySQL database")
parser.add_argument('-d', '--database', required=True, help="Name of the database")
parser.add_argument('-H', '--host', required=True, help="Host of the MySQL server")
args = parser.parse_args()
# Prompt for password if not provided
if args.password is None:
args.password = getpass.getpass(prompt="Enter MySQL password: ")
tables = get_db_tables(args.host, args.user, args.password, args.database)
# Loop through each table and dump it
for table in tables:
print(f"Exporting table: {table}")
# Ensuring the password isn't visible in the process list
dump_command = f"mysqldump -h {args.host} -u {args.user} --single-transaction {args.database} {table}"
subprocess.run(['echo', args.password, '|', dump_command], shell=True)
if __name__ == "__main__":
main()
```
Without pymysql
```python
import argparse
import subprocess
import getpass
def get_db_tables(host, user, password, database):
# Constructing the MySQL command
mysql_command = f"mysql -h {host} -u {user} -p{password} -e 'SHOW TABLES IN {database}'"
try:
# Running the MySQL command
output = subprocess.check_output(mysql_command, shell=True, text=True)
# Parsing the output to get the table names
return [line.strip() for line in output.splitlines() if line.strip() and not line.startswith('Tables_in')]
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e}")
return []
def main():
parser = argparse.ArgumentParser(description="Export tables from a MySQL database.")
parser.add_argument('-u', '--user', required=True, help="Username for the MySQL database")
parser.add_argument('-p', '--password', help="Password for the MySQL database")
parser.add_argument('-d', '--database', required=True, help="Name of the database")
parser.add_argument('-H', '--host', required=True, help="Host of the MySQL server")
args = parser.parse_args()
# Prompt for password if not provided
if args.password is None:
args.password = getpass.getpass(prompt="Enter MySQL password: ")
tables = get_db_tables(args.host, args.user, args.password, args.database)
# Loop through each table and dump it
for table in tables:
print(f"Exporting table: {table}")
dump_command = f"mysqldump -h {args.host} -u {args.user} -p{args.password} --single-transaction {args.database} {table} > {table}.sql"
subprocess.run(dump_command, shell=True)
if __name__ == "__main__":
main()
```
Tags
#mysql #python #pymysql #python3
Final Answer: [ #mysql, #python, #pymysql, #python3 ]
> Finished chain.
[2024-09-18 22:26:24][DEBUG]: == [File Tagger] Task output: [ #mysql, #python, #pymysql, #python3 ]
[ #mysql, #python, #pymysql, #python3 ]