TaskWeaver icon indicating copy to clipboard operation
TaskWeaver copied to clipboard

How to set a plugin (dataset from backend)

Open AbhijitManepatil opened this issue 1 year ago • 1 comments
trafficstars

Instated of asking initially pull a data from 'time_series' table from 'sqlite://test.db' How can I set this (database) in backend when app loads then start directly asking questions.?

AbhijitManepatil avatar Jan 17 '24 12:01 AbhijitManepatil

We would suggest wrap around the taskweaver and automatically send a request (e.g., pull the data) to Taskweaver on behalf of human when starting the services.

ShilinHe avatar Jan 18 '24 09:01 ShilinHe

We would suggest wrap around the taskweaver and automatically send a request (e.g., pull the data) to Taskweaver on behalf of human when starting the services.

Can you please elaborate how to set this up in code? I want to work with one csv file that can be accessed from plugins and stays in memory in the session.

Haxeebraja avatar Jan 30 '24 14:01 Haxeebraja

CodeInterpreter File Handling

To enable CodeInterpreter to access data, I supplied the complete file path, and the file was successfully read and processed. It is important to emphasize that the file must be reachable by the user executing TaskWeave and must have the necessary read permissions.

Plugins in the Application

  1. sql_pull_data Plugin

    • Source Code
    • The path to the SQLite database is determined from an environment variable. sql_pull_data Plugin
  2. anomaly_detection Plugin

    • Source Code
    • The file is incorporated into the context. anomaly_detection Plugin

Creating a custom plugin might prove more convenient than exploring alternatives. Consider specifying the full file path for CodeInterpreter, as it could enhance control and compatibility.

xsa-dev avatar Feb 01 '24 23:02 xsa-dev

CodeInterpreter File Handling

To enable CodeInterpreter to access data, I supplied the complete file path, and the file was successfully read and processed. It is important to emphasize that the file must be reachable by the user executing TaskWeave and must have the necessary read permissions.

Plugins in the Application

  1. sql_pull_data Plugin

    • Source Code
    • The path to the SQLite database is determined from an environment variable. sql_pull_data Plugin
  2. anomaly_detection Plugin

    • Source Code
    • The file is incorporated into the context. anomaly_detection Plugin

Creating a custom plugin might prove more convenient than exploring alternatives. Consider specifying the full file path for CodeInterpreter, as it could enhance control and compatibility.

Thanks for the response, looks more promising.

AbhijitManepatil avatar Feb 02 '24 10:02 AbhijitManepatil

I have one Query here,

I have a SQL Db sitting on the Cloud and i am using similar Function to connect to it db = SQLDatabase.from_uri("SQL PATH")

I am Seeing this observation that when the CI calls the Plugin , it takes time to make connection every time.

I dont want to make connection every time i want to reuse the Connection so that i can reduce latency and not needing to connect to the DB every time the plugin gets called

Can some one suggest a solution where DB object is only instanciated once and Reused again in the plugins. Hence Reducing Latency

NisaarAgharia avatar Feb 06 '24 07:02 NisaarAgharia

I have one Query here,

I have a SQL Db sitting on the Cloud and i am using similar Function to connect to it db = SQLDatabase.from_uri("SQL PATH")

I am Seeing this observation that when the CI calls the Plugin , it takes time to make connection every time.

I dont want to make connection every time i want to reuse the Connection so that i can reduce latency and not needing to connect to the DB every time the plugin gets called

Can some one suggest a solution where DB object is only instanciated once and Reused again in the plugins. Hence Reducing Latency

A simple way to achieve this is as follows:

@register_plugin
class SqlPullData(Plugin):
    db = None
    def __call__(self, query: str):
        ...
        if db is None:
            db = SQLDatabase.from_uri(self.config.get("sqlite_db_path"))

The connection will be created at the first time calling this plugin and reused in following calls.

Will revise the implementation later.

liqul avatar Feb 06 '24 07:02 liqul

Thanks @liqul , One more question : Lets say i initialize it once and use it again, what if the connection is broken or it is stale.

what would be a best way to implement above logic while also handling scenarios where connection would be stale or lost?

NisaarAgharia avatar Feb 06 '24 10:02 NisaarAgharia

This may be a bit going beyond developing the plugin. It is a common issue for all db access scenarios. I didn't investigate it and you can take a look at langchain's implementation details here.

liqul avatar Feb 06 '24 10:02 liqul