当前位置: 首页 > news >正文

网站建站去哪找客户wordpress 单页模版

网站建站去哪找客户,wordpress 单页模版,做网页难吗,中铁航空港建设集团网站昨天写了一篇文章#xff0c;使用fastapi直接操作neo4j图数据库插入数据的例子#xff0c; 本文实现LLM大模型结合neo4j图数据库实现AI问答功能。 废话不多说#xff0c;先上代码 import gradio as gr from fastapi import FastAPI, HTTPException, Request from pydantic…昨天写了一篇文章使用fastapi直接操作neo4j图数据库插入数据的例子 本文实现LLM大模型结合neo4j图数据库实现AI问答功能。 废话不多说先上代码 import gradio as gr from fastapi import FastAPI, HTTPException, Request from pydantic import BaseModel from langchain_openai import ChatOpenAI from langchain.prompts import (ChatPromptTemplate,MessagesPlaceholder,SystemMessagePromptTemplate,HumanMessagePromptTemplate, ) from langchain.chains import LLMChain from langchain.memory import ConversationBufferMemory from langchain_community.graphs import Neo4jGraph from langchain.chains import GraphCypherQAChain import asyncio from typing import List import json# Initialize FastAPI app FastAPI()# Initialize Neo4j with timeout try:graph Neo4jGraph(urlbolt://localhost:7687,usernameneo4j,passwordpassword,databaseneo4j,timeout60 # 60 seconds timeout) except Exception as e:print(fFailed to connect to Neo4j: {e})graph None# Fallback in-memory storage job_seekers [] job_positions []# Initialize LangChain components llm ChatOpenAI(temperature0.95,modelglm-4-flash,openai_api_keyxxxxxx,openai_api_basehttps://open.bigmodel.cn/api/paas/v4/ )prompt ChatPromptTemplate(messages[SystemMessagePromptTemplate.from_template(You are a helpful AI assistant for a recruitment company. You can answer questions about job seekers and available positions.),MessagesPlaceholder(variable_namechat_history),HumanMessagePromptTemplate.from_template({question})] )memory ConversationBufferMemory(memory_keychat_history, return_messagesTrue) conversation LLMChain(llmllm,promptprompt,verboseTrue,memorymemory )# Initialize GraphCypherQAChain if Neo4j is available if graph:graph_qa GraphCypherQAChain.from_llm(llm,graphgraph,verboseTrue)# Define chat function with timeout async def chat_with_timeout(message, history):try:if graph:neo4j_response await asyncio.wait_for(asyncio.to_thread(graph_qa.run, message),timeout10.0 # 10 seconds timeout)return fBased on our database: {neo4j_response}else:# Fallback to in-memory dataif job seekers in message.lower():return fBased on our records: We have {len(job_seekers)} job seekers.elif job positions in message.lower():return fBased on our records: We have {len(job_positions)} job positions.else:response conversation.invoke({question: message})return response[text]except asyncio.TimeoutError:return Im sorry, but the database query took too long. Please try a simpler question or try again later.except Exception as e:print(fError in chat function: {e})response conversation.invoke({question: message})return response[text]# # Create Gradio interface iface gr.ChatInterface(chat_with_timeout) # # # Mount Gradio app to FastAPI app gr.mount_gradio_app(app, iface, path/)# Run the app if __name__ __main__:import uvicornuvicorn.run(app, host0.0.0.0, port8000)还是老规矩先AI解释下构建一个基于FastAPI和Gradio的聊天应用主要功能如下 1、初始化FastAPI应用和Neo4j图数据库连接带超时处理 2、定义了用于对话的LangChain组件包括LLM模型、提示模板及对话记忆 3、根据Neo4j是否可用初始化图查询链 4、实现异步聊天函数支持数据库查询数据检索并处理超时错误 5、使用Gradio创建用户界面并将应用挂载到FastAPI上。 核心关注graph_qa.run方法执行原理 自然语言处理 当调用 graph_qa.run(message) 时首先会将用户的自然语言查询message传递给大语言模型LLM。 Cypher 查询生成 LLM 分析用户的查询并尝试将其转换为 Cypher 查询语言。Cypher 是 Neo4j 图数据库使用的查询语言。这个步骤涉及到理解用户意图和将其映射到图数据库的结构上。 数据库查询 生成的 Cypher 查询被发送到 Neo4j 数据库执行。这个过程涉及到遍历图数据库匹配节点和关系并检索相关数据。 结果解释 数据库返回查询结果后这些结果会被传回给 LLM。LLM 会分析这些原始数据理解其含义和上下文。 响应生成 最后LLM 会根据原始查询和数据库返回的结果生成一个人类可读的响应。这个响应应该直接回答用户的问题并可能包含从数据库中提取的具体信息。 在上一篇文章中我已经在neo4j插入了一些数据比如张三1的技能。 这里问一下 原文链接 【知识图谱】4、LLM大模型结合neo4j图数据库实现AI问答的功能
http://www.w-s-a.com/news/106076/

相关文章:

  • 国开行网站毕业申请怎么做大连旅顺口旅游攻略
  • 鲜花店网站源码成都专做婚介网站的公司
  • 合肥企业网站建设工哈尔滨公告
  • 华强北 做网站互联网服务平台入口
  • vi设计案例网站微信导航网站 dedecms
  • 青浦区做网站设计图片手绘图片
  • 做网站的基本功制作网站公司推荐
  • 阿里云快速建站教程个人网站 费用
  • 广东购物网站建设微信公众号制作模板免费
  • 阿里国际站韩语网站怎么做让移动网站
  • 北京外包做网站如何报价中国几大网络推广公司
  • 中国建设部网站关于资质wordpress 建app
  • 程序员找工作的网站哈尔滨建设信息网站
  • 公司 网站 方案高考写作网站
  • 网站后台如何登陆网站开发需求逻辑图
  • 市级档案网站建设情况分析server2008做DNS与网站
  • 公积金门户网站建设方案网站建设代理平台怎么做
  • 网站建设知识论文抖音开放平台是干什么的
  • 网站建设期末试卷大气简洁网站
  • 电子商务网站建设报告范文单位做网站怎么做
  • 优质的外国网站qq小程序在哪里打开
  • 商务网站建设与推广实训报告免费素材网站无水印
  • 外贸站seoapp开发公司历程概述
  • 沈阳网站推广¥做下拉去118cr陶瓷企业 瓷砖地板公司网站建设
  • 医院网站官方微信精神文明建设我做服装设计师的 求推荐资源网站
  • 微信网站建设需要那些资料昆明cms模板建站
  • 安庆网站建设兼职中企动力是500强吗
  • 网站排名优化技巧基于网站的网络营销方法有哪些
  • 摄影素材网站做知识问答的网站
  • 中小企业网站建设济南兴田德润电话门店管理系统软件排行