getData(); // Handle both standard OpenAI format and Cohere native format $modelsData = []; if (isset($responseData['data']) && !empty($responseData['data'])) { $modelsData = (array) $responseData['data']; } elseif (isset($responseData['models']) && !empty($responseData['models'])) { $modelsData = (array) $responseData['models']; } else { throw ResponseException::fromMissingData('Cohere', 'models'); } $baseTextOptions = [ new SupportedOption(OptionEnum::systemInstruction()), new SupportedOption(OptionEnum::maxTokens()), new SupportedOption(OptionEnum::temperature()), new SupportedOption(OptionEnum::topP()), new SupportedOption(OptionEnum::stopSequences()), new SupportedOption(OptionEnum::outputMimeType(), ['text/plain', 'application/json']), new SupportedOption(OptionEnum::customOptions()), new SupportedOption(OptionEnum::inputModalities(), [[ModalityEnum::text()]]), new SupportedOption(OptionEnum::outputModalities(), [[ModalityEnum::text()]]), new SupportedOption(OptionEnum::functionDeclarations()), ]; $models = []; foreach ($modelsData as $modelData) { $modelId = $modelData['id'] ?? $modelData['name']; // Fallback to 'name' if 'id' is missing. if (!$modelId || str_contains($modelId, 'embed') || str_contains($modelId, 'rerank')) { continue; } $models[] = new ModelMetadata( $modelId, $modelId, // Cohere uses the ID/name as the name. [CapabilityEnum::textGeneration(), CapabilityEnum::chatHistory()], $baseTextOptions ); } return $models; } }