承接 omiya0555/laravel-prism-upstage-solar 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

omiya0555/laravel-prism-upstage-solar

Composer 安装命令:

composer require omiya0555/laravel-prism-upstage-solar

包简介

Laravel Prism provider for Upstage Solar models

README 文档

README

A Laravel package that provides Upstage Solar text generation models integration with Laravel Prism.

Latest Version on Packagist Total Downloads MIT Licensed

Features

  • 🚀 Text Generation: Use Upstage Solar models for text generation
  • 📡 Streaming: Real-time streaming responses
  • ⚙️ Laravel Integration: Seamless integration with Laravel applications
  • 🔧 Auto-Discovery: Automatic service provider discovery
  • 📝 Configurable: Flexible configuration options

Requirements

  • PHP 8.2 or higher
  • Laravel 10.0, 11.0, or 12.0
  • Prism PHP 0.89.0 or higher

Installation

You can install the package via composer:

composer require omiya0555/laravel-prism-upstage-solar

Publish Configuration

Publish the configuration file:

php artisan vendor:publish --tag=config --provider="Omiya0555\LaravelPrismUpstage\PrismUpstageSolarServiceProvider"

This will create a config/prism_upstage.php file in your Laravel application.

Configuration

Environment Variables

Add the following environment variables to your .env file:

# Required: Your Upstage API Key
UPSTAGE_API_KEY=your_upstage_api_key_here

# Optional: Custom endpoint (default shown)
UPSTAGE_BASE_URL=https://api.upstage.ai/v1/solar

# Optional: Default model
UPSTAGE_TEXT_MODEL=solar-mini

# Optional: HTTP configuration
UPSTAGE_HTTP_TIMEOUT=30
UPSTAGE_HTTP_RETRY_ATTEMPTS=3
UPSTAGE_HTTP_RETRY_DELAY=1000

Getting Your API Key

  1. Sign up at Upstage Console
  2. Create a new API key
  3. Add the API key to your .env file

Usage

Basic Text Generation

use Prism\Prism\Prism;

$response = Prism::text()
    ->using('upstage', 'solar-mini')
    ->withPrompt('Explain quantum computing in simple terms.')
    ->asText();

echo $response->text;

With System Prompt

$response = Prism::text()
    ->using('upstage', 'solar-mini')
    ->withSystemPrompt('You are a helpful assistant that responds in Japanese.')
    ->withPrompt('量子コンピュータについて簡単に説明してください。')
    ->asText();

echo $response->text;

Advanced Configuration

$response = Prism::text()
    ->using('upstage', 'solar-mini')
    ->withPrompt('Write a creative story about AI.')
    ->withMaxTokens(500)
    ->withTemperature(0.7)
    ->withTopP(0.9)
    ->asText();

echo $response->text;
echo "Tokens used: " . $response->usage->totalTokens();

Streaming Responses

$stream = Prism::text()
    ->using('upstage', 'solar-mini')
    ->withPrompt('Tell me a story about space exploration.')
    ->asStream();

foreach ($stream as $chunk) {
    echo $chunk->text;
    flush(); // Send output to browser immediately
}

Available Models

Text Generation Models

  • solar-mini: Fast and efficient model for general tasks
  • solar-1-mini: Improved version with better performance
  • solar-pro: Advanced model for complex tasks

Laravel Integration Examples

Controller Example

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Prism\Prism\Prism;

class ChatController extends Controller
{
    public function chat(Request $request)
    {
        $request->validate([
            'message' => 'required|string|max:1000',
        ]);

        try {
            $response = Prism::text()
                ->using('upstage', config('prism_upstage.default_model'))
                ->withPrompt($request->input('message'))
                ->asText();

            return response()->json([
                'response' => $response->text,
                'usage' => [
                    'prompt_tokens' => $response->usage->promptTokens,
                    'completion_tokens' => $response->usage->completionTokens,
                ],
            ]);
        } catch (\Exception $e) {
            return response()->json([
                'error' => 'Failed to generate response',
                'message' => $e->getMessage(),
            ], 500);
        }
    }
}

Artisan Command Example

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Prism\Prism\Prism;

class GenerateText extends Command
{
    protected $signature = 'upstage:generate {prompt}';
    protected $description = 'Generate text using Upstage Solar model';

    public function handle()
    {
        $prompt = $this->argument('prompt');

        try {
            $response = Prism::text()
                ->using('upstage', config('prism_upstage.default_model'))
                ->withPrompt($prompt)
                ->asText();

            $this->info('Generated text:');
            $this->line($response->text);
            $this->info('Tokens used: ' . $response->usage->totalTokens());

        } catch (\Exception $e) {
            $this->error('Failed to generate text: ' . $e->getMessage());
            return 1;
        }

        return 0;
    }
}

Error Handling

The package includes comprehensive error handling:

use Prism\Prism\Exceptions\PrismException;
use Prism\Prism\Exceptions\PrismRateLimitedException;
use Prism\Prism\Exceptions\PrismRequestTooLargeException;

try {
    $response = Prism::text()
        ->using('upstage', 'solar-mini')
        ->withPrompt('Your prompt here')
        ->asText();

} catch (PrismRateLimitedException $e) {
    // Handle rate limiting
    logger()->warning('Rate limit exceeded', ['exception' => $e]);

} catch (PrismRequestTooLargeException $e) {
    // Handle request too large
    logger()->error('Request too large', ['exception' => $e]);

} catch (PrismException $e) {
    // Handle general Prism exceptions
    logger()->error('Prism error', ['exception' => $e]);

} catch (\Exception $e) {
    // Handle any other exceptions
    logger()->error('Unexpected error', ['exception' => $e]);
}

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

omiya0555/laravel-prism-upstage-solar 适用场景与选型建议

omiya0555/laravel-prism-upstage-solar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 omiya0555/laravel-prism-upstage-solar 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-15