码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 在线问诊 Python、FastAPI、Neo4j — 提供咨询接口服务


    合集 - 在线问诊(10)
    1.在线问诊 Python、FastAPI、Neo4j — 创建药品节点09-122.在线问诊 Python、FastAPI、Neo4j — 创建症状节点09-143.在线问诊 Python、FastAPI、Neo4j — 创建 检查节点09-194.在线问诊 Python、FastAPI、Neo4j — 创建 疾病节点09-205.在线问诊 Python、FastAPI、Neo4j — 创建 饮食节点09-216.在线问诊 Python、FastAPI、Neo4j — 创建 节点关系09-227.在线问诊 Python、FastAPI、Neo4j — 构建问题分类器09-278.在线问诊 Python、FastAPI、Neo4j — 生成 Cypher 语句09-289.在线问诊 Python、FastAPI、Neo4j — 问题咨询10-10
    10.在线问诊 Python、FastAPI、Neo4j — 提供咨询接口服务10-11
    收起

    目录
    • 构建服务层
    • 接口路由层
    • PostMan 调用

    采用 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.py、question_classifier.py、question_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

  • 相关阅读:
    一文2000字教你从0到1实现Jmeter 分布式压测
    金色传说:SAP-QM-周期性检验:MSC1N/MSC2N/MSC3N下一次检验日期逻辑问题
    Sora关于背景详细的提示词技巧
    设计模式浅析(八) ·外观模式
    超有爱科技携手企企通,打造智慧的数字化采购体系,推动教育数字转型
    【Linux | systemd】systemd(systemctl命令)运行服务的配置文件详解
    G1D21-作业-AttacKG&SVM&kg_book&偷懒哈哈哈
    LeetCode刷题之分隔链表(图解➕代码)
    王怀远:阿里云一站式物联网存储架构设计
    【数据结构】栈
  • 原文地址:https://www.cnblogs.com/vipsoft/p/17729756.html
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号