gmulti/xgen

SDK for text generator

dev-master 2019-09-05 19:36 UTC

This package is auto-updated.

Last update: 2024-04-06 06:36:06 UTC


README

Official PHP SDK of the XGen API.

API Documentation : https://thomas-15.gitbook.io/generator/

Requirements

  • PHP version 7.2 and later
  • XGen API Key, contact me

Installation

You can install the library via Composer. Run the following command:

composer require gmulti/xgen

To use the library, use Composer's autoload:

require_once __DIR__. '/vendor/autoload.php';

Example

Usage with data sample

<?php

require_once __DIR__ . '/vendor/autoload.php';

use XGen\Client;
use XGen\XGen;

try {
    $xgen = new XGen();
    $xgen->addContextFromFile(__DIR__ . '/vendor/gmulti/xgen/data/context-1.json');
    $xgen->addContextFromFile(__DIR__ . '/vendor/gmulti/xgen/data/context-2.json');
    $xgen->addSourceFromFile(__DIR__ . '/vendor/gmulti/xgen/data/source.json');

    $client = new Client('API_KEY');
    $result = $client->getResource('generate')->postGenerateWithXGen($xgen);
    var_dump($result);
    // array (size=1)
    //   'text' => string 'Dans le cadre de la 2ème journée, Angers SCO accueille Olympique Lyonnais' (length=75)
    
} catch (\Exception $e) {
}

Load source from URL

<?php

require_once __DIR__ . '/sdk/vendor/autoload.php';

use XGen\Client;
use XGen\XGen;

try {
    $xgen = new XGen();
    $xgen->addContextFromFile(__DIR__ . '/vendor/gmulti/xgen/data/context-1.json');
    $xgen->addContextFromFile(__DIR__ . '/vendor/gmulti/xgen/data/context-2.json');
    $xgen->addSourceFromUrlJson('https://apigenerator.gmulti.now.sh/v1/example-data/source');

    $client = new Client('API_KEY');
    $text = $client->getResource('generate')->postGenerateWithXGen($xgen);
    var_dump($result);
    // array (size=1)
    //   'text' => string 'Dans le cadre de la 2ème journée, Angers SCO accueille Olympique Lyonnais' (length=75)
} catch (\Exception $e) {
}

About

xgen is guided and supported by Thomas Deneulin.