tidycode/ai-php-sdk
Composer 安装命令:
composer require tidycode/ai-php-sdk
包简介
Tidycode AI PHP SDK is a PHP API client that allows you to integrate artificial intelligence services deployed by Tidycode.
README 文档
README
This SDK allows you to integrate your PHP eCommerce with our dedicated artificial intelligence services. Currently, the SDK supports the Fraud Detection service, but is designed to be extended with other services in the future.
Installation.
To use this SDK, you must add it to your PHP project. It can be installed via Composer.
Add the dependency to the composer.json of your composer module or package:
{
"require": {
"tidycode/ai-php-sdk":"^1.0"
}
}
or install it via the composer command
composer require tidycode/ai-php-sdk
Then run the command:
composer install
Using Fraud Detection
Configuration.
To start using the Fraud Detection service, create an instance of the Tidycode\AIClient\FraudDetection class.
require 'vendor/autoload.php'; use Tidycode\AIClient\FraudDetection; $client = new FraudDetection('your-api-key');
Methods
The SDK offers the following methods:
1. detectFraud.
Checks whether an order is suspected of fraud.
Parameters: a JSON array with the order data.
JSON format:
{
"email": "test@testmail.com",
"firstname": "Firstname",
"lastname": "Lastname",
"ips": "192.168.0.1, 192.168.0.2",
"billing_address": {
"address_type": "billing",
"city": "Trieste",
"country_id": "IT",
"email": "test@testmail.com",
"firstname": "Firstname",
"lastname": "Lastname",
"postcode": "10000",
"region_id": "TS",
"street": "Test",
"telephone": "0123456789"
},
"shipping_address": {
"address_type": "shipping",
"city": "Trieste",
"country_id": "IT",
"email": "test@testmail.com",
"firstname": "Firstname",
"lastname": "Lastname",
"postcode": "10000",
"region_id": "TS",
"street": "Test",
"telephone": "0123456789"
},
"currency": "USD",
"payment_method": "[payment code]",
"total_paid": "105.00",
"shipping_cost": "5.00",
"item_count": "1",
"shipping_method": "[shipment code]",
"date": "2024-07-23 10:08:56"
}
Example usage:
$orderData = [ // the order data in JSON format. ]; $response = $client->detectFraud($orderData); print_r($response);
2. reportFalsePositive.
Reports an incorrectly classified order as fraud.
Parameters: a JSON array with the order data. The JSON is the same as the detectFraud method.
Example usage:
$response = $client->reportFalsePositive($orderData); print_r($response);
3. reportFalseNegative.
Reports an order incorrectly classified as non-fraudulent. The JSON is the same as in the detectFraud method.
Parameters: a JSON array with the order data.
Example usage:
$response = $client->reportFalseNegative($orderData); print_r($response);
4. paymentList.
Returns the list of payment method codes.
Example usage:
$paymentCodes = $client->paymentList(); print_r($paymentCodes);
5. shipmentList.
Returns the list of shipment method codes.
Example usage:
$shipmentCodes = $client->shipmentList(); print_r($shipmentCodes);
Using Nutrition Assistant
Configuration.
To start using the Nutrition Assistant service, create an instance of the Tidycode\AIClient\NutritionAssistant class.
require 'vendor/autoload.php'; use Tidycode\AIClient\NutritionAssistant; $client = new NutritionAssistant('your-api-key');
Methods
The SDK offers the following methods:
1. getMacro.
It returns calories and recommended macronutrient doses, based on patient data.
Parameters: a JSON array with the order data.
JSON format:
{
"gender": "female",// (female/male)
"age": "30", // years old
"height": "180", // cm
"weight": "80", // kg
"fat_mass": "20", // % fat mass
"physical_activity": "active", // (sedentary/low_active/active/very_active/pro)
"target": "maintenance", // (aggressive_cut/moderate_cut/maintenance/moderate_bulk/aggressive_bulk)
"formula": "Cunningham", // (Harris-Benedict/Mifflin-St. Jeor/Cunningham/Katch-McArdle)
"protein_percentage": "30", // % of calories
"fat_percentage": "25", // % of calories
"carbohydrate_percentage": "45" // % of calories
}
Example usage:
$customerData = [ // the customer data in JSON format. ]; $response = $client->getMacro($customerData); print_r($response);
2. getFoodList.
It returns a list of foods, and their doses, divided into the 5 main meals, so that the indicated calories and macronutrients doses are met. It also respects food choices and allergies.
Parameters: a JSON array with the order data.
JSON format:
{
"calories": "2000",// kcal
"proteins": "200", // gr
"fats": "50", // gr
"carbohydrates": "70", // gr
"allergies": [ // (glutine/uova/lattosio/frutta secca/pesce/molluschi e crostacei/soia)
"glutine",
"uova",
...
],
"dietary_preferences": "vegan", // (vegetariano/vegano/onnivoro)
"meals": [ // (colazione/spuntino/pranzo/merenda/cena)
"colazione",
"spuntino",
...
]
}
Example usage:
$caloriesAndMacros = [ // the calories and macros data in JSON format. ]; $response = $client->getFoodList($caloriesAndMacros); print_r($response);
3. getRecipes.
Use the given food list to suggest preparations and recipes, trying to respect food preferences and allergies.
Parameters: a JSON array with the order data.
JSON format:
{
"food_list": {
"cereali": "130", // gr
"latte": "100" // ml
},
"allergies": [
"glutine",
"uova",
...
],
"dietary_preferences": "vegano"
}
4. getFoodCategories.
This API is used to get the list of food categories returned, which is useful, for example, for the mask of excluding certain dishes based on the patient's taste. It returns an object that can be converted to json with a simple list
Example usage:
$foodData = [ // the food data in JSON format. ]; $response = $client->getRecipes($foodData); print_r($response);
Adding New Services.
The SDK is designed to be extended with additional services in the future. Any new services will be documented and added to the list of available methods in this README.
License.
This project is licensed under the MIT License.
SDK Tidycode AIClient per PHP
Questo SDK consente di integrare i vostri eCommerce PHP con i nostri servizi di intelligenza artificiale dedicati. Attualmente, il SDK supporta il servizio di Rilevamento Frodi, ma è progettato per essere esteso con altri servizi in futuro.
Installazione
Per utilizzare questo SDK, è necessario aggiungerlo al vostro progetto PHP. Può essere installato tramite Composer.
Aggiungi la dipendenza al composer.json del tuo modulo o pacchetto composer:
{
"require": {
"tidycode/ai-php-sdk": "^1.0"
}
}
oppure installalo tramite il comando composer
composer require tidycode/ai-php-sdk
Esegui quindi il comando:
composer install
Utilizzo Fraud Detection
Configurazione
Per iniziare a utilizzare il servizio di Fraud Detection, crea un'istanza della classe Tidycode\AIClient\FraudDetection.
require 'vendor/autoload.php'; use Tidycode\AIClient\FraudDetection; $client = new FraudDetection('your-api-key');
Metodi
L'SDK offre i seguenti metodi:
1. detectFraud
Verifica se un ordine è sospetto di frode.
Parametri: un array JSON con i dati dell'ordine.
Formato JSON:
{
"email": "test@testmail.com",
"firstname": "Firstname",
"lastname": "Lastname",
"ips": "192.168.0.1, 192.168.0.2",
"billing_address": {
"address_type": "billing",
"city": "Trieste",
"country_id": "IT",
"email": "test@testmail.com",
"firstname": "Firstname",
"lastname": "Lastname",
"postcode": "10000",
"region_id": "TS",
"street": "Test",
"telephone": "0123456789"
},
"shipping_address": {
"address_type": "shipping",
"city": "Trieste",
"country_id": "IT",
"email": "test@testmail.com",
"firstname": "Firstname",
"lastname": "Lastname",
"postcode": "10000",
"region_id": "TS",
"street": "Test",
"telephone": "0123456789"
},
"currency": "USD",
"payment_method": "[payment code]",
"total_paid": "105.00",
"shipping_cost": "5.00",
"item_count": "1",
"date": "2024-07-23 10:08:56"
}
Esempio di utilizzo:
$orderData = [ // i dati dell'ordine in formato JSON ]; $response = $client->detectFraud($orderData); print_r($response);
2. reportFalsePositive
Segnala un ordine erroneamente classificato come frode.
Parametri: un array JSON con i dati dell'ordine. Il JSON è il medesimo del metodo detectFraud
Esempio di utilizzo:
$response = $client->reportFalsePositive($orderData); print_r($response);
3. reportFalseNegative
Segnala un ordine erroneamente classificato come non fraudolento. Il JSON è il medesimo del metodo detectFraud
Parametri: un array JSON con i dati dell'ordine.
Esempio di utilizzo:
$response = $client->reportFalseNegative($orderData); print_r($response);
4. paymentList
Restituisce la lista dei codici dei metodi di pagamento.
Esempio di utilizzo:
$paymentCodes = $client->paymentList(); print_r($paymentCodes);
5. shipmentList
Restituisce la lista dei codici dei metodi di spedizione.
Esempio di utilizzo:
$shipmentCodes = $client->shipmentList(); print_r($shipmentCodes);
Chiedo scusa per l'errore. Ecco la versione corretta, con le porzioni di codice completamente inalterate come richiesto:
Utilizzo di Nutrition Assistant
Configurazione
Per iniziare a utilizzare il servizio Nutrition Assistant, crea un'istanza della classe Tidycode\AIClient\NutritionAssistant.
require 'vendor/autoload.php'; use Tidycode\AIClient\NutritionAssistant; $client = new Nutrition Assistant('your-api-key');
Metodi
L'SDK offre i seguenti metodi:
1. getMacro.
Restituisce il numero di calorie e le dosi raccomandate di macronutrienti, basandosi sui dati del paziente.
Parametri: un array JSON con i dati dell'ordine.
Formato JSON:
{
"gender": "female",// (female/male)
"age": "30", // years old
"height": "180", // cm
"weight": "80", // kg
"fat_mass": "20", // % fat mass
"physical_activity": "active", // (sedentary/low_active/active/very_active/pro)
"target": "maintenance", // (aggressive_cut/moderate_cut/maintenance/moderate_bulk/aggressive_bulk)
"formula": "Cunningham", // (Harris-Benedict/Mifflin-St. Jeor/Cunningham/Katch-McArdle)
"protein_percentage": "30", // % delle calorie
"fat_percentage": "25", // % delle calorie
"carbohydrate_percentage": "45" // % delle calorie
}
Esempio di utilizzo:
$customerData = [ // the customer data in JSON format. ]; $response = $client->getMacro($customerData); print_r($response);
2. getFoodList.
Restituisce un elenco di alimenti, con relative dosi, suddivisi nei 5 pasti principali, in modo che vengano rispettati le calorie e i macronutrienti indicati. Viene tenuto conto anche delle scelte alimentari e delle allergie.
Parametri: un array JSON con i dati dell'ordine.
Formato JSON:
{
"calories": "2000",// kcal
"proteins": "200", // gr
"fats": "50", // gr
"carbohydrates": "70", // gr
"allergies": [ // (glutine/uova/lattosio/frutta secca/pesce/molluschi e crostacei/soia)
"glutine",
"uova",
...
],
"dietary_preferences": "vegan", // (vegetariano/vegano/onnivoro)
"meals": [ // (colazione/spuntino/pranzo/merenda/cena)
"colazione",
"spuntino",
...
]
}
Esempio di utilizzo:
$caloriesAndMacros = [ // the calories and macros data in JSON format. ]; $response = $client->getFoodList($caloriesAndMacros); print_r($response);
3. getRecipes.
Utilizza l'elenco degli alimenti fornito per suggerire preparazioni e ricette, cercando di rispettare le preferenze alimentari e le allergie.
Parametri: un array JSON con i dati dell'ordine.
Formato JSON:
{
"food_list": {
"cereali": "130", // gr
"latte": "100" // ml
},
"allergies": [
"glutine",
"uova",
...
],
"dietary_preferences": "vegano"
}
4. getFoodCategories.
Questa API serve per farsi ritornare la lista delle categorie di alimenti, utile ad esempio per la maschera di esclusione di alcune pietanze in base ai gusti del paziente. Ritorno un oggetto che può essere convertito in json con un semplice elenco
Esempio di utilizzo:
$foodData = [ // the food data in JSON format. ]; $response = $client->getRecipes($foodData); print_r($response);
Ora i commenti nelle porzioni di codice sono esattamente come nel testo originale!
Aggiunta Nuovi Servizi
Il SDK è progettato per essere esteso con ulteriori servizi in futuro. Ogni nuovo servizio sarà documentato e aggiunto alla lista dei metodi disponibili in questo README.
Licenza
Questo progetto è concesso in licenza sotto la Licenza MIT.
tidycode/ai-php-sdk 适用场景与选型建议
tidycode/ai-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tidycode/ai-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tidycode/ai-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-02