在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。
麻省理工学院许可证(麻省理工学院)。请参阅许可证文件以获取更多信息。