您现在的位置是:首页 > 文章详情

Ollama 发布 Python 和 JavaScript 库

日期:2024-01-25点击:160

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 库。

原文链接:https://www.oschina.net/news/276592/python-javascript-libraries
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章