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

fix llm strategy value store format. #1172

Closed
wants to merge 6 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
2 changes: 1 addition & 1 deletion dbgpt/app/static/404.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/404/index.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dbgpt/app/static/agent/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/app/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/chat/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/database/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/flow/canvas/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/flow/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/knowledge/chunk/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/knowledge/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/models/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/app/static/prompt/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbgpt/serve/agent/agents/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def gpts_create(self, entity: GptsInstanceEntity):
def get_dbgpts(self, user_code: str = None, sys_code: str = None):
apps = self.gpts_app.app_list(
GptsAppQuery(user_code=user_code, sys_code=sys_code)
)
).app_list
return apps

async def agent_chat(
Expand Down
2 changes: 1 addition & 1 deletion dbgpt/serve/agent/app/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def create(gpts_app: GptsApp):
@router.post("/v1/app/list")
async def app_list(query: GptsAppQuery):
try:
return Result.succ(gpts_dao.app_list(query))
return Result.succ(gpts_dao.app_list(query, True))
except Exception as ex:
return Result.failed(code="E000X", msg=f"query app error: {ex}")

Expand Down
40 changes: 33 additions & 7 deletions dbgpt/serve/agent/db/gpts_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ def _serialize(self, value):
return value

@classmethod
def from_dict(cls, d: Dict[str, Any]):
def from_dict(cls, d: Dict[str, Any], parse_llm_strategy: bool = False):
lsv = d.get("llm_strategy_value")
if parse_llm_strategy and lsv:
strategies = json.loads(lsv)
llm_strategy_value = ",".join(strategies)
else:
llm_strategy_value = d.get("llm_strategy_value", None)

return cls(
app_code=d["app_code"],
app_name=d["app_name"],
Expand All @@ -56,7 +63,7 @@ def from_dict(cls, d: Dict[str, Any]):
resources=AgentResource.from_josn_list_str(d.get("resources", None)),
prompt_template=d.get("prompt_template", None),
llm_strategy=d.get("llm_strategy", None),
llm_strategy_value=d.get("llm_strategy_value", None),
llm_strategy_value=llm_strategy_value,
created_at=d.get("created_at", None),
updated_at=d.get("updated_at", None),
)
Expand Down Expand Up @@ -135,6 +142,13 @@ class GptsAppQuery(GptsApp):
is_collected: Optional[str] = None


class GptsAppResponse(BaseModel):
total_count: Optional[int] = 0
total_page: Optional[int] = 0
current_page: Optional[int] = 0
app_list: Optional[List[GptsApp]] = []


class GptsAppCollection(BaseModel):
app_code: Optional[str] = None
user_code: Optional[str] = None
Expand Down Expand Up @@ -318,7 +332,7 @@ def list(self, query: GptsAppCollection):


class GptsAppDao(BaseDao):
def app_list(self, query: GptsAppQuery):
def app_list(self, query: GptsAppQuery, parse_llm_strategy: bool = False):
collection_dao = GptsAppCollectionDao()
gpts_collections = collection_dao.list(
GptsAppCollection.from_dict(
Expand All @@ -339,6 +353,7 @@ def app_list(self, query: GptsAppQuery):
app_qry = app_qry.filter(GptsAppEntity.sys_code == query.sys_code)
if query.is_collected and query.is_collected.lower() in ("true", "false"):
app_qry = app_qry.filter(GptsAppEntity.app_code.in_(app_codes))
total_count = app_qry.count()
app_qry = app_qry.order_by(GptsAppEntity.id.desc())
app_qry = app_qry.offset((query.page_no - 1) * query.page_size).limit(
query.page_size
Expand All @@ -348,6 +363,7 @@ def app_list(self, query: GptsAppQuery):
result_app_codes = [res.app_code for res in results]
app_details_group = self._group_app_details(result_app_codes, session)
apps = []
app_resp = GptsAppResponse()
for app_info in results:
app_details = app_details_group.get(app_info.app_code, [])

Expand All @@ -370,13 +386,19 @@ def app_list(self, query: GptsAppQuery):
"created_at": app_info.created_at,
"updated_at": app_info.updated_at,
"details": [
GptsAppDetail.from_dict(item.to_dict())
GptsAppDetail.from_dict(
item.to_dict(), parse_llm_strategy
)
for item in app_details
],
}
)
)
return apps
app_resp.total_count = total_count
app_resp.app_list = apps
app_resp.current_page = query.page_no
app_resp.total_page = (total_count + query.page_size - 1) // query.page_size
return app_resp

def _group_app_details(self, app_codes, session):
app_detail_qry = session.query(GptsAppDetailEntity).filter(
Expand Down Expand Up @@ -483,7 +505,9 @@ def create(self, gpts_app: GptsApp):
resources=json.dumps(resource_dicts, ensure_ascii=False),
prompt_template=item.prompt_template,
llm_strategy=item.llm_strategy,
llm_strategy_value=item.llm_strategy_value,
llm_strategy_value=None
if item.llm_strategy_value is None
else json.dumps(tuple(item.llm_strategy_value.split(","))),
created_at=item.created_at,
updated_at=item.updated_at,
)
Expand Down Expand Up @@ -525,7 +549,9 @@ def edit(self, gpts_app: GptsApp):
resources=json.dumps(resource_dicts, ensure_ascii=False),
prompt_template=item.prompt_template,
llm_strategy=item.llm_strategy,
llm_strategy_value=item.llm_strategy_value,
llm_strategy_value=None
if item.llm_strategy_value is None
else json.dumps(tuple(item.llm_strategy_value.split(","))),
created_at=item.created_at,
updated_at=item.updated_at,
)
Expand Down
4 changes: 2 additions & 2 deletions web/client/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '@/types/knowledge';
import { UpdatePromptParams, IPrompt, PromptParams } from '@/types/prompt';
import { IFlow, IFlowNode, IFlowResponse, IFlowUpdateParam } from '@/types/flow';
import { IAgent, IApp, ITeamModal } from '@/types/app';
import { IAgent, IApp, IAppData, ITeamModal } from '@/types/app';

/** App */
export const postScenes = () => {
Expand Down Expand Up @@ -283,7 +283,7 @@ export const addApp = (data: IApp) => {
};

export const getAppList = (data: Record<string, string>) => {
return POST<Record<string, string>, IApp[]>('/api/v1/app/list', data);
return POST<Record<string, string>, IAppData>('/api/v1/app/list', data);
};

export const collectApp = (data: Record<string, string>) => {
Expand Down
2 changes: 1 addition & 1 deletion web/pages/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function App() {
}
if (!data) return;

setApps(data || []);
setApps(data.app_list || []);
setSpinning(false);
};

Expand Down
7 changes: 7 additions & 0 deletions web/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export type IApp = {
is_collected: string;
};

export type IAppData = {
app_list: IApp[];
current_page: number;
total_count: number;
total_page: number;
};

// agent
export type AgentParams = {
agent_name: string;
Expand Down