GithubHelp home page GithubHelp logo

jeffersonsimaogoncalves / sharpapi-laravel-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sharpapi/sharpapi-laravel-client

0.0 0.0 0.0 69 KB

SharpAPI - AI-Powered Swiss Army Knife API. Assisting coders with the most repetitive content analysis and content generation processing needs of any app or platform.

License: MIT License

PHP 100.00%

sharpapi-laravel-client's Introduction

SharpAPI GitHub cover

SharpAPI Laravel Client

AI-Powered Swiss Army Knife API for every software developer

Save countless hours and supercharge your app with AI capabilities in just 2 lines of code.

Latest Version on Packagist Total Downloads

Save time on repetitive content analysis and generation tasks that your app users perform daily.

See more at SharpAPI.com Website »

Requirements

  • PHP >= 8.1
  • Laravel >= 9.0

If you don't use Laravel then you can find Generic SharpAPI PHP Client here »

What can it do for you?

  • E-commerce
    • Quickly generate engaging product introductions to attract customers.
    • Automatically create personalized thank-you emails for enhanced customer experience.
    • Streamline product categorization for a well-organized catalog.
    • Sentiment Analysis: Understand and analyze sentiment in product reviews for data-driven decision-making.
  • Content & Marketing Automation
    • Easily translate text for a global audience.
    • Spam Content Detection: Identify and filter out spam content effectively.
    • Contact Information Extraction: Extract phone numbers and email addresses from non-standard formats for streamlined communication.
    • Generate concise summaries for improved content consumption.
    • Boost SEO efforts by automatically generating META tags based on content.
  • HR Tech
    • Generate complex job descriptions effortlessly, saving time in the hiring process.
    • Skills and Position Insights: Identify related job positions and skills to streamline recruitment.
    • Automated Resume Parsing: Efficiently parse and extract information from resumes files for easy processing.
  • Travel, Tourism & Hospitality
    • Analyze sentiment in travel reviews to improve services.
    • Streamline categorization for tours, activities, and hospitality products.

Features

Please refer to the official:

  • API Documentation
  • Multi-language Support: Supporting 80 languages for every content or data analysis API endpoint. Check the list here.
  • Easy-to-Use RESTful Format: With standardized set of endpoints - gain valuable insights through analysis endpoints, covering product categories, skills, and job positions, providing relevant scores.
  • Always the same, clean data formats: Rest assured with consistent, predictable JSON format for all returned data. No need to worry about fuzzy AI data.
  • Tech Support: Crafted by developers for developers, we provide continuous assistance throughout your journey.

Installation

  1. You can install the package via composer:
composer require sharpapi/sharpapi-laravel-client
  1. Register at SharpApi.com and get the API key.

  2. Set the API key inside .env

SHARP_API_KEY=8bKzQl3cwckfVsnsN8T8p4BsACkziEQJ72U4pXpQ

That's it!

Usage

You can inject SharpApiService class or use the facade \SharpApiService singleton.

We recommend you to use Laravel queuing system to optimize dispatched jobs and the process of checking the results, especially if you process bigger batches of data.

Typical use case require these steps:

  1. Dispatch one of the available AI processing methods (this will return job processing status URL)
  2. Run pollJobStatusAndFetchResults($statusUrl) method which operates in polling mode, sending underneath requests every 10 seconds for 180 seconds (these values can be customized).
  3. SharpApiJob object will be returned.
  4. For a job finished with success return status you can obtain the results with one of the methods, for example $jobResultJson = $jobResult->getResultJson().

Each dispatched job usually takes somewhere between a couple of seconds to a minute.

After that period a returned job will usually have success status and it's results will be available for further processing. Each API method returns different return format. Go to List of API methods/endpoints below for details»

Our API guarantees to return correct format every time. AI engines that SharpAPI use in rare cases have a tendency to misbehave and timeout or return incorrect data. In those cases the returned status for the job will be failed. You can rerun the exact same job request in that case.

As long as the job is still being processed by our engine it will keep returning pending status.

Controller usage example

<?php

namespace App\Http\Controllers;

use GuzzleHttp\Exception\GuzzleException;
use SharpAPI\SharpApiService\SharpApiService;

class SharpTest extends Controller
{
    public function __construct(public SharpApiService $sharpApiService)
    {
    }

