Skip to content

Commit

Permalink
Merge pull request #28 from csunny/dev
Browse files Browse the repository at this point in the history
add config
  • Loading branch information
csunny authored May 11, 2023
2 parents f42da6a + ca50c9f commit 3e9fba7
Show file tree
Hide file tree
Showing 17 changed files with 720 additions and 56 deletions.
72 changes: 72 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#*******************************************************************#
#** DB-GPT - GENERAL SETTINGS **#
#*******************************************************************#
## DISABLED_COMMAND_CATEGORIES - The list of categories of commands that are disabled. Each of the below are an option:
## pilot.commands.query_execute

## For example, to disable coding related features, uncomment the next line
# DISABLED_COMMAND_CATEGORIES=


#*******************************************************************#
#*** LLM PROVIDER ***#
#*******************************************************************#

# TEMPERATURE=0

#*******************************************************************#
#** LLM MODELS **#
#*******************************************************************#

## SMART_LLM_MODEL - Smart language model (Default: vicuna-13b)
## FAST_LLM_MODEL - Fast language model (Default: chatglm-6b)
# SMART_LLM_MODEL=vicuna-13b
# FAST_LLM_MODEL=chatglm-6b


### EMBEDDINGS
## EMBEDDING_MODEL - Model to use for creating embeddings
## EMBEDDING_TOKENIZER - Tokenizer to use for chunking large inputs
## EMBEDDING_TOKEN_LIMIT - Chunk size limit for large inputs
# EMBEDDING_MODEL=all-MiniLM-L6-v2
# EMBEDDING_TOKENIZER=all-MiniLM-L6-v2
# EMBEDDING_TOKEN_LIMIT=8191


#*******************************************************************#
#** DATABASE SETTINGS **#
#*******************************************************************#
DB_SETTINGS_MYSQL_USER=root
DB_SETTINGS_MYSQL_PASSWORD=password
DB_SETTINGS_MYSQL_HOST=localhost
DB_SETTINGS_MYSQL_PORT=3306


### MILVUS
## MILVUS_ADDR - Milvus remote address (e.g. localhost:19530)
## MILVUS_USERNAME - username for your Milvus database
## MILVUS_PASSWORD - password for your Milvus database
## MILVUS_SECURE - True to enable TLS. (Default: False)
## Setting MILVUS_ADDR to a `https://` URL will override this setting.
## MILVUS_COLLECTION - Milvus collection, change it if you want to start a new memory and retain the old memory.
# MILVUS_ADDR=localhost:19530
# MILVUS_USERNAME=
# MILVUS_PASSWORD=
# MILVUS_SECURE=
# MILVUS_COLLECTION=dbgpt

#*******************************************************************#
#** ALLOWLISTED PLUGINS **#
#*******************************************************************#

#ALLOWLISTED_PLUGINS - Sets the listed plugins that are allowed (Example: plugin1,plugin2,plugin3)
#DENYLISTED_PLUGINS - Sets the listed plugins that are not allowed (Example: plugin1,plugin2,plugin3)
ALLOWLISTED_PLUGINS=
DENYLISTED_PLUGINS=


#*******************************************************************#
#** CHAT PLUGIN SETTINGS **#
#*******************************************************************#
# CHAT_MESSAGES_ENABLED - Enable chat messages (Default: False)
# CHAT_MESSAGES_ENABLED=False
9 changes: 3 additions & 6 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ dependencies:
- python=3.9
- cudatoolkit
- pip
- pytorch=1.12.1
- pytorch-mutex=1.0=cuda
- torchaudio=0.12.1
- torchvision=0.13.1
- pip:
- pytorch
- accelerate==0.16.0
- aiohttp==3.8.4
- aiosignal==1.3.1
Expand Down Expand Up @@ -57,11 +55,10 @@ dependencies:
- sentence-transformers
- umap-learn
- notebook
- gradio==3.24.1
- gradio==3.23
- gradio-client==0.0.8
- wandb
- fschat=0.1.10
- llama-index=0.5.27
- llama-index==0.5.27
- pymysql
- unstructured==0.6.3
- pytesseract==0.3.10
19 changes: 19 additions & 0 deletions examples/gradio_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import gradio as gr

