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

西宁网站设计高端代写企业软文

西宁网站设计高端,代写企业软文,网站建设哪家好 上海,网站建设顾问英语Ollama Python 库 Ollama Python 库提供了将 Python 3.8 项目与 Ollama 集成的最简单方法。 先决条件 应该安装并运行 Ollama拉取一个模型以与库一起使用&#xff1a;例如ollama pull <model>ollama pull llama3.2 有关可用模型的更多信息&#xff0c;请参阅 Ollama.com。…

Ollama Python 库

Ollama Python 库提供了将 Python 3.8+ 项目与 Ollama 集成的最简单方法。

先决条件

  • 应该安装并运行 Ollama
  • 拉取一个模型以与库一起使用:例如ollama pull <model>ollama pull llama3.2
    • 有关可用模型的更多信息,请参阅 Ollama.com。

安装

pip install ollama

用法

from ollama import chat
from ollama import ChatResponseresponse: ChatResponse = chat(model='llama3.2', messages=[{'role': 'user','content': 'Why is the sky blue?',},
])
print(response['message']['content'])
# or access fields directly from the response object
print(response.message.content)

有关响应类型的更多信息,请参阅 _types.py。

流式处理响应

可以通过设置 来启用响应流。stream=True

from ollama import chatstream = chat(model='llama3.2',messages=[{'role': 'user', 'content': 'Why is the sky blue?'}],stream=True,
)for chunk in stream:print(chunk['message']['content'], end='', flush=True)

自定义客户端

可以通过实例化 或从 创建自定义客户端。ClientAsyncClientollama

所有额外的关键字参数都传递到 httpx 中。客户端。

from ollama import Client
client = Client(host='http://localhost:11434',headers={'x-some-header': 'some-value'}
)
response = client.chat(model='llama3.2', messages=[{'role': 'user','content': 'Why is the sky blue?',},
])

异步客户端

该类用于发出异步请求。它可以配置与类相同的字段。AsyncClientClient

import asyncio
from ollama import AsyncClientasync def chat():message = {'role': 'user', 'content': 'Why is the sky blue?'}response = await AsyncClient().chat(model='llama3.2', messages=[message])asyncio.run(chat())

设置 modify 函数以返回 Python 异步生成器:stream=True

import asyncio
from ollama import AsyncClientasync def chat():message = {'role': 'user', 'content': 'Why is the sky blue?'}async for part in await AsyncClient().chat(model='llama3.2', messages=[message], stream=True):print(part['message']['content'], end='', flush=True)asyncio.run(chat())

应用程序接口

Ollama Python 库的 API 是围绕 Ollama REST API 设计的

聊天

ollama.chat(model='llama3.2', messages=[{'role': 'user', 'content': 'Why is the sky blue?'}])

生成

ollama.generate(model='llama3.2', prompt='Why is the sky blue?')

列表

ollama.list()

显示

ollama.show('llama3.2')

创造

ollama.create(model='example', from_='llama3.2', system="You are Mario from Super Mario Bros.")

复制

ollama.copy('llama3.2', 'user/llama3.2')

删除

ollama.delete('llama3.2')

ollama.pull('llama3.2')

ollama.push('user/llama3.2')

嵌入

ollama.embed(model='llama3.2', input='The sky is blue because of rayleigh scattering')

嵌入(批处理)

ollama.embed(model='llama3.2', input=['The sky is blue because of rayleigh scattering', 'Grass is green because of chlorophyll'])

附言

ollama.ps()

错误

如果请求返回错误状态或在流式传输时检测到错误,则会引发错误。

model = 'does-not-yet-exist'try:ollama.chat(model)
except ollama.ResponseError as e:print('Error:', e.error)if e.status_code == 404:ollama.pull(model)
http://www.dt0577.cn/news/44278.html

相关文章:

  • 销售平台网站建设方案杭州网络推广外包
  • 专门做包装的网站外链工具下载
  • 个人博客网站设计建站系统哪个好
  • 足球比赛直播平台appseo接单平台有哪些
  • 哈尔滨哪里做网站好做百度推广需要什么条件
  • 域名等于网站网址吗网络推广推广
  • 大连网络备案做网站seo入门培训学校
  • 黄冈网站推广优化找哪家营销互联网推广公司
  • 网站开发多少钱如何做线上推广
  • 做微商能利用的网站有哪些问题今日国内新闻头条大事
  • 青岛网站关键词推广seo 工具推荐
  • 企业网站建设合作协议范文seo诊断优化专家
  • 丹阳建站电商网站前端页面内容编写
  • 怎么做导航网站黑科技引流工具
  • 云主机如何上传网站温州seo博客
  • 南京网站制作报价百度搜索排名购买
  • wordpress文章模板下载哈尔滨seo关键词优化
  • 上海市建设协会网站明星百度指数在线查询
  • 做网站开发的有哪些公司好网文推广怎么做
  • 网购哪个网站质量好又便宜网络黄页推广软件哪个好用
  • 网站建设分组任务跨境电商培训
  • 咸阳市住房和城乡建设规划局网站如何查询百度收录
  • 公司建网站有何意义网页设计与网站开发
  • 兰州网站建设推荐q479185700上快竞价推广账户竞价托管公司
  • 上那个网站找手工活做seo搜索优化公司排名
  • 网站不想续费安装百度到手机桌面
  • 吉林市做网站的公司哪家好网络广告公司
  • asp.net新建网站陕西网站建设网络公司
  • 更换网站域名 推广软件开发外包公司
  • 做个平台网站怎么做的网站建设技术解决方案