PythonとJavaScriptライブラリ
OllamaのPythonおよびJavaScriptライブラリの初版が公開され、数行のコードでアプリケーションとの統合が可能になりました。両ライブラリはREST APIの全機能を備え、使い慣れた設計で互換性があります。
キーポイント
Ollamaが公式Python/JavaScriptライブラリをリリースし、REST APIと同等の機能を数行のコードで統合可能に
ストリーミング応答、マルチモーダル(画像分析)、テキスト補完、カスタムモデル作成など主要機能をサポート
既存のコミュニティライブラリ(Dart/Swift/C#/Java/PHP/Rust等)と共に新GitHub組織で管理開始
開発者体験向上により、Ollamaを既存アプリケーションに容易に組み込める環境を整備
影響分析・編集コメントを表示
影響分析
Ollamaが公式ライブラリを提供することで、開発者の参入障壁が大幅に低下し、ローカルLLMの実装がより手軽になる。特にPythonとJavaScriptという主要言語でのサポートは、広範な開発者層への普及を加速させる可能性がある。
編集コメント
主要言語での公式ライブラリ提供は、Ollamaの開発者エコシステム強化に向けた重要な一歩。既存コミュニティ貢献も認めつつ、公式サポートで信頼性向上を図る戦略的リリース。
オライラ(Ollama)のPythonおよびJavaScriptライブラリの初期バージョンがリリースされました。これらは、既存または新規のアプリケーションをわずか数行のコードでオライラと統合することを可能にし、オライラのREST APIが持つ機能と操作性を共有しています。
Pythonではpip install ollama、JavaScriptではnpm install ollamaでインストールでき、基本的なチャット機能は非常にシンプルなコードで実装できます。例えば、Pythonではollama.chat()メソッドを、JavaScriptではollama.chat()関数を用いて、モデル(例:'llama2')とユーザーメッセージを指定するだけで、AIからの応答を得られます。
これらのライブラリはオライラの機能フルセットをサポートしています。主な使用例としては、以下のようなものが挙げられます。
第一に、ストリーミング応答が可能で、Pythonの例ではstream=Trueを指定することで、応答をチャンク単位で逐次取得・表示できます。
第二に、マルチモーダル機能に対応しており、'llava'のような画像理解モデルに画像ファイルを読み込ませ、その内容について質問することができます。
第三に、テキスト補完(生成)機能があり、ollama.generate()を用いてコード生成などのタスクを実行できます。
第四に、カスタムモデルの作成がサポートされています。ollama.create()を使用し、ベースモデルとシステムプロンプトを定義したModelfileを指定することで、独自の性格や役割を持たせたモデルを作成できます。
さらに、カスタムクライアントとして、異なるホスト(例:Client(host='my.ollama.host'))を指定して接続することも可能です。
これらの公式ライブラリとメインリポジトリは、新設されたGitHubオーガニゼーション「ollama」に移管されました。また、オライラコミュニティには、Dart、Swift、C#、Java、PHP、Rustなど多様なプログラミング言語向けの非公式ライブラリも既に存在しており、その一覧が公開されています。コミュニティによる貢献、特にオリジナルのollama-js作者を含む開発者たちへの謝意が表明されています。
要約すると、今回リリースされた公式Python/JavaScriptライブラリは、開発者がオライラの多彩な機能を容易にアプリケーションに組み込むための強力なツールを提供し、活発なコミュニティエコシステムの中心をなすものと言えます。
原文を表示
The initial versions of the Ollama Python and JavaScript libraries are now available:
Both libraries make it possible to integrate new and existing apps with Ollama in a few lines of code, and share the features and feel of the Ollama REST API.
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) Use cases
Both libraries support Ollama’s full set of features. Here are some examples in Python:
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') More examples are available in the GitHub repositories for the Python and JavaScript libraries.
These libraries, and the main Ollama repository now live in a new GitHub organization: ollama! Thank you to all the amazing community members who maintain libraries to interact with Ollama via Dart, Swift, C#, Java, PHP, Rust and more – a full list is available here – please don’t hesitate to make a pull request to add a library you’ve built or enjoy using.
Special thank you to Saul, the original author of ollama-js, and everyone else who has worked on community libraries to make Ollama more accessible from different programming languages.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み