langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
31.35k stars 3.89k forks source link

Fine tuning #3080

Closed gamercoder153 closed 2 months ago

gamercoder153 commented 2 months ago

How do I use the finetuning from csv feature mentioned on the website https://www.langflow.org/

dosubot[bot] commented 2 months ago

To use the fine-tuning from CSV feature mentioned on the Langflow website, you can utilize the CSVAgentComponent class provided in the CSVAgent.py file. Here is how you can do it:

  1. Define the Configuration: The build_config method specifies the configuration needed, including the language model (llm), the path to the CSV file (path), handling parsing errors (handle_parsing_errors), and the agent type (agent_type).

  2. Instantiate the Agent: Use the build method to create an instance of the CSV agent by providing the language model, the path to the CSV file, and optional parameters for handling parsing errors and agent type.

Here is an example of how you can use it in your code:

from langflow.custom import CustomComponent
from langflow.field_typing import LanguageModel, AgentExecutor
from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent

class CSVAgentComponent(CustomComponent):
    display_name = "CSVAgent"
    description = "Construct a CSV agent from a CSV and tools."
    documentation = "https://python.langchain.com/docs/modules/agents/toolkits/csv"

    def build_config(self):
        return {
            "llm": {"display_name": "LLM", "type": LanguageModel},
            "path": {"display_name": "Path", "field_type": "file", "suffixes": [".csv"], "file_types": [".csv"]},
            "handle_parsing_errors": {"display_name": "Handle Parse Errors", "advanced": True},
            "agent_type": {
                "display_name": "Agent Type",
                "options": ["zero-shot-react-description", "openai-functions", "openai-tools"],
                "advanced": True,
            },
        }

    def build(
        self, llm: LanguageModel, path: str, handle_parsing_errors: bool = True, agent_type: str = "openai-tools"
    ) -> AgentExecutor:
        # Instantiate and return the CSV agent class with the provided llm and path
        return create_csv_agent(
            llm=llm,
            path=path,
            agent_type=agent_type,
            verbose=True,
            agent_executor_kwargs=dict(handle_parsing_errors=handle_parsing_errors),
        )

# Example usage
llm = YourLanguageModel()  # Replace with your language model instance
csv_path = "path/to/your/file.csv"  # Replace with the path to your CSV file

csv_agent_component = CSVAgentComponent()
agent_executor = csv_agent_component.build(llm=llm, path=csv_path)

Replace YourLanguageModel with the actual language model you are using and path/to/your/file.csv with the path to your CSV file. This will create and return an instance of the CSV agent that you can use for fine-tuning. You can also customize the handle_parsing_errors and agent_type parameters as needed [1][2].

To continue talking to Dosu, mention @dosu.

gamercoder153 commented 2 months ago

@dosu it giving out this error when I build it :

Error Building Component Error building Component CSVAgent: This agent relies on access to a python repl tool which can execute arbitrary code. This can be dangerous and requires a specially sandboxed environment to be safely used. Please read the security notice in the doc-string of this function. You must o

dosubot[bot] commented 2 months ago

The error you're encountering indicates that the CSVAgent relies on a Python REPL tool that can execute arbitrary code, which poses security risks. To mitigate these risks, you need to ensure that the environment where the agent is executed is properly sandboxed and secure.

Here are some steps you can take to address this issue:

  1. Sandboxing: Run the agent in a sandboxed environment to isolate it from the rest of your system. This can be achieved using containerization tools like Docker or virtual machines.

  2. Access Control: Limit the permissions and access rights of the environment where the agent runs. Ensure that it has only the necessary permissions to read the CSV file and execute the required code.

  3. Input Validation: Validate and sanitize all inputs, especially the path parameter, to prevent any potential injection attacks.

  4. Monitoring and Logging: Implement monitoring and logging to track the agent's activities and detect any suspicious behavior.

  5. Review Documentation: Refer to the official documentation for any additional security measures or recommendations. The documentation for the CSVAgentComponent class can be found here.

By following these steps, you can create a safer environment for running the CSVAgent and mitigate the associated security risks.

To continue talking to Dosu, mention @dosu.

gamercoder153 commented 2 months ago

@dosu can u assign this issue to anyone?

dosubot[bot] commented 2 months ago

This is a tough nut to crack, could really use your help on this, @ogabrielluiz.

To continue talking to Dosu, mention @dosu.

carlosrcoelho commented 2 months ago

@gamercoder153

A user made this custom component a while back, but it was discontinued after updates and new versions.