"""Update uapi entries to match actual GPU service API specs""" import asyncio from sqlor.dbpools import DBPools from appPublic.jsonConfig import getConfig async def main(): c = getConfig('.') DBPools(c.databases) db = DBPools() async with db.sqlorContext('rag') as s: headers_tmpl = '{\n "Content-Type": "application/json"\n}' # VDB — fix param names vdb_fixes = [ ("vdb-upsert", "upsert", "/v1/upsert", '{"colname": "{{colname}}", "data": {{json.dumps(data)}}}'), ("vdb-search", "search", "/v1/query", '{"colname": "{{colname}}", "vector": {{json.dumps(vector)}}, "pagerows": {{top_k}}, "output_fields": ["*"]}'), ("vdb-delete", "delete", "/v1/delete", '{"colname": "{{colname}}", "pks": {{json.dumps(ids)}}}'), ] for aid, name, path, data in vdb_fixes: await s.sqlExe( "UPDATE uapi SET name=" + repr(name) + ", path=" + repr(path) + ", data=" + repr(data) + " WHERE id=" + repr(aid), {}) print(f"VDB: {aid} → {path}") # CLIP — fix to /api/embed with texts+images await s.sqlExe( "UPDATE uapi SET data=" + repr( '{"texts": {{json.dumps(texts)}}, "images": {{json.dumps(images)}}}' ) + " WHERE id='emb-embed'", {}) print("CLIP: /api/embed updated") # Reranker — add top_k parameter await s.sqlExe( "UPDATE uapi SET data=" + repr( '{"query": "{{query}}", "documents": {{json.dumps(documents)}}, "top_k": {{top_k}}}' ) + " WHERE id='reranker-rerank'", {}) print("Reranker: data updated") # NER — fix path to /api/extract + add entities/threshold params await s.sqlExe( "UPDATE uapi SET path=" + repr("/api/extract") + ", data=" + repr( '{"text": "{{text}}", "entities": {{json.dumps(entities)}}, "threshold": {{threshold}}}' ) + " WHERE id='ner-entities'", {}) print("NER: /api/extract updated") # Face — fix param names (images list) await s.sqlExe( "UPDATE uapi SET data=" + repr('{"images": {{json.dumps(images)}}}') + " WHERE id='face-detect'", {}) await s.sqlExe( "UPDATE uapi SET data=" + repr('{"images": {{json.dumps(images)}}}') + " WHERE id='face-recognize'", {}) await s.sqlExe( "UPDATE uapi SET data=" + repr('{"image1": "{{image1}}", "image2": "{{image2}}"}') + " WHERE id='face-compare'", {}) print("Face: params fixed") # Graph — add missing endpoints new_graph = [ ("graph-add-node", "rag-graph", "add_node", "添加节点", "POST", "/api/graph/add_node", '{"graph": "{{graph}}", "node_id": "{{node_id}}", "attrs": {{json.dumps(attrs)}}}', "io-graph"), ("graph-add-edge", "rag-graph", "add_edge", "添加边", "POST", "/api/graph/add_edge", '{"graph": "{{graph}}", "source": "{{source}}", "target": "{{target}}", "attrs": {{json.dumps(attrs)}}}', "io-graph"), ("graph-neighbors", "rag-graph", "neighbors", "邻居查询", "GET", "/api/graph/neighbors", '{"graph": "{{graph}}", "node_id": "{{node_id}}"}', "io-graph"), ] for aid, upappid, name, title, method, path, data, ioid in new_graph: await s.sqlExe( "INSERT IGNORE INTO uapi (id, upappid, name, title, httpmethod, path, data, headers, ioid) " "VALUES (" + repr(aid) + "," + repr(upappid) + "," + repr(name) + "," + repr(title) + "," + repr(method) + "," + repr(path) + "," + repr(data) + "," + repr(headers_tmpl) + "," + repr(ioid) + ")", {}) print(f"Graph: added {aid}") # Verify all print("\n=== All uapi entries ===") for r in await s.sqlExe( "SELECT id, upappid, name, httpmethod, path FROM uapi ORDER BY upappid, name", {}): print(f" {r.id:25s} {r.upappid:15s} {r.name:12s} {r.httpmethod:4s} {r.path}") asyncio.run(main())