Skip to content

Commit

Permalink
modify namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
AkkIcon committed Jan 10, 2024
1 parent 61fe46d commit 010e96b
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 78 deletions.
18 changes: 9 additions & 9 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#APPID=649ce030ba7ab8bd12de8eb4
APPID=b530b97b327a44e2b559c671dff05f5e
APPID=xxxxxxx
PERSIST_DIRECTORY="/opt/dg-agent/vector-store/db"
EMBEDDINGS_MODEL_NAME=shibing624/text2vec-base-chinese
BUSINESS_SERVER=http://localhost:10821
SOURCE_DIRECTORY=../../docs
REDIS_URI=120.79.250.15
REDIS_URI=xx.xx.xx.xx
REDIS_PORT=6399
REDIS_PWD=mkuioy#@$
OPENAI_KEY=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
OPENAI_KEY=sk-xxxx
MODEL_NAME=gpt-4
API_SERVER=dg_agent.api.fastapi.FastAPI
DB=dg_agent.db.mongo.MongoDB
VECTOR_STORE=dg_agent.vector_store.chroma.Chroma
LLM=dg_agent.llm.vanus.Vanus
CONTEXT_STORE=dg_agent.context_store.default.DefaultContextStore
API_SERVER=sql_agent.api.fastapi.FastAPI
DB=sql_agent.db.mongo.MongoDB
VECTOR_STORE=sql_agent.vector_store.chroma.Chroma
LLM=sql_agent.llm.vanus.Vanus
CONTEXT_STORE=sql_agent.context_store.default.DefaultContextStore
MONGODB_URI="mongodb://localhost:27017"
MONGODB_DB_NAME='dg_agent'
MONGODB_DB_NAME='sql_agent'
MONGODB_DB_USERNAME='admin'
MONGODB_DB_PASSWORD='admin'
6 changes: 3 additions & 3 deletions dg_agent/__init__.py → sql_agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dg_agent.config import Settings, System
from dg_agent.api import API
from sql_agent.config import Settings, System
from sql_agent.api import API

__settings = Settings()
__version__ = "V1.0 Alpha"


def client(settings: Settings = __settings) -> API:
"""Return a running dg_agent.API instance"""
"""Return a running sql_agent.API instance"""

system = System(settings)
api = system.instance(API)
Expand Down
4 changes: 2 additions & 2 deletions dg_agent/api/__init__.py → sql_agent/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from fastapi import BackgroundTasks

