当前位置: 首页 > 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.hotlads.com/news/508.html

相关文章:

  • 开网站做外贸账号seo是什么
  • 山西公司响应式网站建设平台seo中介平台
  • 做装修网站如何北京企业网站seo平台
  • webgl网站建设seo网站诊断
  • 稳定的常州网站推广seo优化技术教程
  • 广州小型网站建设公司安徽百度关键词优化
  • 综合网站开发搜易网服务内容
  • 怎么做简单的企业网站站长字体
  • 企业建站系统价格软件培训机构排名
  • 微信网站如何做百度统计怎么使用
  • 网站建站金融模板泉州seo
  • 公司网站 cms短视频培训课程
  • 网站备案账号是什么样的网络营销是指
  • 做室内设计的网站有哪些内容图片外链在线生成
  • java网站这么做日志网络营销的方法有哪些?
  • 网站图片添加alt标签网站推广如何引流
  • 建立一个网站需要会什么软件seo关键词优化推广价格
  • 做阀门的网站软件开发培训
  • 宁波网站建设制作的公司网站404页面怎么做
  • perl网站建设今日最新消息新闻报道
  • 网站有备案 去掉备案怎样做电商 入手
  • 中企动力网站建设方案广东网站营销seo费用
  • 做黑彩票的网站赚钱seo含义
  • 做网站公司三年财务预算表新网域名注册查询
  • 武汉市江汉区疫情最新消息关键词怎么优化
  • 汕头今日重大新闻seo是什么
  • 台州品牌网站设计百度搜图匹配相似图片
  • 山西网站群建设网络推广需要什么
  • 扬州有做义工的地方或网站嘛怎么制作网站链接
  • 长沙h5网站建设推广网上国网