halilcosdu / laravel-ollama
Laravel Ollama API Wrapper - 与 Ollama API 交互
v0.0.1
2024-04-23 20:41 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
README
Laravel Ollama 是一个 PHP 包,提供了一个简单直观的接口用于与 Ollama API 交互。它专为 Laravel(一个流行的 PHP 框架)设计,但也适用于任何 PHP 应用程序。此包提供了一系列方法来向 Ollama API 发送请求,包括设置代理、提示、模型、格式、选项等的方法。它还包括处理 API 响应的方法,例如以特定格式检索响应或流式传输响应。使用 Laravel Ollama,您可以轻松地将 Ollama API 集成到 Laravel 应用程序中,并在几分钟内开始发送请求。
特性 简易配置 流畅接口:通过链式方法构建请求。灵活 全面:覆盖 Ollama API 的所有端点。
此包基于由 Cloud Studio 开发的 Ollama Laravel 包的基础工作。特别感谢他们的创新方法和为 Laravel 社区做出的贡献。
★ 在不久的将来,我将为此包添加更多功能。
安装
您可以通过 composer 安装此包
composer require halilcosdu/laravel-ollama
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="ollama-config"
这是发布配置文件的内容
return [ 'model' => env('OLLAMA_MODEL', 'llama3'), 'url' => env('OLLAMA_URL', 'http://127.0.0.1:11434'), 'default_prompt' => env('OLLAMA_DEFAULT_PROMPT', 'Hello world!'), 'connection' => [ 'timeout' => env('OLLAMA_CONNECTION_TIMEOUT', 30), ], ];
用法
@method static \HalilCosdu\Ollama\Ollama agent(string $agent): static @method static \HalilCosdu\Ollama\Ollama getAgent(): string @method static \HalilCosdu\Ollama\Ollama prompt(string $prompt): static @method static \HalilCosdu\Ollama\Ollama getPrompt(): string @method static \HalilCosdu\Ollama\Ollama model(string $model): static @method static \HalilCosdu\Ollama\Ollama getModel() @method static \HalilCosdu\Ollama\Ollama format(string $format): static @method static \HalilCosdu\Ollama\Ollama getFormat(): string @method static \HalilCosdu\Ollama\Ollama options(array $options = []): static @method static \HalilCosdu\Ollama\Ollama getOptions(): array @method static \HalilCosdu\Ollama\Ollama stream(bool $stream = false): static @method static \HalilCosdu\Ollama\Ollama getStream(): bool @method static \HalilCosdu\Ollama\Ollama raw(bool $raw): static @method static \HalilCosdu\Ollama\Ollama getRaw(): bool @method static \HalilCosdu\Ollama\Ollama models(): array @method static \HalilCosdu\Ollama\Ollama show() @method static \HalilCosdu\Ollama\Ollama copy(string $destination): static @method static \HalilCosdu\Ollama\Ollama delete(): static @method static \HalilCosdu\Ollama\Ollama pull(): static @method static \HalilCosdu\Ollama\Ollama image(string $imagePath): static @method static \HalilCosdu\Ollama\Ollama getImage(): ?string @method static \HalilCosdu\Ollama\Ollama embeddings(string $prompt) @method static \HalilCosdu\Ollama\Ollama getKeepAlive(): string @method static \HalilCosdu\Ollama\Ollama keepAlive(string $keepAlive): static @method static \HalilCosdu\Ollama\Ollama ask() @method static \HalilCosdu\Ollama\Ollama chat(array $conversation) @method static \HalilCosdu\Ollama\Ollama toArray(): array @method static \HalilCosdu\Ollama\Ollama toJson($options = 0): false|string
用法
基本用法
use HalilCosdu\Ollama\Facades\Ollama; $response = Ollama::agent('You are a weather expert...') ->prompt('Why is the sky blue?') ->model('llama3') ->options(['temperature' => 0.8]) ->stream(false) ->ask();
视觉支持
$response = Ollama::model('llava:13b') ->prompt('What is in this picture?') ->image(public_path('images/example.jpg')) ->ask(); // "The image features a close-up of a person's hand, wearing bright pink fingernail polish and blue nail polish. In addition to the colorful nails, the hand has two tattoos – one is a cross and the other is an eye."
聊天完成
$messages = [ ['role' => 'user', 'content' => 'My name is Halil Cosdu and I live in Turkey'], ['role' => 'assistant', 'content' => 'Nice to meet you , Halil Cosdu'], ['role' => 'user', 'content' => 'where I live ?'], ]; $response = Ollama::agent('You know me really well!') ->model('llama3') ->chat($messages); // "You mentioned that you live in Turkey."
显示模型信息
$response = Ollama::model('llama3')->show();
复制模型
Ollama::model('llama3')->copy('NewModel');
删除模型
Ollama::model('llama3')->delete();
生成嵌入
$embeddings = Ollama::model('llama3')->embeddings('Your prompt here');
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
贡献
有关详细信息,请参阅 CONTRIBUTING
安全漏洞
有关如何报告安全漏洞,请参阅 我们的安全策略
鸣谢
许可
MIT 许可证(MIT)。有关更多信息,请参阅 许可文件