    /**
     * @throws GuzzleException
     */
    public function detect_phones(): void
    {
        $statusUrl = $this->sharpApiService->detectPhones(
            'Where to find us? Call with a sales tech advisor:
            Call: 1800-394-7486 or our Singapore office +65 8888 8888'
        );
        
        $result = $this->sharpApiService->pollJobStatusAndFetchResults($statusUrl);
        
        dd($result->getResultJson());
        /* returned:
        [
            {
                "detected_number": "1800-394-7486",
                "parsed_number": "+18003947486"
            },
            {
                "detected_number": "+65 8888 8888",
                "parsed_number": "+6588888888"
            }
        ]
         */
    }
}

Guzzle Exceptions

The underlying HTTP requests are facilitated by Laravel HTTP Client/Guzzle, making it advisable to familiarize yourself with common Guzzle Exceptions.

use GuzzleHttp\Exception\ClientException;

// Step 1: dispatch the job to the API with one of the methods, for example:
try {
    $statusUrl = \SharpApiService::summarizeText($text, 'German');
    // $statusUrl example value: 'http://sharpapi.com/api/v1/job/status/75acb6dc-a975-4969-9ef1-c62cebc511cb'
} catch (ClientException $e) {
    // $e->getResponse()
}

// Step 2: request to check job status in polling mode and wait for the result
$jobResult = \SharpApiService::pollJobStatusAndFetchResults($statusUrl);

// Step 3: get results of dispatched API job, f.e. this returns job result as a prettied JSON
$jobResultJson = $jobResult->getResultJson();
// ..or PHP array:
$jobResultArray = $jobResult->getResultArray();
// ..or PHP stdClass:
$jobResultObject = $jobResult->getResultObject();

OPTIONAL custom configuration

This might come useful if you want to have more control over polling requests.

You can publish the config file with:

php artisan vendor:publish --tag="sharpapi-laravel-client"

This is the contents of the published config file:

return [
    'api_key' => env('SHARP_API_KEY'),
    'base_url' => env('SHARP_API_BASE_URL', 'https://sharpapi.com/api/v1'), // as ENV is mock server needed
    // how long (in seconds) the client should wait in polling mode for results
    'api_job_status_polling_wait' => env('SHARP_API_JOB_STATUS_POLLING_WAIT', 180),
    // how many seconds the client should wait between each result request
    // usually Retry-After header is used (default 10s), this value won't have an effect unless
    // api_job_status_use_polling_interval is set to TRUE
    'api_job_status_polling_interval' => env('SHARP_API_JOB_STATUS_POLLING_INTERVAL', 10),
    'api_job_status_use_polling_interval' => env('SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL', false),
];

So you can overwrite these values with .env settings:

SHARP_API_KEY=8bKzQl3cwckfVsnsN8T8p4BsACkziEQJ72U4pXpQ
SHARP_API_JOB_STATUS_POLLING_WAIT=200
SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL=true
SHARP_API_JOB_STATUS_POLLING_INTERVAL=5
SHARP_API_BASE_URL=MOCK_SERVER

List of API methods/endpoints

Each method always returns SharpApiJob object, where its getResultJson / getResultArray / getResultObject methods will return different data structure. Please refer to the detailed examples provided at SharpAPI.com

For methods that have language parameter you can also use SharpApiLanguages Enum values to make your code more readable.

HR

Parse Resume/CV File

Parses a resume (CV) file from multiple formats (PDF/DOC/DOCX/TXT/RTF) and returns an extensive object of data points.

An optional output language parameter can also be provided (English value is set as the default one) .

$statusUrl = \SharpApiService::parseResume('/test/resume.pdf', 'English');

Generate Job Description

Based on the list of extensive parameters this endpoint provides concise job details in the response format, including the short description, job requirements, and job responsibilities. The only mandatory parameter is name.

This functionality utilizes a specialized DTO class (Data Transfer Object) parameter named JobDescriptionParameters to aid in the validation of input parameters. Only the name parameter in the constructor of this DTO is mandatory.

$jobDescriptionParameters = new JobDescriptionParameters(
    name: "PHP Senior Engineer",
    company_name: "ACME LTD",
    minimum_work_experience: "5 years",
    minimum_education: "Bachelor Degree",
    employment_type: "full time",
    required_skills: ['PHP8', 'Laravel'],
    optional_skills: ['AWS', 'Redis'],
    country: "United Kingdom",
    remote: true,
    visa_sponsored: true,
    language: 'English'
);

$statusUrl = \SharpApiService::generateJobDescription($jobDescriptionParameters);

Related Skills