def change_tab():
return gr.Tabs.update(selected=1)

with gr.Blocks() as demo:
with gr.Tabs() as tabs:
with gr.TabItem("Train", id=0):
t = gr.Textbox()
with gr.TabItem("Inference", id=1):
i = gr.Image()

btn = gr.Button()
btn.click(change_tab, None, tabs)

demo.launch()
Empty file added pilot/commands/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions pilot/commands/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools
import importlib
import inspect
from typing import Any, Callable, Optional

class Command:
"""A class representing a command.
Attributes:
name (str): The name of the command.
description (str): A brief description of what the command does.
signature (str): The signature of the function that the command executes. Default to None.
"""

def __init__(self,
name: str,
description: str,
method: Callable[..., Any],
signature: str = "",
enabled: bool = True,
disabled_reason: Optional[str] = None,
) -> None:
self.name = name
self.description = description
self.method = method
self.signature = signature if signature else str(inspect.signature(self.method))
self.enabled = enabled
self.disabled_reason = disabled_reason

def __call__(self, *args: Any, **kwds: Any) -> Any:
if not self.enabled:
return f"Command '{self.name}' is disabled: {self.disabled_reason}"
return self.method(*args, **kwds)
52 changes: 50 additions & 2 deletions pilot/configs/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
from typing import List
from auto_gpt_plugin_template import AutoGPTPluginTemplate
from pilot.singleton import Singleton

class Config(metaclass=Singleton):
"""Configuration class to store the state of bools for different scripts access"""
def __init__(self) -> None:
"""Initialize the Config class"""
pass

# TODO change model_config there

# TODO change model_config there
self.debug_mode = False
self.skip_reprompt = False

self.plugins_dir = os.getenv("PLUGINS_DIR", "plugins")
self.plugins = List[AutoGPTPluginTemplate] = []
self.temperature = float(os.getenv("TEMPERATURE", 0.7))


# User agent header to use when making HTTP requests
# Some websites might just completely deny request with an error code if
# no user agent was found.
self.user_agent = os.getenv(
"USER_AGENT",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36"
" (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
)

# milvus or zilliz cloud configuration
self.milvus_addr = os.getenv("MILVUS_ADDR", "localhost:19530")
self.milvus_username = os.getenv("MILVUS_USERNAME")
self.milvus_password = os.getenv("MILVUS_PASSWORD")
self.milvus_collection = os.getenv("MILVUS_COLLECTION", "dbgpt")
self.milvus_secure = os.getenv("MILVUS_SECURE") == "True"

plugins_allowlist = os.getenv("ALLOWLISTED_PLUGINS")
if plugins_allowlist:
self.plugins_allowlist = plugins_allowlist.split(",")
else:
self.plugins_allowlist = []

plugins_denylist = os.getenv("DENYLISTED_PLUGINS")
if plugins_denylist:
self.plugins_denylist = []

def set_debug_mode(self, value: bool) -> None:
"""Set the debug mode value"""
self.debug_mode = value

def set_plugins(self, value: list) -> None:
"""Set the plugins value. """
self.plugins = value

def set_templature(self, value: int) -> None:
"""Set the temperature value."""
self.temperature = value


8 changes: 4 additions & 4 deletions pilot/configs/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import nltk


ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
MODEL_PATH = os.path.join(ROOT_PATH, "models")
PILOT_PATH = os.path.join(ROOT_PATH, "pilot")
Expand All @@ -26,9 +27,8 @@
VECTOR_SEARCH_TOP_K = 3
LLM_MODEL = "vicuna-13b"
LIMIT_MODEL_CONCURRENCY = 5
MAX_POSITION_EMBEDDINGS = 2048
VICUNA_MODEL_SERVER = "http://192.168.31.114:8000"

