Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Azure openAI and added API_AZURE_DEPLOYMENT environment variables to adapt to Azure openAI #1135

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions dbgpt/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,20 @@ def _migration_db_storage(param: "WebServerParameters"):
from dbgpt.storage.metadata.db_manager import db
from dbgpt.util._db_migration_utils import _ddl_init_and_upgrade

# Try to create all tables, when the dbtype is sqlite, it will auto create and upgrade system schema,
# Otherwise, you need to execute initialization scripts to create schemas.
CFG = Config()
if CFG.LOCAL_DB_TYPE == "sqlite":
try:
db.create_all()
except Exception as e:
logger.warning(
f"Create all tables stored in this metadata error: {str(e)}"
)

_ddl_init_and_upgrade(
default_meta_data_path, param.disable_alembic_upgrade
)
else:
warn_msg = """For safety considerations, MySQL Database not support DDL init and upgrade. "
"1.If you are use DB-GPT firstly, please manually execute the following command to initialize,
`mysql -h127.0.0.1 -uroot -p{your_password} < ./assets/schema/dbgpt.sql` "
"2.If there are any changes to the table columns in the DB-GPT database,
it is necessary to compare with the DB-GPT/assets/schema/dbgpt.sql file
and manually make the columns changes in the MySQL database instance."""
logger.warning(warn_msg)
# try to create all tables
try:
db.create_all()
except Exception as e:
logger.warning(f"Create all tables stored in this metadata error: {str(e)}")
_ddl_init_and_upgrade(default_meta_data_path, param.disable_alembic_upgrade)


def _initialize_db(
try_to_create_db: Optional[bool] = False, system_app: Optional[SystemApp] = None
) -> str:
"""Initialize the database

Now just support sqlite and MySQL. If db type is sqlite, the db path is `pilot/meta_data/{db_name}.db`.
Now just support sqlite and mysql. If db type is sqlite, the db path is `pilot/meta_data/{db_name}.db`.
"""
from urllib.parse import quote
from urllib.parse import quote_plus as urlquote
Expand Down
11 changes: 10 additions & 1 deletion dbgpt/model/utils/chatgpt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class OpenAIParameters:
api_base: Optional[str] = None
api_key: Optional[str] = None
api_version: Optional[str] = None
api_azure_deployment: Optional[str] = None
full_url: Optional[str] = None
proxies: Optional["ProxiesTypes"] = None

Expand Down Expand Up @@ -70,7 +71,7 @@ def _initialize_openai_v1(init_params: OpenAIParameters):
os.getenv("AZURE_OPENAI_KEY") if api_type == "azure" else None,
)
api_version = api_version or os.getenv("OPENAI_API_VERSION")

api_azure_deployment = init_params.api_azure_deployment or os.getenv("API_AZURE_DEPLOYMENT")
if not base_url and full_url:
base_url = full_url.split("/chat/completions")[0]

Expand All @@ -84,6 +85,7 @@ def _initialize_openai_v1(init_params: OpenAIParameters):
openai_params = {
"api_key": api_key,
"base_url": base_url,
"api_azure_deployment": api_azure_deployment
}
return openai_params, api_type, api_version

Expand All @@ -109,6 +111,8 @@ def _initialize_openai(params: OpenAIParameters):
)
api_version = params.api_version or os.getenv("OPENAI_API_VERSION")

api_azure_deployment = params.api_azure_deployment or os.getenv("API_AZURE_DEPLOYMENT")

if not api_base and params.full_url:
# Adapt previous proxy_server_url configuration
api_base = params.full_url.split("/chat/completions")[0]
Expand All @@ -122,6 +126,8 @@ def _initialize_openai(params: OpenAIParameters):
openai.api_version = api_version
if params.proxies:
openai.proxy = params.proxies
if params.api_azure_deployment:
openai.api_azure_deployment =api_azure_deployment


def _build_openai_client(init_params: OpenAIParameters) -> Tuple[str, ClientType]:
Expand All @@ -134,6 +140,9 @@ def _build_openai_client(init_params: OpenAIParameters) -> Tuple[str, ClientType
return api_type, AsyncAzureOpenAI(
api_key=openai_params["api_key"],
api_version=api_version,
#azure_deployment="siasmodel",
azure_deployment=openai_params["api_azure_deployment"],
# model_name="gpt-35-turbo",
azure_endpoint=openai_params["base_url"],
http_client=httpx.AsyncClient(proxies=init_params.proxies),
)
Expand Down
4 changes: 2 additions & 2 deletions dbgpt/storage/vector_store/milvus_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, vector_store_config: MilvusVectorConfig) -> None:
self.port = milvus_vector_config.get("post") or os.getenv(
"MILVUS_PORT", "19530"
)
self.username = milvus_vector_config.get("user") or os.getenv("MILVUS_USERNAME")
self.username = milvus_vector_config.get("user") or os.getenv("MILVUS_USER")
self.password = milvus_vector_config.get("password") or os.getenv(
"MILVUS_PASSWORD"
)
Expand Down Expand Up @@ -133,7 +133,7 @@ def __init__(self, vector_store_config: MilvusVectorConfig) -> None:
connections.connect(
host=self.uri or "127.0.0.1",
port=self.port or "19530",
user=self.username,
username=self.username,
password=self.password,
alias="default",
)
Expand Down
43 changes: 0 additions & 43 deletions docs/docs/installation/sourcecode.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,50 +354,7 @@ Modify the `.env` file to use llama.cpp, and then you can start the service by r
| `llama_cpp_cache_capacity` | None | Maximum model cache size. For example: 2000MiB, 2GiB |
| `llama_cpp_prefer_cpu` | False | If a GPU is available, the GPU will be used first by default unless prefer_cpu=False is configured. |

## Install DB-GPT Application Database
<Tabs
defaultValue="sqlite"
values={[
{label: 'SQLite', value: 'sqlite'},
{label: 'MySQL', value: 'mysql'},
]}>
<TabItem value="sqlite" label="sqlite">

:::tip NOTE

You do not need to separately create the database tables related to the DB-GPT application in SQLite;
they will be created automatically for you by default.

:::


</TabItem>
<TabItem value="mysql" label="MySQL">

:::warning NOTE

After version 0.4.7, we removed the automatic generation of MySQL database Schema for safety.

:::

1. Frist, execute MySQL script to create database and tables.

```python
$ mysql -h127.0.0.1 -uroot -p{your_password} < ./assets/schema/dbgpt.sql
```

2. Second, set DB-GPT MySQL database settings in `.env` file.

```python
LOCAL_DB_TYPE=mysql
LOCAL_DB_USER= {your username}
LOCAL_DB_PASSWORD={your_password}
LOCAL_DB_HOST=127.0.0.1
LOCAL_DB_PORT=3306
```

</TabItem>
</Tabs>


## Test data (optional)
Expand Down