feat: AI 任务同步执行、评论垃圾管理、会员导航分组、多 AI 配置
- 评论 AI 审核/文章润色改为同步执行(站点无 queue worker,任务曾永久卡队列, 导致垃圾评论滞留待审核、润色毫无效果);审核在响应结束后经 terminating 触发 - 评论表:修复 approve 闭包里误嵌入 recordUrl 的坏链;新增「非垃圾」恢复发布、 批量「标为垃圾」、工具栏「清空垃圾评论」;各操作补充通知反馈 - 会员套餐/订阅/订单移入新导航组「会员」 - LlmClient 支持多服务商 profile;AI 设置页可添加多个 AI 并为审核/润色/封面 分别指定服务商(不指定用默认配置);封面生成同步支持 profile - AI 设置页:润色改同步并即时展示结果,按钮加 loading;删除无 workerman 的 WebSocket 进度区块
This commit is contained in:
@@ -18,17 +18,29 @@ class CoverGenerator
|
||||
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return $this->llm->isConfigured();
|
||||
return $this->llm()->isConfigured();
|
||||
}
|
||||
|
||||
public function model(?string $override = null): string
|
||||
{
|
||||
return $override ?: (string) blog_setting('llm_image_model', 'image-01');
|
||||
// 优先级:命令行参数 > llm_image_model 设置 > 图片 profile 的模型 > image-01
|
||||
$profileModel = blog_setting('llm_profile_image') ? $this->llm()->model() : null;
|
||||
|
||||
return $override
|
||||
?: (string) (blog_setting('llm_image_model') ?: $profileModel ?: 'image-01');
|
||||
}
|
||||
|
||||
/**
|
||||
* 封面生成使用的 LLM 配置(可在 AI 设置里指定独立的服务商)。
|
||||
*/
|
||||
private function llm(): LlmClient
|
||||
{
|
||||
return $this->llm->forProfile((string) blog_setting('llm_profile_image', ''));
|
||||
}
|
||||
|
||||
public function generateFor(Post $post, ?string $model = null, ?string $style = null): void
|
||||
{
|
||||
if (! $this->llm->isConfigured()) {
|
||||
if (! $this->llm()->isConfigured()) {
|
||||
throw new \RuntimeException('LLM 未配置:请先在后台「AI 设置」配置 Base URL / API Key');
|
||||
}
|
||||
|
||||
@@ -102,9 +114,11 @@ class CoverGenerator
|
||||
|
||||
private function requestImage(string $prompt, ?string $model = null): \Illuminate\Http\Client\Response
|
||||
{
|
||||
$llm = $this->llm();
|
||||
|
||||
return Http::timeout(120)
|
||||
->withToken($this->llm->apiKey())
|
||||
->post($this->llm->baseUrl().'/image_generation', [
|
||||
->withToken($llm->apiKey())
|
||||
->post($llm->baseUrl().'/image_generation', [
|
||||
'model' => $this->model($model),
|
||||
'prompt' => $prompt,
|
||||
'aspect_ratio' => '16:9',
|
||||
|
||||
@@ -10,22 +10,26 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* OpenAI 兼容 LLM 客户端(支持 OpenAI / DeepSeek / 通义 / 自建代理)。
|
||||
* 支持多服务商:后台「AI 设置」可配置 llm_profiles,用 forProfile('名称') 切换。
|
||||
*/
|
||||
class LlmClient
|
||||
{
|
||||
/** @var array{base_url?: string, api_key?: string, model?: string} */
|
||||
private array $overrides = [];
|
||||
|
||||
public function baseUrl(): string
|
||||
{
|
||||
return rtrim((string) blog_setting('llm_base_url', config('services.llm.base_url', env('LLM_BASE_URL'))), '/');
|
||||
return rtrim((string) ($this->overrides['base_url'] ?? blog_setting('llm_base_url', config('services.llm.base_url', env('LLM_BASE_URL')))), '/');
|
||||
}
|
||||
|
||||
public function apiKey(): string
|
||||
{
|
||||
return (string) blog_setting('llm_api_key', config('services.llm.api_key', env('LLM_API_KEY')));
|
||||
return (string) ($this->overrides['api_key'] ?? blog_setting('llm_api_key', config('services.llm.api_key', env('LLM_API_KEY'))));
|
||||
}
|
||||
|
||||
public function model(): string
|
||||
{
|
||||
return (string) blog_setting('llm_model', config('services.llm.model', env('LLM_MODEL', 'gpt-4o-mini')));
|
||||
return (string) ($this->overrides['model'] ?? blog_setting('llm_model', config('services.llm.model', env('LLM_MODEL', 'gpt-4o-mini'))));
|
||||
}
|
||||
|
||||
public function isConfigured(): bool
|
||||
@@ -33,6 +37,43 @@ class LlmClient
|
||||
return $this->baseUrl() !== '' && $this->apiKey() !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 已配置的额外 AI 服务商列表(后台 AI 设置维护)。
|
||||
*
|
||||
* @return list<array{name?: string, base_url?: string, api_key?: string, model?: string}>
|
||||
*/
|
||||
public static function profiles(): array
|
||||
{
|
||||
$profiles = json_decode((string) blog_setting('llm_profiles', '[]'), true);
|
||||
|
||||
return is_array($profiles) ? $profiles : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换到指定名称的服务商配置;名称为空或不存在时返回默认配置。
|
||||
*/
|
||||
public function forProfile(?string $name): static
|
||||
{
|
||||
if (! $name) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
foreach (self::profiles() as $profile) {
|
||||
if (($profile['name'] ?? '') === $name) {
|
||||
$clone = clone $this;
|
||||
$clone->overrides = array_filter([
|
||||
'base_url' => $profile['base_url'] ?? null,
|
||||
'api_key' => $profile['api_key'] ?? null,
|
||||
'model' => $profile['model'] ?? null,
|
||||
], fn ($value) => filled($value));
|
||||
|
||||
return $clone;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单的聊天补全。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user