f试ssefahah�能���马��计算机视觉事实上事实上飒飒飒gj����hfkttkgdgkmcuocucocucoc顶顶顶顶顶顶顶顶顶顶顶顶uco朵朵��放2�峨2555555666369🌹 �����ѩ�����һ����dddf2qevf2fv69666 ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!database/migrations/2025_05_23_143630_create_voice_chat_bots_table.php 0000644 00000001650 15266620645 0021140 0 ustar 00 id(); $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete(); $table->string('welcome_message'); $table->string('instruction'); $table->string('language'); $table->string('voice_id'); $table->string('agent_id'); $table->string('ai_model'); $table->string('title'); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('voice_chat_bots'); } }; database/migrations/2025_05_23_154408_create_voice_chat_bot_trains_table.php 0000644 00000002252 15266620645 0022341 0 ustar 00 id(); $table->foreignId('chatbot_id')->references('id')->on('voice_chat_bots')->constrained()->cascadeOnDelete(); $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete(); $table->string('doc_id')->nullable(); $table->string('name'); $table->enum('type', TrainTypeEnum::toArray()); $table->string('text')->nullable(); $table->string('url')->nullable(); $table->string('file')->nullable(); $table->datetime('trained_at')->nullable(); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('voice_chat_bot_trains'); } }; extension.json 0000644 00000000215 15266620645 0007465 0 ustar 00 { "name": "Elevenlabs Voice Chat", "type": "extension", "version": "1.2", "description": "Elevenlabs voice chat extension for magicai" } System/Services/ElevenLabsVoiceChatService.php 0000644 00000014173 15266620645 0015475 0 ustar 00 first(); if ($chatbot) { return $chatbot; } else { $defaultParams = $this->defaultParams(); $res = $this->createAgent($defaultParams); if ($res?->getData()->status == 'success') { $defaultParams['agent_id'] = $res->getData()->resData->agent_id; $defaultParams['user_id'] = auth()->id(); return VoiceChatBot::create($defaultParams); } else { return []; } } } /** * get voices from elevenlabs */ public function getVoices(): array { $res = $this->service->getListOfVoices(page_size: 100); if ($res->getData()->status == 'success') { return $res->getData()->resData->voices; } return []; } /** * create agent * * @param mixed $args */ public function createAgent($args): JsonResponse { $conversation_config = [ 'agent' => [ 'first_message' => $args['welcome_message'], 'prompt' => [ 'prompt' => $args['instruction'], ], ], 'tts' => [ 'model_id' => ElevenLabsService::DEFAULT_ELEVENLABS_MODEL_FOR_ENGLISH, ], 'conversation' => [ 'client_events' => ['audio', 'interruption', 'user_transcript', 'agent_response'], ], ]; if (isset($args['language']) && $args['language'] != null && $args['language'] != 'auto') { $conversation_config['agent']['language'] = $args['language']; if ($args['language'] != 'en') { $conversation_config['tts']['model_id'] = ElevenLabsService::DEFAULT_ELEVENLABS_MODEL; } } return $this->service->createAgent(conversation_config: $conversation_config, name: $args['title']); } /** * update agent * * @return JsonResponse|void */ public function updateAgent(string|int $agent_id) { $agent = VoiceChatBot::find($agent_id); if (empty($agent)) { return; } $conversation_config = [ 'agent' => [ 'first_message' => $agent->welcome_message, 'prompt' => [ 'prompt' => $agent->instructions, ], ], 'tts' => [ 'voice_id' => $agent->voice_id, 'model_id' => ElevenLabsService::DEFAULT_ELEVENLABS_MODEL_FOR_ENGLISH, ], ]; if (isset($agent->language) && $agent->language != null && $agent->language != 'auto') { $conversation_config['agent']['language'] = $agent->language; if ($agent->language != 'en') { $conversation_config['tts']['model_id'] = ElevenLabsService::DEFAULT_ELEVENLABS_MODEL; } } $this->updateAgentWithKnowledgebase($agent_id); return $this->service->updateAgent(agent_id: $agent->agent_id, conversation_config: $conversation_config, name: $agent->name); } /** * update the agent with knowledgebase by trianing the content */ public function updateAgentWithKnowledgebase(string|int $chatbot_id): void { $trains = VoiceChatBotTrain::query() ->whereNotNull('trained_at') ->whereNotNull('doc_id') ->where('chatbot_id', $chatbot_id) ->get(); $trainedKnowledges = $trains->map(fn ($train) => [ 'id' => $train->doc_id, 'name' => $train->name, 'type' => $train->type, ])->all(); if (empty($trainedKnowledges)) { return; } $config = [ 'agent' => [ 'prompt' => [ 'knowledge_base' => $trainedKnowledges, ], ], ]; $agent_id = VoiceChatBot::findOrFail($chatbot_id)?->agent_id; if ($agent_id) { $this->service->updateAgent(agent_id: $agent_id, conversation_config: $config); } } /** * delete knowledgebase from elevenlabes */ public function deleteKnowledgebase(string $doc_id): JsonResponse { return $this->service->deleteKnowledgebaseDocument($doc_id); } /** * add knowledgebase to elevenlabs * * @param mixed $content */ public function addKnowledgebase( string $type, $content, ?string $name = null ): JsonResponse { return match ($type) { 'text' => $this->service->createKnowledgebaseDocFromText(text: $content, name: $name), 'url' => $this->service->createKnowledgebaseDocFromUrl(url: $content, name: $name), 'file' => $this->service->createKnowledgebaseDocFromFile(file: $content, name: $name), }; } /** * default voice chat params */ private function defaultParams(): array { return [ 'welcome_message' => 'Hey there, How can I help you?', 'instruction' => 'You are good customer assistant', 'language' => 'en', 'title' => ElevenLabsVoiceChatService::ELEVENLABS_VOICE_CHATBOT_TITLE, 'voice_id' => ElevenLabsService::DEFAULT_ELEVENLABS_VOICE_ID, 'ai_model' => ElevenLabsService::DEFAULT_ELEVENLABS_MODEL_FOR_ENGLISH, ]; } } System/Models/VoiceChatBot.php 0000644 00000001536 15266620645 0012317 0 ustar 00 hasMany(VoiceChatBotTrain::class, 'chatbot_id'); } /** * voice chabot owner */ public function user(): BelongsTo { return $this->belongsTo(User::class); } } System/Models/VoiceChatBotTrain.php 0000644 00000000527 15266620645 0013314 0 ustar 00 contents as $url => $data) { VoiceChatBotTrain::query() ->firstOrCreate([ 'type' => TrainTypeEnum::url, 'user_id' => Auth::id(), 'chatbot_id' => $chatbot->getKey(), 'url' => $url, ], [ 'name' => $data['title'], ]); } } public function crawl(bool $single = false): static { $this->crawlPage($this->baseUrl, $single); return $this; } private function crawlPage(string $url, bool $single): void { ini_set('max_execution_time', -1); // 5 minutes $html = @file_get_contents($url); if ($html === false) { return; // Handle the error appropriately } preg_match('/