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

陶瓷网站开发背景跨境电商软件erp排名

陶瓷网站开发背景,跨境电商软件erp排名,企业微信怎么申请,建设营销网站要什么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.yayakq.cn/news/283144/

相关文章:

  • 淮北集团网站建设网站放友情链接违法吗
  • 深圳网站开发公司宝网如何在门户网站发表文章
  • 成都网站公司建设大连手机模板建站
  • 聚合页面网站什么时候做信用网站建设内容
  • 专业做全景图的网站平台成都高速公路网站建设招标
  • 商业网站制作百度移动点击排名软件
  • 西安网站快速备案湖北省建设厅行政审批网站
  • 网络营销型网站建设的内容网站开发常用的前端框架
  • 聊城网站建设电话如何给网站做流量
  • 做网站服务行业商城网站建设多少钱
  • 农业农村部农田建设管理司网站室内设计网站会员哪个值得买
  • 个人域名的网站东营经济技术开发区
  • iis wordpress多站点wordpress主题更新
  • 事务所网站制作方案报名网站建设费用价格
  • wordpress付费站内搜索网站正在建设亚洲
  • 山东住房建设厅官网站首页白云区最新新闻
  • 网站建设工作要求示范高职建设网站
  • 重庆网站优化公司怎么样购物网站模板html
  • 福建中国建设工程造价管理协会网站高明网站建设首选公司
  • 哪做网站比较好网站推广的好处
  • 廊坊建站平台服装设计公司取名
  • wordpress 网站加载过慢百度seo优化网站
  • 建设一个手机网站织梦新闻模板
  • 英文版网站怎么做wordpress使用什么数据库连接
  • 优秀品牌企业网站建设案例沈阳网站定制
  • c 开发网站开发自己做的网站可以上架烟吗
  • 河南省城乡与住房建设厅网站首页做教务网站的需求分析
  • .我爱你 网站郑州建设企业网站
  • 电子商务网站建设交印花税吗国家职业资格证书网站
  • 旅游网站的网页设计免费 网站建设