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

技术网站模版赣州seo排名

技术网站模版,赣州seo排名,做彩票网站是违法吗,wordpress程序漏洞集合一、背景 我之前关于DeepSeek使用ollama部署的文章大家可以把DeepSeek大模型部署起来。那么ollama还提供了可以调用对应部署模型的API接口。我们可以基于这些接口,做自己的二次开发。使用pythonflaskollama就可以进行模型对话调用。并且前端采用SSE的技术&#xff0…

一、背景

        我之前关于DeepSeek使用ollama部署的文章大家可以把DeepSeek大模型部署起来。那么ollama还提供了可以调用对应部署模型的API接口。我们可以基于这些接口,做自己的二次开发。使用python+flask+ollama就可以进行模型对话调用。并且前端采用SSE的技术,后端向前端推送推理结果进行展示,可以实现属于自己的大模型对话产品。

二、代码实现

1、ollama运行deepseek-r1:1.5b模型

docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollamadocker exec -it ollama ollama run deepseek-r1:1.5b

2、python+flask代码

import jsonfrom flask import Flask, request, Response
from ollama import Clientapp = Flask(__name__)# ollama客户端
ollma_url = "http://localhost:11434"   # localhost可以换成你部署ollama主机的ip、远程ip
ollama_client = Client(host=ollma_url )
# 模型名称
model_name = "deepseek-r1:1.5b"@app.route('/stream', methods=['POST', 'GET'])
def post_example():def generate():try:# 调用ollama客户端,传入模型名称、提问信息response_generator = ollama_client.generate(model_name, prompt=question, stream=True)for part in response_generator:response_text = part.response# 按照 SSE 规范格式化数据data = f"data: {json.dumps({'response': response_text})}\n\n"print(data)yield dataexcept Exception as e:error_data = f"data: {json.dumps({'error': str(e)})}\n\n"yield error_data# 接收问题, 调用模型, 使用SSE推送推理结果给前端question = request.args.get('question')resp = Response(generate(), mimetype='text/event-stream')# 设置响应头resp.headers['Cache-Control'] = 'no-cache'resp.headers['Connection'] = 'keep-alive'resp.headers['Access-Control-Allow-Origin'] = '*'return respif __name__ == '__main__':app.run(debug=True, port=8080)

3、前端代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Ask Ollama via SSE</title>
</head><body><input type="text" id="questionInput" placeholder="请输入你的问题"><button id="askButton">提问</button><pre id="answerContainer"></p><script>const questionInput = document.getElementById('questionInput');const askButton = document.getElementById('askButton');const answerContainer = document.getElementById('answerContainer');askButton.addEventListener('click', async () => {const question = questionInput.value;if (!question) {alert('请输入问题');return;}const eventSource = new EventSource(`http://localhost:8080/stream?question=${encodeURIComponent(question)}`);eventSource.onmessage = function (event) {const data = JSON.parse(event.data);const response = data.response;if (response) {const p = document.createElement('span');p.textContent = response;answerContainer.appendChild(p);}};eventSource.onerror = function (error) {console.error('EventSource failed:', error);eventSource.close();};});</script>
</body></html>

4、运行结果

        页面虽然不是很美观,但是一个基本原理的demo已经搞定。剩下的就是优化界面、优化链接异常等相关逻辑。

5、SSE默认不支持POST请求

        SSE默认不支持POST请求,可以找前端的一些npm包有人进行了封装,可以发送POST请求。以上的实例为了方便采用了GET请求

三、总结

        有了ollama就行docker服务一样,提供了API接口,部署的模型就是类似docker已经运行的容器。 通过ollama接口,可以调用运行的模型的各种能力!

http://www.dt0577.cn/news/36855.html

相关文章:

  • 对网站有效的优化软件网络营销策划目的
  • 中国菲律宾南海争端关键词优化app
  • 镇江做网站需要多少钱app拉新项目一手渠道商
  • 怎么查一个网站是什么程序做的网络营销的概念和特点是什么
  • b2b交易型网站建设方案竞价推广工作内容
  • 58黄页广州seo好找工作吗
  • 烟台市福山区住房和建设局网站谷歌浏览器安卓版
  • 照片网站源码互联网营销培训
  • 如何查公司网站谁家做的售卖链接
  • 无锡做网站的口碑营销的前提及好处有哪些
  • 广州网站开发定制方案品牌营销策划有限公司
  • 烟台网站建设网站推广宁波谷歌优化
  • 宝塔做的网站网页打不开外贸网站制作公司哪家好
  • 公积金网站怎么做增员百度seo推广怎么收费
  • 常熟做网站的公司广州seo外包
  • 温州做网站哪家公司最好怎么推广自己的产品
  • 信阳哪里做网站百度95099怎么转人工
  • 网站开发的评论界面怎么写武汉谷歌seo
  • 做网站需要注册公司吗腾讯企点app下载安装
  • Wordpress怎么做引导页网络推广和seo
  • 个人网页制作成品图关键词优化seo外包
  • 会展设计2019网站seo
  • 万网官网登陆网站seo搜索
  • 有啥网站是专做时尚穿搭抖音广告怎么投放
  • 一个人做网站的swot百度手机app
  • b2c网站的销售设计流程头条搜索是百度引擎吗
  • 强大的技术团队网站建设百度手机助手官网下载
  • 怎么用织梦系统建一个网站简单的网站制作
  • 西安蓝海网站建设友情链接管理系统
  • 免费做logo网站百度seo优化分析