MAX_POSITION_EMBEDDINGS = 4096
VICUNA_MODEL_SERVER = "http://47.97.125.199:8000"

# Load model config
ISLOAD_8BIT = True
Expand All @@ -37,7 +37,7 @@

DB_SETTINGS = {
"user": "root",
"password": "aa123456",
"password": "aa12345678",
"host": "localhost",
"port": 3306
}
101 changes: 98 additions & 3 deletions pilot/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class SeparatorStyle(Enum):

SINGLE = auto()
TWO = auto()
THREE = auto()
FOUR = auto()

@dataclasses.dataclass
class Conversation:
Expand Down Expand Up @@ -146,10 +148,103 @@ def gen_sqlgen_conversation(dbname):
sep2="</s>",
)

auto_dbgpt_one_shot = Conversation(
system="You are DB-GPT, an AI designed to answer questions about HackerNews by query `hackerbews` database in MySQL. "
"Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.",
roles=("USER", "ASSISTANT"),
messages=(
(
"USER",
""" Answer how many users does hackernews have by query mysql database
Constraints:
1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.
2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.
3. No user assistance
4. Exclusively use the commands listed in double quotes e.g. "command name"
Commands:
1. analyze_code: Analyze Code, args: "code": "<full_code_string>"
2. execute_python_file: Execute Python File, args: "filename": "<filename>"
3. append_to_file: Append to file, args: "filename": "<filename>", "text": "<text>"
4. delete_file: Delete file, args: "filename": "<filename>"
5. list_files: List Files in Directory, args: "directory": "<directory>"
6. read_file: Read file, args: "filename": "<filename>"
7. write_to_file: Write to file, args: "filename": "<filename>", "text": "<text>"
8. tidb_sql_executor: "Execute SQL in TiDB Database.", args: "sql": "<sql>"
Resources:
1. Internet access for searches and information gathering.
2. Long Term memory management.
3. vicuna powered Agents for delegation of simple tasks.
4. File output.
Performance Evaluation:
1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.
2. Constructively self-criticize your big-picture behavior constantly.
3. Reflect on past decisions and strategies to refine your approach.
4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.
5. Write all code to a file.
You should only respond in JSON format as described below
Response Format:
{
"thoughts": {
"text": "thought",
"reasoning": "reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan",
"criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user"
},
"command": {
"name": "command name",
"args": {
"arg name": "value"
}
}
}
Ensure the response can be parsed by Python json.loads
"""
),
(
"ASSISTANT",
"""
{
"thoughts": {
"text": "thought",
"reasoning": "reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan",
"criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user"
},
"command": {
"name": "command name",
"args": {
"arg name": "value"
}
}
}
"""
)
),
offset=0,
sep_style=SeparatorStyle.THREE,
sep=" ",
sep2="</s>",
)

auto_dbgpt_without_shot = Conversation(
system="You are DB-GPT, an AI designed to answer questions about HackerNews by query `hackerbews` database in MySQL. "
"Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications.",
roles=("USER", "ASSISTANT"),
messages=(),
offset=0,
sep_style=SeparatorStyle.FOUR,
sep=" ",
sep2="</s>",
)

conv_qa_prompt_template = """ 基于以下已知的信息, 专业、详细的回答用户的问题。
如果无法从提供的恶内容中获取答案, 请说: "知识库中提供的内容不足以回答此问题", 但是你可以给出一些与问题相关答案的建议:
conv_qa_prompt_template = """ 基于以下已知的信息, 专业、详细的回答用户的问题,
如果无法从提供的恶内容中获取答案, 请说: "知识库中提供的内容不足以回答此问题", 但是你可以给出一些与问题相关答案的建议。
已知内容:
{context}
问题:
Expand Down
Loading

0 comments on commit 3e9fba7

Please sign in to comment.