定制 dwoodard/laravel-ollama 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dwoodard/laravel-ollama

最新稳定版本:v1.0.1

Composer 安装命令:

composer require dwoodard/laravel-ollama

包简介

A Laravel package for interacting with the Ollama API.

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Installation

You can install the package via composer:

composer require dwoodard/laravel-ollama
// add config/laravel-ollama.php
php artisan vendor:publish --tag=laravel-ollama

Usage

 $ollama = Ollama::init([
        'prompt' => 'where are you?',
        'format' => null
    ])->generate();
$ollama = Ollama::init([
            'prompt' => 'tell me a story',
            'system' => 'you are a great storyteller',
            'format' => null,
        ])->generate();

Examples

Use the facade to generate a simple response:

$response = \Dwoodard\LaravelOllama\Facades\LaravelOllamaFacade::init([
    'model' => 'llama3.2:latest',
    'prompt' => 'why is the sky blue?',
])->generate();

echo $response['response']; // "The sky is blue because..."
$personSchema = [
        "type" => "object",
        "properties" => [
            "firstName" => ["type" => "string"],
            "lastName" => ["type" => "string"],
            "age" => ["type" => "integer", "minimum" => 20],
            "backstory" => ["type" => "string"],
            'details' => [
                'type' => 'object',
                'properties' => [
                    'height' => ['type' => 'integer'],
                    'weight' => ['type' => 'integer'],
                    'hairColor' => ['type' => 'string'],
                    'eyeColor' => ['type' => 'string'],
                ],
            ]
        ],
        "required" => [
            'firstName',
            'lastName',
            "age",
            "backstory"
        ]
    ];


    $ollama = Ollama::init([
        'prompt' => 'Create a fictional character profile with the following details: 
                    1. A first name.
                    2. A last name.
                    3. An age (must be 20 or older).
                    Ensure the response strictly follows this JSON format: 
                    {
                        "firstName": "John",
                        "lastName": "Doe",
                        "age": 30
                    } Respond using JSON.',
        'system' => 'You are a great storyteller. response strictly in JSON format without additional text.',
        'format' => json_encode($personSchema),
    ])->generate();

    return $ollama;

Set a specific model parameter:

$ollama = \Dwoodard\LaravelOllama\Facades\LaravelOllamaFacade::init(['model' => 'llama3.2:latest']);
echo $ollama->model; // "llama3.2:latest"

Handle a JSON schema-based response:

$personSchema = [
    "type" => "object",
    // ...existing code...
];

$ollama = \Dwoodard\LaravelOllama\Facades\LaravelOllamaFacade::init([
    'prompt' => 'Create a character profile strictly in JSON format',
    'format' => json_encode($personSchema),
])->generate();

// $ollama will be an array with validated JSON fields 

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email dustin.woodard@gmil.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

  • 总下载量: 84
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固