首页 > 编程语言 >在线问诊 Python、FastAPI、Neo4j — 提供接口服务

在线问诊 Python、FastAPI、Neo4j — 提供接口服务

时间:2023-09-26 11:57:51浏览次数:40  
标签:service Python FastAPI self question qa Neo4j answer import

目录

采用 Fast API 搭建服务接口: https://www.cnblogs.com/vipsoft/p/17684079.html
Fast API 文档:https://fastapi.tiangolo.com/zh/

构建服务层

qa_service.py

from service.question_classifier import *
from service.question_parser import *
from service.answer_search import *


class QAService:
    def __init__(self):
        self.classifier = QuestionClassifier()
        self.parser = QuestionPaser()
        self.searcher = AnswerSearcher()

    def chat_main(self, sent):
        answer = '您的问题,我还没有学习到。祝您身体健康!'
        res_classify = self.classifier.classify(sent)
        if not res_classify:
            return answer
        res_sql = self.parser.parser_main(res_classify)
        final_answers = self.searcher.search_main(res_sql)
        if not final_answers:
            return answer
        else:
            return '\n'.join(final_answers)

同时将 answer_search.pyquestion_classifier.pyquestion_parser.py 从test 目录中,移到 service 包中
image

QuestionClassifier 中的 路径获取方式进行修改 ../dic/xxxx 替换为 dic/xxx
image

接口路由层

FastAPI 请求体:https://fastapi.tiangolo.com/zh/tutorial/body/
创建路由接口文件
qa_router.py

#!/usr/bin/python3

import logging
from fastapi import APIRouter, status
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from service.qa_service import QAService
import json

router = APIRouter()
qa = QAService() #实类化 QAService 服务


class Item(BaseModel):
    name: str = None
    question: str


@router.post("/consult")
async def get_search(param: Item):
    answer = qa.chat_main(param.question)
    return JSONResponse(content=answer, status_code=status.HTTP_200_OK)

PostMan 调用

URL: http://127.0.0.1:8000/api/qa/consult

{"question": "请问最近看东西有时候清楚有时候不清楚是怎么回事"}

返回值:
"可能是:干眼"
image

image
image

源代:https://gitee.com/VipSoft/VipQA

参考:https://github.com/liuhuanyong/QASystemOnMedicalKG

标签:service,Python,FastAPI,self,question,qa,Neo4j,answer,import
From: https://www.cnblogs.com/vipsoft/p/17729756.html

相关文章

  • fastapi+tortoise-orm+redis+celery 多worker数据库连接
    我用fastapi在写接口,数据库orm用的是tortoise-orm,接口的数据库操作是正常的。现在加入了celery,但是每个celery在执行任务时,不能获取到数据库连接我想要每个worker获得数据库连接,但是不要每个任务都去连接一次,并在每个worker结束时,断开连接,但是不能断开其他worker的数据库连接from......
  • 【python】只需一段代码,剪辑一个视频——Moviepy详解
    http://www.shanhubei.com/archives/2757.html前言知道吗,用moviepy一行代码就能够快速剪辑视频中某个区间的片段:clip=VideoFileClip(“videoplayback.mp4”).subclip(50,60)这一段代码,能够在3秒内将videoplayback.mp4的50秒-60秒的视频片段提取出来,非常方便。仅如此,movie......
  • Python学习笔记
    pip安装包命令pipinstallnumpy-ihttps://pypi.douban.com/simple#安装(指定国内源来安装)pipinstall--upgradenumpy#升级pipuninstallnumpy#卸载piplist#查看piplist-o#查看需要被升级的包pipshow-fnumpy#查看某个包的信息pipchecknumpy#查看兼容问......
  • 在线问诊 Python、FastAPI、Neo4j — 问题反馈
    目录查出节点拼接节点属性测试结果问答演示通过节点关系,找出对应的节点,获取节点属性值,并拼接成想要的结果。接上节生成的CQL#输入question_class={'args':{'看东西有时候清楚有时候不清楚':['symptom']},'question_types':['symptom_disease']}#输出[{'question_typ......
  • 如何在Python中实现高效的数据处理与分析
    在当今信息爆炸的时代,我们面对的数据量越来越大,如何高效地处理和分析数据成为了一种迫切的需求。Python作为一种强大的编程语言,提供了丰富的数据处理和分析库,帮助我们轻松应对这个挑战。本文将为您介绍如何在Python中实现高效的数据处理与分析,以提升工作效率和数据洞察力。1、数据......
  • Python之html2text:将HTML转换为Markdown文档示例详解
    From: https://mp.weixin.qq.com/s/Pa3NDXOseyg0mIn869mbhQ-----------------------------------------------------------------------------------------hello大家好我是Monday,本文将详细介绍如何使用Python库中的html2text模块来实现将HTML转换为Markdown的操作,并提供示例......
  • 在线问诊 Python、FastAPI、Neo4j — Cypher 生成
    目录构建节点字典构建CypherCQL语句Test这边只是为了测试,演示效果和思路,实际应用中,可以通过NLP构建CQL接上一篇的问题分类question="请问最近看东西有时候清楚有时候不清楚是怎么回事"#最终输出data={'args':{'看东西有时候清楚有时候不清楚':['symptom']},'questio......
  • python读写excel
     pipinstallpandasopenpyxl 读取Excel文件importpandasaspd#读取Excel文件df=pd.read_excel('your_file.xlsx')#查看数据print(df) 写入Excel文件importpandasaspd#创建一个数据框(dataframe)data={'Name':['Tom','Nick&#......
  • 利用Python对当前目录下xlsx文件数据绘制拆线图
    importpandasaspdimportxlwtimportosimportglobimportmatplotlib.pyplotaspltfromopenpyxlimportWorkbookfromopenpyxlimportload_workbookfrommatplotlibimportrcParams ##获取当前路径path=os.getcwd()##获取当前路径下(不包含子目录)的所有xlsx文件zx_w......
  • [888] How to get the directory of the current Python file
    TogetthedirectoryofthecurrentPythonfile,youcanusetheos.pathmoduleincombinationwiththe__file__attribute.Here'showyoucandoit:importos#GetthedirectoryofthecurrentPythonfilecurrent_directory=os.path.dirname(os.pat......