经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » neo4j » 查看文章
在线问诊 Python、FastAPI、Neo4j — 提供咨询接口服务
来源:cnblogs  作者:VipSoft  时间:2023/10/11 16:10:35  对本文有异议

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

构建服务层

qa_service.py

  1. from service.question_classifier import *
  2. from service.question_parser import *
  3. from service.answer_search import *
  4. class QAService:
  5. def __init__(self):
  6. self.classifier = QuestionClassifier()
  7. self.parser = QuestionPaser()
  8. self.searcher = AnswerSearcher()
  9. def chat_main(self, sent):
  10. answer = '您的问题,我还没有学习到。祝您身体健康!'
  11. res_classify = self.classifier.classify(sent)
  12. if not res_classify:
  13. return answer
  14. res_sql = self.parser.parser_main(res_classify)
  15. final_answers = self.searcher.search_main(res_sql)
  16. if not final_answers:
  17. return answer
  18. else:
  19. 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

  1. #!/usr/bin/python3
  2. import logging
  3. from fastapi import APIRouter, status
  4. from fastapi.responses import JSONResponse
  5. from pydantic import BaseModel
  6. from service.qa_service import QAService
  7. import json
  8. router = APIRouter()
  9. qa = QAService() #实类化 QAService 服务
  10. class Item(BaseModel):
  11. name: str = None
  12. question: str
  13. @router.post("/consult")
  14. async def get_search(param: Item):
  15. answer = qa.chat_main(param.question)
  16. return JSONResponse(content=answer, status_code=status.HTTP_200_OK)

PostMan 调用

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

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

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

image
image

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

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

原文链接:https://www.cnblogs.com/vipsoft/p/17729756.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号