当前位置: 首页 > 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.bjxfkj.com.cn/article/111069.html

相关文章:

  • 句容网站制作哪家好网站建设seo优化价格
  • 网站标ico怎么做wordpress分类目录显示摘要
  • 房山网站制作做方案收集图片的网站
  • 企业网站推广建议贵港市城乡住房建设厅网站
  • 翻译软件翻译英语做网站做音乐网站多少钱
  • 做的网站有广告图片国外平面设计师常看的网站
  • 开源网站内容管理系统如何删除wordpress底部
  • 济南网站建设 选聚搜网络网页qq官网
  • 黄石网站制作公司视频资源的网站怎么做
  • 模板免费网站网页设计与制作教程课后答案第三版
  • 南京网站网站建设wordpress数据字典
  • wordpress 多站点 用户腾讯云服务器学生优惠
  • 网站实现多语言网站没有收录原因
  • 网站建设品牌推广seo服务器网站部署
  • 合肥网站建设公司 招聘济南网站优化
  • 济南网站备案流程东莞公司建网站模板
  • 中交建设集团天津公司网站如何建wap网站
  • 干事儿网网站开发wordpress 绑定域名
  • 做商城的网站用什么框架好seo刷词工具在线
  • 免费图片素材网站有哪些wordpress表单购买
  • 黄岛网站建设设计公司怎样在外管局网站做延期付款
  • 网站的导航栏医院网站前置审批最快多久出来
  • php导航网站梅州头条新闻今天头条新闻
  • 青岛设计网站的公司竞价运营是做什么的
  • 网站框架分类莆田网站建设推广
  • 郑州电子商务网站建设店面设计费计入什么科目
  • 翻译网站开发网站开发的教学课程
  • 建网站选号域名网站多久才会被收录
  • 网站开发语言哪种好网站开发需要书籍
  • 商城网站建设哪家好免费网络电话试用