Signed-off-by: ZePan110 <ze.pan@intel.com> Signed-off-by: chensuyue <suyue.chen@intel.com> Signed-off-by: Zhu, Yongbo <yongbo.zhu@intel.com> Signed-off-by: Wang, Xigui <xigui.wang@intel.com> Co-authored-by: ZePan110 <ze.pan@intel.com> Co-authored-by: chen, suyue <suyue.chen@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: xiguiw <111278656+xiguiw@users.noreply.github.com> Co-authored-by: lvliang-intel <liang1.lv@intel.com>
30 lines
825 B
Python
30 lines
825 B
Python
# Copyright (C) 2024 Intel Corporation
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
from comps.cores.proto.api_protocol import ChatCompletionRequest
|
|
from edgecraftrag.context import ctx
|
|
from fastapi import FastAPI
|
|
|
|
chatqna_app = FastAPI()
|
|
|
|
|
|
# Retrieval
|
|
@chatqna_app.post(path="/v1/retrieval")
|
|
async def retrieval(request: ChatCompletionRequest):
|
|
nodeswithscore = ctx.get_pipeline_mgr().run_retrieve(chat_request=request)
|
|
print(nodeswithscore)
|
|
if nodeswithscore is not None:
|
|
ret = []
|
|
for n in nodeswithscore:
|
|
ret.append((n.node.node_id, n.node.text, n.score))
|
|
return ret
|
|
|
|
return "Not found"
|
|
|
|
|
|
# ChatQnA
|
|
@chatqna_app.post(path="/v1/chatqna")
|
|
async def chatqna(request: ChatCompletionRequest):
|
|
ret = ctx.get_pipeline_mgr().run_pipeline(chat_request=request)
|
|
return str(ret)
|