From 92528af60031d6895f5e5ba2174c67b89c8ff3e5 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 22 Jan 2025 19:14:40 +0000 Subject: [PATCH 01/10] Update README.md --- README.md | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f2699fe6..3627c77c 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,11 @@

- Open-Source Documentation Assistant + Open-Source RAG Assistant

- DocsGPT is a cutting-edge open-source solution that streamlines the process of finding information in the project documentation. With its integration of the powerful GPT models, developers can easily ask questions about a project and receive accurate answers. - -Say goodbye to time-consuming manual searches, and let DocsGPT help you quickly find the information you need. Try it out and see how it revolutionizes your project documentation experience. Contribute to its development and be a part of the future of AI-powered assistance. + DocsGPT is an open-source genAI tool that helps users get reliable answers from any knowledge source, while avoiding hallucinations. It enables quick and reliable information retrieval, with tooling and agentic system capability built in.

@@ -19,25 +17,37 @@ Say goodbye to time-consuming manual searches, and let ![link to license file](https://img.shields.io/github/license/arc53/docsgpt) ![link to discord](https://img.shields.io/discord/1070046503302877216) ![X (formerly Twitter) URL](https://img.shields.io/twitter/follow/docsgptai) -
+video-example-of-docs-gpt + +

+ Key Features: +

+ + +## Roadmap + +You can find our roadmap [here](https://github.com/orgs/arc53/projects/2). Please don't hesitate to contribute or create issues, it helps us improve DocsGPT! + ### Production Support / Help for Companies: We're eager to provide personalized assistance when deploying your DocsGPT to a live environment. -[Book a Meeting :wave:](https://cal.com/arc53/docsgpt-demo-b2b)⁠ +[Get a Demo :wave:](https://www.docsgpt.cloud/contact)⁠ -[Send Email :email:](mailto:contact@arc53.com?subject=DocsGPT%20support%2Fsolutions) +[Send Email :email:](mailto:support@docsgpt.cloud?subject=DocsGPT%20support%2Fsolutions) -video-example-of-docs-gpt - -## Roadmap - -You can find our roadmap [here](https://github.com/orgs/arc53/projects/2). Please don't hesitate to contribute or create issues, it helps us improve DocsGPT! - ## Our Open-Source Models Optimized for DocsGPT: | Name | Base Model | Requirements (or similar) | From 5a38c09f8dce65feb6e97f1c20ecdd71223146d7 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 24 Jan 2025 15:06:16 +0000 Subject: [PATCH 02/10] feat: postgres tool --- application/requirements.txt | 1 + application/tools/implementations/postgres.py | 163 ++++++++++++++++++ frontend/public/toolIcons/tool_postgres.svg | 29 ++++ 3 files changed, 193 insertions(+) create mode 100644 application/tools/implementations/postgres.py create mode 100644 frontend/public/toolIcons/tool_postgres.svg diff --git a/application/requirements.txt b/application/requirements.txt index c193f38d..8029f9fb 100644 --- a/application/requirements.txt +++ b/application/requirements.txt @@ -60,6 +60,7 @@ prance==23.6.21.0 primp==0.10.0 prompt-toolkit==3.0.48 protobuf==5.29.3 +psycopg2-binary==2.9.10 py==1.11.0 pydantic==2.10.4 pydantic-core==2.27.2 diff --git a/application/tools/implementations/postgres.py b/application/tools/implementations/postgres.py new file mode 100644 index 00000000..a83db9aa --- /dev/null +++ b/application/tools/implementations/postgres.py @@ -0,0 +1,163 @@ +import psycopg2 +from application.tools.base import Tool + +class PostgresTool(Tool): + """ + PostgreSQL Database Tool + A tool for connecting to a PostgreSQL database using a connection string, + executing SQL queries, and retrieving schema information. + """ + + def __init__(self, config): + self.config = config + self.connection_string = config.get("token", "") + + def execute_action(self, action_name, **kwargs): + actions = { + "postgres_execute_sql": self._execute_sql, + "postgres_get_schema": self._get_schema, + } + + if action_name in actions: + return actions[action_name](**kwargs) + else: + raise ValueError(f"Unknown action: {action_name}") + + def _execute_sql(self, sql_query): + """ + Executes an SQL query against the PostgreSQL database using a connection string. + """ + conn = None # Initialize conn to None for error handling + try: + conn = psycopg2.connect(self.connection_string) + cur = conn.cursor() + cur.execute(sql_query) + conn.commit() + + if sql_query.strip().lower().startswith("select"): + column_names = [desc[0] for desc in cur.description] if cur.description else [] + results = [] + rows = cur.fetchall() + for row in rows: + results.append(dict(zip(column_names, row))) + response_data = {"data": results, "column_names": column_names} + else: + row_count = cur.rowcount + response_data = {"message": f"Query executed successfully, {row_count} rows affected."} + + cur.close() + return { + "status_code": 200, + "message": "SQL query executed successfully.", + "response_data": response_data, + } + + except psycopg2.Error as e: + error_message = f"Database error: {e}" + print(f"Database error: {e}") + return { + "status_code": 500, + "message": "Failed to execute SQL query.", + "error": error_message, + } + finally: + if conn: # Ensure connection is closed even if errors occur + conn.close() + + def _get_schema(self, db_name): + """ + Retrieves the schema of the PostgreSQL database using a connection string. + """ + conn = None # Initialize conn to None for error handling + try: + conn = psycopg2.connect(self.connection_string) + cur = conn.cursor() + + cur.execute(""" + SELECT + table_name, + column_name, + data_type, + column_default, + is_nullable + FROM + information_schema.columns + WHERE + table_schema = 'public' + ORDER BY + table_name, + ordinal_position; + """) + + schema_data = {} + for row in cur.fetchall(): + table_name, column_name, data_type, column_default, is_nullable = row + if table_name not in schema_data: + schema_data[table_name] = [] + schema_data[table_name].append({ + "column_name": column_name, + "data_type": data_type, + "column_default": column_default, + "is_nullable": is_nullable + }) + + cur.close() + return { + "status_code": 200, + "message": "Database schema retrieved successfully.", + "schema": schema_data, + } + + except psycopg2.Error as e: + error_message = f"Database error: {e}" + print(f"Database error: {e}") + return { + "status_code": 500, + "message": "Failed to retrieve database schema.", + "error": error_message, + } + finally: + if conn: # Ensure connection is closed even if errors occur + conn.close() + + def get_actions_metadata(self): + return [ + { + "name": "postgres_execute_sql", + "description": "Execute an SQL query against the PostgreSQL database and return the results. Use this tool to interact with the database, e.g., retrieve specific data or perform updates. Only SELECT queries will return data, other queries will return execution status.", + "parameters": { + "type": "object", + "properties": { + "sql_query": { + "type": "string", + "description": "The SQL query to execute.", + }, + }, + "required": ["sql_query"], + "additionalProperties": False, + }, + }, + { + "name": "postgres_get_schema", + "description": "Retrieve the schema of the PostgreSQL database, including tables and their columns. Use this to understand the database structure before executing queries. db_name is 'default' if not provided.", + "parameters": { + "type": "object", + "properties": { + "db_name": { + "type": "string", + "description": "The name of the database to retrieve the schema for.", + }, + }, + "required": ["db_name"], + "additionalProperties": False, + }, + }, + ] + + def get_config_requirements(self): + return { + "token": { + "type": "string", + "description": "PostgreSQL database connection string (e.g., 'postgresql://user:password@host:port/dbname')", + }, + } \ No newline at end of file diff --git a/frontend/public/toolIcons/tool_postgres.svg b/frontend/public/toolIcons/tool_postgres.svg new file mode 100644 index 00000000..c7acdb18 --- /dev/null +++ b/frontend/public/toolIcons/tool_postgres.svg @@ -0,0 +1,29 @@ + + + + + + + Data + + + sql-database-generic + + + SQL Database (Generic) + + + image/svg+xml + + + Amido Limited + + + Richard Slater + + + + + + + \ No newline at end of file From 3e45a3b4d809d2e912b3b38f02580b12461bd33a Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 25 Jan 2025 14:39:38 +0000 Subject: [PATCH 03/10] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3627c77c..d83bfb9f 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ ![X (formerly Twitter) URL](https://img.shields.io/twitter/follow/docsgptai) - -video-example-of-docs-gpt - +
+video-example-of-docs-gpt +

Key Features:

From fff8cfdee0705d676f111980611e5c519538a0a9 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 25 Jan 2025 15:08:36 +0000 Subject: [PATCH 04/10] Update index.mdx --- docs/pages/index.mdx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index eedc2b09..3dcbb7d3 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -25,7 +25,10 @@ DocsGPT 🦖 is an innovative open-source tool designed to simplify the retrieva -homedemo + Try it yourself: [https://www.docsgpt.cloud/](https://www.docsgpt.cloud/) From e7b8d71010c4353fe2c18b48612f84564b396dee Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 25 Jan 2025 15:10:30 +0000 Subject: [PATCH 05/10] Update index.mdx --- docs/pages/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index 3dcbb7d3..423a0a01 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -25,7 +25,7 @@ DocsGPT 🦖 is an innovative open-source tool designed to simplify the retrieva -