初始化:质量数据分析平台源码

This commit is contained in:
2026-10-22 15:58:57 +08:00
commit 1e8a655adc
280 changed files with 43922 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
"""Send real consecutive research requests to the isolated local DB-GPT SSE API."""
import argparse,json,uuid,urllib.request,time
from pathlib import Path
from dbgpt_trial import model_settings
ROOT=Path(__file__).resolve().parents[1]
OUT=ROOT/'output/dbgpt-trial'
STATE=ROOT/'.runtime/dbgpt-trial/chat-state.json'
def run(question,label,new=False):
state=json.loads(STATE.read_text()) if STATE.exists() and not new else {'conv_uid':str(uuid.uuid4())}
model=model_settings()[2]
body={'conv_uid':state['conv_uid'],'user_input':question,'chat_mode':'chat_react_agent','model_name':model,'temperature':0.1,'max_new_tokens':4000,'ext_info':{'database_name':'sqlite_quality_trial','skill_name':'quality-center'}}
STATE.write_text(json.dumps(state,ensure_ascii=False));STATE.chmod(0o600)
(OUT/(label+'-request.json')).write_text(json.dumps(body,ensure_ascii=False,indent=2))
req=urllib.request.Request('http://127.0.0.1:5670/api/v1/chat/react-agent',data=json.dumps(body,ensure_ascii=False).encode(),headers={'Content-Type':'application/json','Accept':'text/event-stream'})
events=[];begin=time.monotonic();seen=set()
with urllib.request.urlopen(req,timeout=420) as response, (OUT/(label+'.sse')).open('w') as stream:
for raw in response:
line=raw.decode('utf-8',errors='replace');stream.write(line);stream.flush()
if not line.startswith('data:'):continue
data=line[5:].strip()
if data=='[DONE]':print('DONE',label,round(time.monotonic()-begin,1),flush=True);break
try:item=json.loads(data)
except json.JSONDecodeError:continue
events.append(item)
kind=item.get('type') or item.get('event') or item.get('status') or ''
# Only event kinds are echoed; full user data stays in the local artifact.
if kind and kind not in seen:print('event',str(kind)[:100],flush=True);seen.add(kind)
(OUT/(label+'-events.json')).write_text(json.dumps(events,ensure_ascii=False,indent=2))
print('saved',len(events),'events',state['conv_uid'],flush=True)
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('label');p.add_argument('question');p.add_argument('--new',action='store_true');a=p.parse_args();run(a.question,a.label,a.new)