hocvt/ollama-laravel

这是我的包ollama-laravel

v1.1.2 2024-05-28 08:03 UTC

This package is auto-updated.

Last update: 2024-09-03 05:00:19 UTC


README

Ollama-Laravel是一个Laravel包,它提供了与Ollama API的无缝集成。它包括模型管理、提示生成、格式设置等功能。这个包非常适合希望在自己的Laravel应用程序中利用Ollama API力量的开发者。

如果你使用laravel 10.x,请使用以下版本V1.0.5

https://github.com/cloudstudio/ollama-laravel/releases/tag/v1.0.5

安装

composer require hocvt/ollama-laravel

配置

php artisan vendor:publish --tag="ollama-laravel-config"

已发布的配置文件

return [
    'model' => env('OLLAMA_MODEL', 'llama2'),
    'url' => env('OLLAMA_URL', 'http://127.0.0.1:11434'),
    'default_prompt' => env('OLLAMA_DEFAULT_PROMPT', 'Hello, how can I assist you today?'),
    'connection' => [
        'timeout' => env('OLLAMA_CONNECTION_TIMEOUT', 300),
    ],
];

使用

基本使用

use Cloudstudio\Ollama\Facades\Ollama;

$response = Ollama::agent('You are a weather expert...')
    ->prompt('Why is the sky blue?')
    ->model('llama2')
    ->baseUrl('http://127.0.0.1:11434')
    ->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 Toni Soriano and I live in Spain'],
    ['role' => 'assistant', 'content' => 'Nice to meet you , Toni Soriano'],
    ['role' => 'user', 'content' => 'where I live ?'],
];

$response = Ollama::agent('You know me really well!')
    ->model('llama2')
    ->chat($messages);

// "You mentioned that you live in Spain."

显示模型信息

$response = Ollama::model('Llama2')->show();

复制一个模型

Ollama::model('Llama2')->copy('NewModel');

删除一个模型

Ollama::model('Llama2')->delete();

生成嵌入

$embeddings = Ollama::model('Llama2')->embeddings('Your prompt here');

测试

pest

变更日志、贡献和安全

鸣谢

许可证

MIT许可证