from dg_agent.config import Component
from dg_agent.protocol import (
from sql_agent.config import Component
from sql_agent.protocol import (
ChatCompletionRequest,
CompletionKnowledgeLoadRequest,
CompletionKnowledgeDeleteRequest,
Expand Down
20 changes: 10 additions & 10 deletions dg_agent/api/fastapi.py → sql_agent/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import requests
from overrides import override
from typing import Generator, Any, List
from dg_agent.api import API
from dg_agent.config import System
from dg_agent.db import DB
from dg_agent.llm import LLM
from sql_agent.api import API
from sql_agent.config import System
from sql_agent.db import DB
from sql_agent.llm import LLM
from fastapi import BackgroundTasks
from dg_agent.generator import prompt_generator
from sql_agent.generator import prompt_generator
import pandas as pd
from dg_agent.protocol.types import GoldenRecord
from dg_agent.vector_store.doc_index import DocIndex
from dg_agent.context_store import ContextStore
from sql_agent.protocol.types import GoldenRecord
from sql_agent.vector_store.doc_index import DocIndex
from sql_agent.context_store import ContextStore
from fastapi.responses import StreamingResponse, JSONResponse
from dg_agent.protocol import (
from sql_agent.protocol import (
ChatCompletionRequest,
ChatCompletionResponseStreamChoice,
ChatCompletionStreamResponse,
Expand All @@ -26,7 +26,7 @@
CompletionKnowledgeDeleteRequest,
CompletionGoldenSQLAddRequest
)
from dg_agent.protocol.types import GoldenRecord, Question
from sql_agent.protocol.types import GoldenRecord, Question


def create_error_response(code: int, message: str) -> JSONResponse:
Expand Down
24 changes: 12 additions & 12 deletions dg_agent/config/__init__.py → sql_agent/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
from pydantic import BaseSettings

_abstract_type_keys: Dict[str, str] = {
"dg_agent.api.API": "api_impl",
"dg_agent.db.DB": "db_impl",
"dg_agent.llm.LLM": "llm_impl",
"dg_agent.vector_store.VectorStore": "vector_store_impl",
"dg_agent.vector_store.doc_index.DocIndex": "doc_index_impl",
"dg_agent.context_store.ContextStore": "context_store_impl"
"sql_agent.api.API": "api_impl",
"sql_agent.db.DB": "db_impl",
"sql_agent.llm.LLM": "llm_impl",
"sql_agent.vector_store.VectorStore": "vector_store_impl",
"sql_agent.vector_store.doc_index.DocIndex": "doc_index_impl",
"sql_agent.context_store.ContextStore": "context_store_impl"
}


class Settings(BaseSettings):
load_dotenv()
api_impl: str = os.environ.get("API_SERVER", "dg_agent.api.fastapi.FastAPI")
db_impl: str = os.environ.get("DB", "dg_agent.db.mongo.MongoDB")
api_impl: str = os.environ.get("API_SERVER", "sql_agent.api.fastapi.FastAPI")
db_impl: str = os.environ.get("DB", "sql_agent.db.mongo.MongoDB")

vector_store_impl: str = os.environ.get(
"VECTOR_STORE", "dg_agent.vector_store.chroma.Chroma"
"VECTOR_STORE", "sql_agent.vector_store.chroma.Chroma"
)
llm_impl: str = os.environ.get(
"LLM", "dg_agent.llm.vanus.Vanus"
"LLM", "sql_agent.llm.vanus.Vanus"
)
doc_index_impl: str = os.environ.get(
"DocIndex", "dg_agent.vector_store.doc_index.chroma_doc.ChromaDoc"
"DocIndex", "sql_agent.vector_store.doc_index.chroma_doc.ChromaDoc"
)
context_store_impl:str=os.environ.get(
"CONTEXT_STORE", "dg_agent.context_store.default.DefaultContextStore"
"CONTEXT_STORE", "sql_agent.context_store.default.DefaultContextStore"
)

db_name: Union[str, None] = os.environ.get("MONGODB_DB_NAME")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from abc import ABC, abstractmethod
from typing import List, Tuple, Union

from dg_agent.config import Component, System
from dg_agent.db import DB
from dg_agent.protocol.types import GoldenRecord, Question
from dg_agent.vector_store import VectorStore
from sql_agent.config import Component, System
from sql_agent.db import DB
from sql_agent.protocol.types import GoldenRecord, Question
from sql_agent.vector_store import VectorStore


class ContextStore(Component, ABC):
Expand All @@ -18,7 +18,7 @@ def __init__(self, system: System):
self.system = system
self.db = self.system.instance(DB)
self.golden_record_collection = os.environ.get(
"GOLDEN_RECORD_COLLECTION", "dg_agent-staging"
"GOLDEN_RECORD_COLLECTION", "sql_agent-staging"
)
self.vector_store = self.system.instance(VectorStore)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from typing import List, Tuple, Union

from dg_agent.repositories.golden_records import GoldenRecordRepository
from dg_agent.repositories.instructions import InstructionRepository
from dg_agent.protocol.types import GoldenRecord, Question
from sql_agent.repositories.golden_records import GoldenRecordRepository
from sql_agent.repositories.instructions import InstructionRepository
from sql_agent.protocol.types import GoldenRecord, Question
from overrides import override
from sql_metadata import Parser

from dg_agent.config import System
from dg_agent.context_store import ContextStore
from sql_agent.config import System
from sql_agent.context_store import ContextStore

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion dg_agent/db/__init__.py → sql_agent/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod

from dg_agent.config import Component, System
from sql_agent.config import Component, System


class DB(Component, ABC):
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions dg_agent/db/mongo.py → sql_agent/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from overrides import override
from pymongo import MongoClient

from dg_agent.config import System
from dg_agent.db import DB
from sql_agent.config import System
from sql_agent.db import DB


class MongoDB(DB):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from dotenv import load_dotenv
from langchain.embeddings import HuggingFaceEmbeddings

from dg_agent.db.models.types import (
from sql_agent.db.models.types import (
TableDescription,
ColumnDetail,
ForeignKeyDetail
)
from dg_agent.generator.redis_client import Redis
from sql_agent.generator.redis_client import Redis

load_dotenv()
embeddings_model_name = os.environ.get('EMBEDDINGS_MODEL_NAME')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import redis
from dg_agent.config import System
from dg_agent.db import DB
from sql_agent.config import System
from sql_agent.db import DB
from overrides import override


Expand Down
2 changes: 1 addition & 1 deletion dg_agent/llm/__init__.py → sql_agent/llm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from dg_agent.config import Component
from sql_agent.config import Component


class LLM(Component, ABC):
Expand Down
4 changes: 2 additions & 2 deletions dg_agent/llm/openai.py → sql_agent/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from httpx import AsyncClient
from overrides import override

from dg_agent.config import System
from dg_agent.llm import LLM
from sql_agent.config import System
from sql_agent.llm import LLM


class ChatGPT(LLM):
Expand Down
4 changes: 2 additions & 2 deletions dg_agent/llm/vanus.py → sql_agent/llm/vanus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from httpx import AsyncClient
from overrides import override

from dg_agent.config import System
from dg_agent.llm import LLM
from sql_agent.config import System
from sql_agent.llm import LLM


class Vanus(LLM):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Union

from bson.objectid import ObjectId
from dg_agent.protocol.types import GoldenRecord
from sql_agent.protocol.types import GoldenRecord

DB_COLLECTION = "golden_records"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bson.objectid import ObjectId
from typing import Union
from dg_agent.protocol.types import Instruction
from sql_agent.protocol.types import Instruction

DB_COLLECTION = "instructions"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bson.objectid import ObjectId
from typing import Union
from dg_agent.protocol.types import Question
from sql_agent.protocol.types import Question

DB_COLLECTION = "questions"

Expand Down
6 changes: 3 additions & 3 deletions dg_agent/server.py → sql_agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# 添加上两层目录到sys.path
sys.path.append(project_dir)

import dg_agent
from dg_agent.server.fastapi import FastAPI
import sql_agent
from sql_agent.server.fastapi import FastAPI

settings = dg_agent.config.Settings()
settings = sql_agent.config.Settings()
server = FastAPI(settings)
if __name__ == "__main__":
app = server.app()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod

from dg_agent.config import Settings
from sql_agent.config import Settings


class Server(ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from fastapi import BackgroundTasks
from fastapi import FastAPI as _FastAPI
from fastapi.routing import APIRoute
import dg_agent
from dg_agent.config import Settings
from dg_agent.protocol import (
import sql_agent
from sql_agent.config import Settings
from sql_agent.protocol import (
ChatCompletionRequest,
CompletionKnowledgeLoadRequest,
CompletionKnowledgeDeleteRequest,
Expand All @@ -25,11 +25,11 @@ def use_route_names_as_operation_ids(app: _FastAPI) -> None:
route.operation_id = route.name


class FastAPI(dg_agent.server.Server):
class FastAPI(sql_agent.server.Server):
def __init__(self, settings: Settings):
super().__init__(settings)
self._app = fastapi.FastAPI(debug=True)
self._api: dg_agent.api.API = dg_agent.client(settings)
self._api: sql_agent.api.API = sql_agent.client(settings)

self.router = fastapi.APIRouter()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from typing import Any, List

from dg_agent.config import Component, System
from sql_agent.config import Component, System


class VectorStore(Component, ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import chromadb
from overrides import override

from dg_agent.config import System
from dg_agent.vector_store import VectorStore
from sql_agent.config import System
from sql_agent.vector_store import VectorStore


class Chroma(VectorStore):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from typing import List

from dg_agent.config import Component, System
from sql_agent.config import Component, System


class DocIndex(Component, ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from tqdm import tqdm
from typing import List
from multiprocessing import Pool
from dg_agent.config import System
from sql_agent.config import System
from overrides import override
from dg_agent.vector_store.doc_index import DocIndex
from sql_agent.vector_store.doc_index import DocIndex
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import Chroma
from langchain.text_splitter import RecursiveCharacterTextSplitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from langchain.vectorstores import Chroma
from bson.objectid import ObjectId
from langchain.embeddings import HuggingFaceEmbeddings
from dg_agent.db.models.types import GoldenRecord
from sql_agent.db.models.types import GoldenRecord
from dotenv import load_dotenv
from dg_agent.db.models.types import NlQuestion
from sql_agent.db.models.types import NlQuestion

load_dotenv('../../config.env')
embeddings_model_name = os.environ.get('EMBEDDINGS_MODEL_NAME')
Expand Down

0 comments on commit 010e96b

Please sign in to comment.