fjffk简å�•的咖啡店科开å�‘2方法2 环æ»�皆山也。其西å�—诸峰,林壑尤美,望之蔚然而深秀者,ç�…ç�Šä¹Ÿã€‚山行å…七里,æ¸�闻水声潺潺,而泻出于两峰之间者,酿泉也 ??????????????????????????????? ??????????????/????????????????? ............/................... .........................../... ??????????????????????????????? >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>> ÿØÿà JFIF ÿÛ „ ( %!1!%)+//.383,7(-.+ -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ Â¥2" ÿÄ ÿÄ J ! 1AQ"aqÂ�2‘#BR‚¡Ã�Ñ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ ÿÄ * !1AQa‘"2q3Â�±ð#b¡ÿÚ ? ¼QxJQaÃ�uò¸Zö Úü8,Ã�Úú "SSn<rçù–´âE—^ªBÖ9À\†¸Â�ÔÂ�Ã�TÂÃÛ5 ëd´³Ã�#Ã�;Þ38ϔÂ� ¶H£M:wÃŽ3…³…âpÔF&‚FK¸9„â4à GEõªfÂ�ÿ ‘ñ(ßwÂpŽF|È¥ù®häðÃ�Ѷ¹‘[Ã’inÙW¶ùñYËœQ{›K"išÒ[Ú8žë\F¹@-?v"ÔUâ€�,ìöžkÿ {I‡£šÃ�?e rÂ�ÃV ?> ......................................... ............................................................................. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> dsdfPK ΃W]âÔ⨠¨ F database/migrations/2025_05_23_143630_create_voice_chat_bots_table.phpnu „[µü¤ 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'); } }; PK ΃W]#¢ #ª ª L database/migrations/2025_05_23_154408_create_voice_chat_bot_trains_table.phpnu „[µü¤ 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'); } }; PK ΃W]qj�� � extension.jsonnu „[µü¤ { "name": "Elevenlabs Voice Chat", "type": "extension", "version": "1.2", "description": "Elevenlabs voice chat extension for magicai" } PK ΃W]âìv½{ { . System/Services/ElevenLabsVoiceChatService.phpnu „[µü¤ 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, ]; } } PK ΃W]âὪ^ ^ System/Models/VoiceChatBot.phpnu „[µü¤ hasMany(VoiceChatBotTrain::class, 'chatbot_id'); } /** * voice chabot owner */ public function user(): BelongsTo { return $this->belongsTo(User::class); } } PK ΃W]T¯×´W W # System/Models/VoiceChatBotTrain.phpnu „[µü¤ 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('/