在Sharpapi.com網站上查看更多信息»
請參考官員:
composer require sharpapi/sharpapi-php-client在Sharpapi.com上註冊並獲取API密鑰。
就是這樣!
$ sharpApi = new SharpAPI SharpApiService SharpApiService ( SHARP_API_KEY );
$ statusUrl = $ sharpApi -> productCategories (
' Lenovo Chromebook Laptop (2023), 14" FHD Touchscreen Slim 3,
8-Core MediaTek Kompanio 520 CPU, 4GB RAM, 128GB Storage ' ,
' German ' , // optional language
400 , // optional quantity
' optional neutral voice tone ' , // optional voice tone
' optional current e-store categories ' // optional context, current categories to match
);
$ resultSharpApiJob = $ sharpApi -> fetchResults ( $ statusUrl );
var_dump ( $ resultSharpApiJob -> getResultJson ());典型的用例需要以下步驟:
fetchResults($statusUrl)方法,每10秒在請求下發送180秒(可以自定義這些值,請檢查SharpApiService源代碼)。SharpApiJob對象將被返回。success返回狀態的工作,您可以使用其中一種方法獲得結果,例如$jobResultJson = $jobResult->getResultJson() 。每個派遣工作通常都會在幾秒鐘到一分鐘之間。
在此期間之後,返回的工作通常會具有success狀態,結果將用於進一步處理。每個API方法都返回不同的返回格式。請訪問下面的API方法/端點列表以獲取詳細信息»
我們的API保證每次都返回正確的格式。 Sharpapi在極少數情況下使用的AI引擎傾向於表現不佳,超時或返回錯誤的數據。在那些情況下,該作業的返回status將failed 。在這種情況下,您可以重新運行完全相同的工作請求。
只要我們的引擎仍在處理工作,它將繼續返回pending狀態。
基本的HTTP請求是用Guzzle提供動力的,因此最好檢查典型的Guzzle例外:
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 ' // optional language
500 , // optional length
' neutral ' // optional voice tone
);
// $statusUrl example value: 'https://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:: fetchResults ( $ 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 (); <?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 -> fetchResults ( $ statusUrl );
dd ( $ result -> getResultJson ());
/* returned:
[
{
"detected_number": "1800-394-7486",
"parsed_number": "+18003947486"
},
{
"detected_number": "+65 8888 8888",
"parsed_number": "+6588888888"
}
]
*/
}
}每種方法始終返回SharpApiJob對象,其中其getResultJson / getResultArray / getResultObject方法將返回不同的數據結構。請參閱Sharpapi.com上提供的詳細示例。
SharpApiLanguages枚舉值使您的代碼更可讀。從多種格式(PDF/DOC/DOCX/TXT/RTF)中解析簡歷(CV)文件,並返回數據點的廣泛對象。
還可以提供可選的輸出語言參數(將English值設置為默認值)。
$ statusUrl = SharpApiService:: parseResume ( ' /test/resume.pdf ' , ' English ' );根據廣泛參數的列表,此端點以響應格式提供簡潔的作業詳細信息,包括簡短的描述,工作要求和工作職責。唯一的強制性參數是name 。
此功能利用了名為JobDescriptionParameters的專用DTO類( Data Transfer Object )參數來輔助驗證輸入參數。該DTO的構造函數中只有name參數是強制性的。
您可以通過提供voice_tone參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
此API方法還提供了可選的上下文參數,該參數可用於提供其他靈活說明用於內容處理。
$ jobDescriptionParameters = new JobDescriptionParameters (
name: " PHP Senior Engineer " ,
company_name: " ACME LTD " , // optional
minimum_work_experience: " 5 years " , // optional
minimum_education: " Bachelor Degree " , // optional
employment_type: " full time " , // optional
required_skills: [ ' PHP8 ' , ' Laravel ' ], // optional
optional_skills: [ ' AWS ' , ' Redis ' ], // optional
country: " United Kingdom " , // optional
remote: true , // optional
visa_sponsored: true , // optional
voice_tone: ' Professional and Geeky ' , // optional voice tone
context: null , // optional context, additional AI processing instructions
language: null // optional output language
);
$ statusUrl = SharpApiService:: generateJobDescription ( $ jobDescriptionParameters );生成一系列相關技能列表,其權重作為浮點值(1.0-10.0),其中10等於100%,最高相關性得分。
僅需要第一個參數( name )。
您可以使用max_quantity參數限制輸出。
$ statusUrl = SharpApiService:: relatedSkills (
' MySQL ' ,
' English ' , // optional language
10 // optional quantity
);生成具有權重的相關工作位置的列表,即浮點值(1.0-10.0),其中10等於100%,最高相關性得分。
僅需要第一個參數( name )。
您可以使用max_quantity參數限制輸出。
$ statusUrl = SharpApiService:: relatedJobPositions (
' Senior PHP Engineer ' ,
' English ' , // optional language
10 // optional quantity
);解析客戶的產品評論,並以0-100%的分數提供其情感(正/負/中性)。非常適合任何在線商店的情感報告處理。
$ statusUrl = SharpApiService:: productReviewSentiment ( ' customer review contents ' );生成具有相關權重作為浮點值(1.0-10.0)的產品的合適類別列表,其中10等於100%,最高相關性得分。提供產品名稱及其參數以獲得最佳類別匹配。與填充產品目錄數據和批量產品的處理派上用場。
您可以使用max_quantity參數限制輸出。
您可以通過提供voice_tone參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
在其他可選參數上下文中,您可以提供將在映射過程中考慮的其他類別列表(例如,您當前的電子商務類別)。
$ statusUrl = SharpApiService:: productCategories (
' Sony Playstation 5 ' ,
' English ' , // optional language
5 , // optional quantity
' Tech-savvy ' , // optional voice tone
' Game Console, PS5 Console ' // optional context, current categories to match
);生成產品描述的較短版本。提供產品的許多細節和參數,以獲得最佳的營銷介紹。與填充的產品目錄數據和批量產品處理派上用場。
您可以使用max_length參數限制輸出。請記住, max_length是語言模型的強烈建議,而不是嚴格的要求,以維持結果的一般意義。
您可以通過提供voice_tone參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
$ statusUrl = SharpApiService:: generateProductIntro (
' Sony Playstation 5 ' ,
SharpApiLanguages:: ENGLISH , // optional language
300 , // optional length
' Funny ' // optional voice tone
);購買後,向客戶生成個性化的感謝電子郵件。響應內容最後不包含標題,問候或發件人信息,因此您可以輕鬆地個性化電子郵件。
您可以使用max_length參數限制輸出。請記住, max_length是語言模型的強烈建議,而不是嚴格的要求,以維持結果的一般意義。
您可以通過提供voice_tone參數來設置首選的寫作樣式。它可以是搞笑或歡樂的形容詞,甚至是著名作家的名字。
此API方法還提供了可選的上下文參數,該參數可用於提供其他靈活說明用於內容處理。
$ statusUrl = SharpApiService:: generateThankYouEmail (
' Sony Playstation 5 ' ,
SharpApiLanguages:: ENGLISH , // optional language
250 , // optional length
' Neutral ' , // optional voice tone
' Must invite customer to visit again before Holidays ' // optional context
);將提供的文字翻譯成選定的語言。支持80種語言。請檢查包括SharpApiLanguages枚舉課程以獲取詳細信息。
您可以通過提供voice_tone參數來設置首選的寫作樣式。它可以是搞笑或歡樂的形容詞,甚至是著名作家的名字。
還提供可選context參數。它可用於為翻譯文本提供更多上下文,例如用例示例或一些其他說明。
$ statusUrl = SharpApiService:: translate (
' turn ' ,
SharpApiLanguages:: FRENCH , // optional language
' neutral ' , // optional voice tone
' to turn a page ' // optional context
);
// will result in :
// {"content": "tourner", "to_language": "French", "from_language": "English"} 生成提供文本的釋義版本。僅需要content參數。您可以定義輸出語言,最大字符長度和語音。
可以在上下文參數中提供有關如何處理文本的其他說明。請記住, max_length是語言模型的強烈建議,而不是嚴格的要求,以維持結果的一般意義。
您可以通過提供可選的voice_tone參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
此API方法還提供了可選的context參數,該參數可用於提供其他靈活說明用於內容處理。
$ statusUrl = SharpApiService:: paraphrase (
$ text ,
SharpApiLanguages:: FRENCH , // optional language
500 , // optional length
' neutral ' , // optional voice tone
' avoid using abbreviations ' // optional context
);校對(並檢查語法)提供的文本。
$ statusUrl = SharpApiService:: proofread ( $ text );檢查如果提供的內容是否通過垃圾郵件過濾測試。提供一個百分比的置信度得分,並解釋是否被視為垃圾郵件。此信息對於主持人做出最終決定很有用。
$ statusUrl = SharpApiService:: detectSpam ( $ text );解析任何電話號碼提供的文本,並返回原始檢測版本及其E.164格式。如果您想在不應該的地方檢測到電話號碼,則可能會派上用場。
$ statusUrl = SharpApiService:: detectPhones ( $ text );為任何可能的電子郵件解析提供的文本。如果您想在不應該的地方檢測電子郵件,則可能會派上用場。
$ statusUrl = SharpApiService:: detectEmails ( $ text );根據提供的內容生成唯一關鍵字/標籤的列表。
您可以使用max_quantity參數限制輸出。
您可以通過提供voice_tone參數來設置首選的寫作樣式。
$ statusUrl = SharpApiService:: generateKeywords (
$ text ,
' English ' , // optional language
5 , // optional length
' Freaky & Curious ' , // optional voice tone
' add emojis! ' // optional extra context instructions for content processing
);生成提供的內容的摘要版本。非常適合產生較長文本的營銷介紹。
您可以使用max_length參數限制輸出。請記住, max_length是語言模型的強烈建議,而不是嚴格的要求,以維持結果的一般意義。
您可以通過提供voice_ton e參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
$ statusUrl = SharpApiService:: summarizeText (
$ text ,
' English ' , // optional language
' David Attenborough ' , // optional voice tone
' add emojis! ' // optional extra context instructions for content processing
);根據所提供的內容生成所有最重要的元標記。確保包括指向網站和圖片URL的鏈接,以獲取最多的標籤。
您可以通過提供voice_ton e參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
$ statusUrl = SharpApiService:: generateSeoTags (
$ text ,
' English ' , // optional language
' David Attenborough ' // optional voice tone
);解析旅行/酒店產品評論,並以0-100%的分數提供其情感(正/負/中性)。非常適合任何在線商店的情感報告處理。
$ statusUrl = SharpApiService:: travelReviewSentiment ( $ text );生成具有相關權重為浮點值(1.0-10.0)的遊覽和活動產品的合適類別列表,其中10等於100%,最高相關性得分。提供產品名稱及其參數以獲得最佳類別匹配。與填充的產品目錄數據和批量產品處理派上用場。僅需要第一個參數productName 。
您可以使用max_quantity參數限制輸出。
您可以通過提供voice_tone參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
在其他可選參數context中,您可以提供將在映射過程中考慮的其他類別列表(例如,您當前的電子商務類別)。
$ statusUrl = SharpApiService:: toursAndActivitiesProductCategories (
' Oasis of the Bay '
'Ha Long', // optional city
' Vietnam ' , // optional country
' English ' , // optional language
10 , // optional quantity
' Adventurous ' , // optional voice tone
' Bay Hotels, Ha Long Hotels ' // optional context, current categories to match
);生成適合酒店類型產品的合適類別列表,其中相關權重為浮點值(1.0-10.0),其中10等於100%,最高相關性得分。提供產品名稱及其參數以獲得最佳類別匹配。與填充產品目錄數據和批量產品的處理派上用場。僅需要第一個參數productName 。
您可以使用max_quantity參數限制輸出。
您可以通過提供voice_tone參數來設置首選的寫作樣式。它可以是funny或joyous形容詞,甚至是著名作家的名字。
在其他可選參數context中,您可以提供將在映射過程中考慮的其他類別列表(例如,您當前的電子商務類別)。
$ statusUrl = SharpApiService:: hospitalityProductCategories (
' Hotel Crystal 大人専用'
'Tokyo', // optional city
' Japan ' , // optional country
' English ' , // optional language
10 , // optional quantity
' Adventurous ' , // optional voice tone
' Tokyo Hotels, Crystal Hotels ' // optional context, current categories to match
);端點要檢查有關訂閱當前期間的詳細信息
$ statusUrl = SharpApiService:: quota ();將導致:
{
"timestamp" : " 2024-03-19T12:49:41.445736Z " ,
"on_trial" : false ,
"trial_ends" : " 2024-03-17T07:57:46.000000Z " ,
"subscribed" : true ,
"current_subscription_start" : " 2024-03-18T12:37:39.000000Z " ,
"current_subscription_end" : " 2024-04-18T12:37:39.000000Z " ,
"subscription_words_quota" : 100000 ,
"subscription_words_used" : 9608 ,
"subscription_words_used_percentage" : 0.1
} subscription_words_used_percentage是當前每月配額使用情況的百分比,可能會向用戶警告耗盡的信用。以高於80%的值,建議您在https://sharpapi.com/dashboard/credits上訂閱更多積分,以避免服務中斷。
這些值也可以在儀表板上https://sharpapi.com/dashboard提供
簡單的ping端點以檢查API的可用性及其內部Timze區域(TIMESTAMP)。
$ statusUrl = SharpApiService:: ping ();將導致:
{
"ping" : " pong " ,
"timestamp" : " 2024-03-12T08:50:11.188308Z "
}請讓我們知道»
有關最近發生了變化的更多信息,請參見ChangElog。
麻省理工學院許可證(麻省理工學院)。請參閱許可證文件以獲取更多信息。