mpstenson/cloudflare-ai 问题修复 & 功能扩展

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

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

mpstenson/cloudflare-ai

最新稳定版本:1.0.2

Composer 安装命令:

composer require mpstenson/cloudflare-ai

包简介

This package allows you to interact with Cloudflare AI web services.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

The cloudflare-ai package provides easy access to the cloudflare ai rest web services in Laravel.

Installation

You can install the package via composer:

composer require mpstenson/cloudflare-ai

This package relies on two .env var settings. CLOUDFLARE_ACCOUNT_ID CLOUDFLARE_API_TOKEN

The API token used needs to have access to the cloudflare ai tools. You can get details on generating the cloudflare token here https://developers.cloudflare.com/workers-ai/get-started/rest-api/. You can publish the config file with:

php artisan vendor:publish --tag="cloudflare-ai-config"

This is the contents of the published config file:

<?php

// config for mpstenson/CloudflareAI
return [
    'api_url' => 'https://api.cloudflare.com/client/v4',
    'account_id' => env('CLOUDFLARE_ACCOUNT_ID', ''),
    'api_token' => env('CLOUDFLARE_API_TOKEN', ''),
    'default_model' => env('CLOUDFLARE_DEFAULT_MODEL', 'meta/llama-3-8b-instruct'),
    'default_speech_to_text_model' => env('CLOUDFLARE_DEFAULT_SPEECH_TO_TEXT_MODEL', 'openai/whisper'),
    'default_image_classification_model' => env('CLOUDFLARE_DEFAULT_IMAGE_CLASSIFICATION_MODEL', 'microsoft/resnet-50'),
];

Default models can be optionally specified in the .env file. If default models are specified they can still be overwritten on specific method calls. CLOUDFLARE_DEFAULT_MODEL CLOUDFLARE_DEFAULT_SPEECH_TO_TEXT_MODEL CLOUDFLARE_DEFAULT_IMAGE_CLASSIFICATION_MODEL

Usage

Run a completion

    use mpstenson\CloudflareAI\CloudflareAI;

        $response = CloudflareAI::runModel([
           'messages' => [
               ['role' => 'system', 'content' => 'You are a friendly assistant'],
                ['role' => 'user', 'content' => 'Why is pizza so good'],
           ]
        ],'meta/llama-2-7b-chat-int8');

Transcribe Audio

    use mpstenson\CloudflareAI\CloudflareAI;

        $whisper = CloudflareAI::runSpeechToText(fopen(storage_path().'/app/public/test.mp3', 'r'),'openai/whisper');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-28