Generates a list of related skills with their weights as a float value (1.0-10.0) where 10 equals 100%, the highest relevance score.

$statusUrl = \SharpApiService::relatedSkills('MySQL', 'English');

Related Job Positions

Generates a list of related job positions with their weights as float value (1.0-10.0) where 10 equals 100%, the highest relevance score.

$statusUrl = \SharpApiService::relatedJobPositions('Senior PHP Engineer', 'English');

E-commerce

Product Review Sentiment

Parses the customer's product review and provides its sentiment (POSITIVE/NEGATIVE/NEUTRAL) with a score between 0-100%. Great for sentiment report processing for any online store.

$statusUrl = \SharpApiService::productReviewSentiment('review contents');

Product Categories

Generates a list of suitable categories for the product with relevance weights as a float value (1.0-10.0) where 10 equals 100%, the highest relevance score. Provide the product name and its parameters to get the best category matches possible. Comes in handy with populating product catalogue data and bulk products' processing.

$statusUrl = \SharpApiService::productCategories('Sony Playstation 5', 'English');

Generate Product Intro

Generates a shorter version of the product description. Provide as many details and parameters of the product to get the best marketing introduction possible. Comes in handy with populating product catalog data and bulk products processing.

$statusUrl = \SharpApiService::generateProductIntro('Sony Playstation 5', 'English');

Generate Thank You E-mail

Generates a personalized thank-you email to the customer after the purchase. The response content does not contain the title, greeting or sender info at the end, so you can personalize the rest of the email easily.

$statusUrl = \SharpApiService::generateThankYouEmail('Sony Playstation 5', 'English');

Content

Translate Text

Translates provided text to selected language. 80 languages are supported. Please check included SharpApiLanguages Enum class for details.

$statusUrl = \SharpApiService::translate($text, SharpApiLanguages::ITALIAN);

Detect Spam

Checks if provided content passes a spam filtration test. Provides a percentage confidence score and an explanation for whether it is considered spam or not. This information is useful for moderators to make a final decision.

$statusUrl = \SharpApiService::detectSpam($text);

Detect Phones Numbers

Parses the provided text for any phone numbers and returns the original detected version and its E.164 format. Might come in handy in the case of processing and validating big chunks of data against phone numbers or f.e. if you want to detect phone numbers in places where they're not supposed to be.

$statusUrl = \SharpApiService::detectPhones($text);

Detect Emails

Parses the provided text for any possible emails. Might come in handy in case of processing and validating big chunks of data against email addresses or f.e. if you want to detect emails in places where they're not supposed to be.

$statusUrl = \SharpApiService::detectEmails($text);

Summarize Text

Generates a summarized version of the provided content. Perfect for generating marketing introductions of longer texts.

$statusUrl = \SharpApiService::summarizeText($text, 'English');

SEO

Generate SEO Tags

Generates all most important META tags based on the content provided. Make sure to include link to the website and pictures URL to get as many tags populated as possible.

$statusUrl = \SharpApiService::generateSeoTags($text, 'English');

Travel, Tourism & Hospitality

Travel Review Sentiment

Parses the Travel/Hospitality product review and provides its sentiment (POSITIVE/NEGATIVE/NEUTRAL) with a score between 0-100%. Great for sentiment report processing for any online store.

$statusUrl = \SharpApiService::travelReviewSentiment($text);

Tours & Activities Product Categories

Generates a list of suitable categories for the Tours & Activities product with relevance weights as float value (1.0-10.0) where 10 equals 100%, the highest relevance score. Provide the product name and its parameters to get the best category matches possible. Comes in handy with populating product catalogue data and bulk product processing. Only first parameter productName is required.

$statusUrl = \SharpApiService::toursAndActivitiesProductCategories(
        'Oasis of the Bay'
        'Ha Long',
        'Vietnam',
        'English'
    );

Hospitality Product Categories

Generates a list of suitable categories for the Hospitality type product with relevance weights as float value (1.0-10.0) where 10 equals 100%, the highest relevance score. Provide the product name and its parameters to get the best category matches possible. Comes in handy with populating products catalogs data and bulk products' processing. Only first parameter productName is required.

$statusUrl = \SharpApiService::hospitalityProductCategories(
        'Hotel Crystal 大人専用'
        'Tokyo',
        'Japan',
        'English'
    );

Do you think our API is missing some obvious functionality?

Please let us know»

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

sharpapi-laravel-client's People

Contributors

makowskid avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.