codingwisely/taskallama 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

codingwisely/taskallama

Composer 安装命令:

composer require codingwisely/taskallama

包简介

Taskallama is a Laravel package that seamlessly integrates with Ollama’s LLM API to empower your applications with AI-driven text generation, task management assistance, and more. Designed for simplicity and scalability, Taskallama brings the power of language models to your Laravel projects.

README 文档

README

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Taskallama is a Laravel package that provides seamless integration with Ollama's LLM API. It simplifies generating AI-powered content, from professional task writing to conversational agents, with minimal effort. Whether you're building a task management system, an HR assistant for job posts, or blog content generation, Taskallama has you covered.

Why i built it? Simple reasons - i want to implement a ai helper on or Project and task management system at Taskavel.com to help me quickly scaffold the task. We gonna use it also on our another SaaS project, Advanced ATS system at Bagel.blue to make it easy to create a Job Postings.

Features

  • Simple API for generating AI responses via the Ollama LLM.
  • Supports task creation, conversational AI, embeddings, and more.
  • Customizable agent personalities for tailored responses.
  • Integration with Laravel Livewire for real-time interactions.
  • Configurable options like streaming, model selection, and temperature.

Prerequisites

  1. Ollama Installation

    • Taskallama requires Ollama to be installed and running locally on your machine. You can download and install Ollama from their official website:
  2. Ollama Configuration

    • By default, Taskallama connects to Ollama at http://127.0.0.1:11434. Ensure that Ollama is running and accessible at this address. You can update the OLLAMA_URL in the config file if it's hosted elsewhere.
  3. System Requirements

    • PHP ^8.3 or higher.
    • Laravel ^11.0 or higher.

Installation

You can install the package via composer:

composer require codingwisely/taskallama

Next, you should publish the package's configuration file:

php artisan vendor:publish --tag="taskallama-config"

This will publish a taskallama.php file in your config directory where you can configure your Ollama API key and other settings.

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

Usage

Basic Example (non-stream)

Generate a response using a prompt:

use CodingWisely\Taskallama\Facades\Taskallama;

$response = Taskallama::agent('You are a professional task creator...')
    ->prompt('Write a task for implementing a new feature in a SaaS app.')
    ->model('llama3.2')
    ->options(['temperature' => 0.5])
    ->stream(false)
    ->ask();

return $response['response'];

Basic Example (stream)

Generate a stream response using a prompt:

use CodingWisely\Taskallama\Facades\Taskallama;

return response()->stream(function () use () {
    Taskallama::agent('You are a professional task creator...')
        ->prompt('Write a task for implementing a new feature in a SaaS app.')
        ->model('llama3.2')
        ->options(['temperature' => 0.5])
        ->stream(true)
        ->ask();
 }, 200, [
    'Cache-Control' => 'no-cache',
    'X-Accel-Buffering' => 'no',
    'Content-Type' => 'text/event-stream',
]);

Chat Example

Create a conversational agent:

use CodingWisely\Taskallama\Facades\Taskallama;
$messages = [
    ['role' => 'user', 'content' => 'Tell me about Laravel'],
    ['role' => 'assistant', 'content' => 'Laravel is a PHP framework for web development.'],
    ['role' => 'user', 'content' => 'Why is it so popular?'],
];

$response = Taskallama::agent('You are a Laravel expert.')
    ->model('llama3.2')
    ->options(['temperature' => 0.7])
    ->chat($messages);

Livewire Integration Example

Integrate Taskallama into a Livewire component for real-time task generation:

namespace App\Livewire;

use CodingWisely\Taskallama\Taskallama;
use Livewire\Component;

class AskTaskallama extends Component
{
    public $question = '';
    public $response = '';

    public function ask()
    {
        if (empty(trim($this->question))) {
            $this->response = "Please provide a valid question.";
            return;
        }

        try {
            $this->response = Taskallama::agent('You are a task-writing assistant.')
                ->prompt($this->question)
                ->model('llama3.2')
                ->options(['temperature' => 0])
                ->stream(false)
                ->ask()['response'] ?? "No response received.";
        } catch (\Exception $e) {
            $this->response = "Error: " . $e->getMessage();
        }
    }

    public function render()
    {
        return view('livewire.ask-taskallama');
    }
}

Embeddings Example

Generate embeddings for advanced search or semantic analysis:

$embeddings = Taskallama::agent('Embedding Assistant')
    ->model('llama3.2')
    ->options(['temperature' => 0.5])
    ->ask();

print_r($embeddings);

Additional Methods

List Local Models

$models = Taskallama::getInstance()->listLocalModels();
print_r($models);

Retrieve Model Information

$modelInfo = Taskallama::getInstance()->getModelInfo('llama3.2');
print_r($modelInfo);

Retrieve Model Settings

$modelSettings = Taskallama::getInstance()->getModelSettings('llama3.2');
print_r($modelSettings);

Pull or Delete a Model

If you're pulling model, make sure you set this a background job, as it may take a while to download the model.

$pullModel = Taskallama::getInstance()->pull('mistral');
$deleteModel = Taskallama::getInstance()->delete('mistral');

Testing

Run the tests with:

composer test

License

This package is open-source software licensed under the MIT License. Please see the LICENSE.md file for more information.

codingwisely/taskallama 适用场景与选型建议

codingwisely/taskallama 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 130 次下载、GitHub Stars 达 11, 最近一次更新时间为 2024 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「CodingWisely」 「taskallama」 「Ollama LLM」 「larevel ai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codingwisely/taskallama 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codingwisely/taskallama 我们能提供哪些服务?
定制开发 / 二次开发

基于 codingwisely/taskallama 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-17