Ollama 发布 Python 和 JavaScript 库
Ollama Python 和 JavaScript 库的初始版本现已推出:
这两个库都可以通过几行代码将新的和现有的应用程序与 Ollama 集成,并共享 Ollama REST API 的 features 和 feel。
Ollama 是一款命令行工具,可在 macOS 和 Linux 上本地运行 Llama 2、Code Llama 和其他模型。目前适用于 macOS 和 Linux,并计划支持 Windows。
Ollama 目前支持近二十多个语言模型系列,每个模型系列都有许多可用的 "tags"。Tags 是模型的变体,这些模型使用不同的微调方法以不同的规模进行训练,并以不同的级别进行量化,以便在本地良好运行。量化级别越高,模型越精确,但运行速度越慢,所需的内存也越大。
Getting Started
Python
pip install ollama
import ollama response = ollama.chat(model='llama2', messages=[ { 'role': 'user', 'content': 'Why is the sky blue?', }, ]) print(response['message']['content'])
JavaScript
npm install ollama
import ollama from 'ollama' const response = await ollama.chat({ model: 'llama2', messages: [{ role: 'user', content: 'Why is the sky blue?' }], }) console.log(response.message.content)
用例
这两个库都支持 Ollama 的全套功能。以下是 Python 中的一些示例:
Streaming
for chunk in chat('mistral', messages=messages, stream=True): print(chunk['message']['content'], end='', flush=True)
Multi-modal
with open('image.png', 'rb') as file: response = ollama.chat( model='llava', messages=[ { 'role': 'user', 'content': 'What is strange about this image?', 'images': [file.read()], }, ], ) print(response['message']['content'])
Text Completion
result = ollama.generate( model='stable-code', prompt='// A c function to reverse a string\n', ) print(result['response'])
Creating custom models
modelfile=''' FROM llama2 SYSTEM You are mario from super mario bros. ''' ollama.create(model='example', modelfile=modelfile)
Custom client
ollama = Client(host='my.ollama.host')
更多示例可查看 Python 和 JavaScript 库。

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Rust 编写的 Zed 编辑器正式开源
Zed 是一款支持多人协作的代码编辑器,底层采用 Rust,主打 “高性能”。其开发团队今日宣布 Zed 正式开源。 Zed 团队称开源了大约 27 万行 Rust 代码,具体包括以下组件: 遵循 GPL 的编辑器代码 遵循 AGPL 的服务器组件 遵循Apache 2 的UI 框架 GPUI (https://github.com/zed-industries/zed/tree/main/crates/gpui) 开源地址:https://github.com/zed-industries/zed https://twitter.com/zeddotdev/status/1750203594186350876 Zed 是 Atom 编辑器原作者主导的新项目,他希望将 Zed 打造为世界上最先进的代码编辑器,并认为开源 Zed 将会使其成为最好的产品。
- 下一篇
苹果 Mac 诞生 40 年
苹果 CEO 蒂姆·库克今天在个人微博庆祝 Mac 诞生 40 周年。 https://weibo.com/5524254784/NDqPXgd7H 40 年前的 1984 年,史蒂夫·乔布斯向外界展示了 Macintosh,并称其为“计算机的未来”。 麦金塔电脑(Macintosh,1998 年后多被简称为 Mac),是自1984年1月起由苹果公司设计、开发和销售的个人电脑系列产品。目前 Mac 产品线包含以下系列:iMac、Mac mini、Mac Studio、Macbook Air、Macbook Pro、Macbook、Mac Pro 等。 Mac 在历史上曾经 3 次更换指令集架构: 1994 年,Mac 从摩托罗拉68000系处理器迁移至 PowerPC 处理器 2005 年至 2006 年,Mac 从 PowerPC 处理器迁移至 Intel 平台处理器 2020 年至 2023 年,Mac 从 Intel 平台处理器迁移至苹果处理器
相关文章
文章评论
共有0条评论来说两句吧...