PHP code example of wetrocloud / wetrocloud-sdk

1. Go to this page and download the library: Download wetrocloud/wetrocloud-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wetrocloud / wetrocloud-sdk example snippets




use Wetrocloud\WetrocloudSdk\Wetrocloud;

// Initialize the SDK
$wetrocloud = new Wetrocloud('your-api-key');

// Create a collection
$response = $wetrocloud->createCollection('my-collection');

// Insert a resource
$wetrocloud->insertResource('my-collection', 'https://example.com/article', 'web');

// Query the collection
$results = $wetrocloud->queryCollection('my-collection', 'What is this about?');



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

// Create collection with auto-generated ID
$response = $wetrocloud->createCollection();

// Create collection with custom ID
$response = $wetrocloud->createCollection('unique-collection-id');

echo "Creating Collection: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');
$response = $wetrocloud->listAllCollections();

echo "Listing Collections: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');
$response = $wetrocloud->deleteCollection('your-collection-id');

echo "Deleting collection: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

$response = $wetrocloud->insertResource(
    'your-collection-id',
    'https://medium.com/@AlexanderObregon/a-brief-history-of-artificial-intelligence-1656693721f9',
    'web'
);

echo "Insert a resource: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');
$response = $wetrocloud->removeResource('your-collection-id', 'your-resource-id');

echo "Deleting resource: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

$collectionId = 'your-collection-id';
$query = 'What are the sales trends for Q1?';

$response = $wetrocloud->queryCollection($collectionId, $query);

// With schema and rules
$response = $wetrocloud->queryCollection(
    $collectionId,
    $query,
    '{"type": "object", "properties": {"answer": {"type": "string"}}}',
    '{"



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

// Simple chat without history
$response = $wetrocloud->chatCollection('your-collection-id', 'Tell me more');

// Chat with history
$chatHistory = json_encode([
    ['role' => 'user', 'content' => 'What is this all about?'],
    ['role' => 'assistant', 'content' => 'This is about Queen Elizabeth II of England']
]);

$response = $wetrocloud->chatCollection(
    'your-collection-id',
    'Tell me more',
    $chatHistory
);

echo "Chat with collection: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

$response = $wetrocloud->categorizeResource(
    'match review: John Cena vs. The Rock',
    'text',
    '{"label": ""}',
    'football,coding,entertainment,basketball,wrestling,information',
    'Where does this fall under?'
);

echo "Categorizing resource: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

$messages = [
    ['role' => 'system', 'content' => 'You are a helpful assistant.'],
    ['role' => 'user', 'content' => 'Write a short poem about technology.']
];

$response = $wetrocloud->textGeneration($messages, 'llama-3.3-70b');

echo "Generation without RAG: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

$imageUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTQBQcwHfud1w3RN25Wgys6Btt_Y-4mPrD2kg&s';
$query = 'What animal is this?';

$response = $wetrocloud->imageToText($imageUrl, $query);

echo "Image to text: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

// Convert web page to markdown
$response = $wetrocloud->markdownConverter(
    'https://www.forbes.com/real-time-billionaires/',
    'web'
);

// Convert file to markdown
$response = $wetrocloud->markdownConverter(
    'https://example.com/document.pdf',
    'file'
);

// Convert image to markdown
$response = $wetrocloud->markdownConverter(
    'https://example.com/image.jpg',
    'image'
);

echo "Converted Markdown: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

$wetrocloud = new Wetrocloud('your-api-key');

$response = $wetrocloud->transcript(
    'https://www.youtube.com/watch?v=m4qBwGnubew',
    'youtube'
);

echo "Transcript result: " . json_encode($response, JSON_PRETTY_PRINT);



use Wetrocloud\WetrocloudSdk\Wetrocloud;

// Use custom API endpoint
$wetrocloud = new Wetrocloud('your-api-key', 'https://custom-api.wetrocloud.com');