tidycode/ai-php-sdk

Tidycode AI PHP SDK 是一个 PHP API 客户端,允许您集成 Tidycode 部署的人工智能服务。

1.2.2 2024-09-27 08:14 UTC

This package is auto-updated.

Last update: 2024-09-27 08:15:03 UTC


README

此 SDK 允许您将您的 PHP 电子商务与我们的专用人工智能服务集成。目前,SDK 支持 欺诈检测 服务,但设计上可以扩展以支持未来的其他服务。

安装。

要使用此 SDK,您必须将其添加到您的 PHP 项目中。它可以通过 Composer 安装。

将依赖项添加到您的 composer 模块或包的 composer.json

{
  "require": {
    "tidycode/ai-php-sdk":"^1.0"
  }
}

或通过 composer 命令安装

composer require tidycode/ai-php-sdk

然后运行以下命令

composer install

使用欺诈检测

配置。

要开始使用欺诈检测服务,请创建一个 Tidycode\AIClient\FraudDetection 类的实例。

require 'vendor/autoload.php';

use Tidycode\AIClient\FraudDetection;

$client = new FraudDetection('your-api-key');

方法

SDK 提供以下方法

1. detectFraud

检查订单是否疑似欺诈。

参数:一个包含订单数据的 JSON 数组。

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",
    "shipping_method": "[shipment code]",
    "date": "2024-07-23 10:08:56"
}

示例用法:

$orderData = [
    // the order data in JSON format.
];

$response = $client->detectFraud($orderData);
print_r($response);

2. reportFalsePositive

报告一个被错误分类为欺诈的订单。

参数:一个包含订单数据的 JSON 数组。JSON 与 detectFraud 方法相同。

示例用法:

$response = $client->reportFalsePositive($orderData);
print_r($response);

3. reportFalseNegative

报告一个被错误分类为非欺诈的订单。JSON 与 detectFraud 方法相同。

参数:一个包含订单数据的 JSON 数组。

示例用法:

$response = $client->reportFalseNegative($orderData);
print_r($response);

4. paymentList

返回支付方式代码列表。

示例用法:

$paymentCodes = $client->paymentList();
print_r($paymentCodes);

5. shipmentList

返回运输方式代码列表。

示例用法:

$shipmentCodes = $client->shipmentList();
print_r($shipmentCodes);

使用营养助手

配置。

要开始使用营养助手服务,请创建一个 Tidycode\AIClient\NutritionAssistant 类的实例。

require 'vendor/autoload.php';

use Tidycode\AIClient\NutritionAssistant;

$client = new NutritionAssistant('your-api-key');

方法

SDK 提供以下方法

1. getMacro

根据患者数据返回卡路里和推荐的宏量营养素剂量。

参数:一个包含订单数据的 JSON 数组。

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", // % of calories
    "fat_percentage": "25", // % of calories
    "carbohydrate_percentage": "45" // % of calories
}

示例用法:

$customerData = [
    // the customer data in JSON format.
];

$response = $client->getMacro($customerData);
print_r($response);

2. getFoodList

返回食物列表及其剂量,分为五餐,以满足指定的卡路里和宏量营养素剂量。同时尊重食物选择和过敏。

参数:一个包含订单数据的 JSON 数组。

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",
        ...
    ]
}

示例用法:

$caloriesAndMacros = [
    // the calories and macros data in JSON format.
];

$response = $client->getFoodList($caloriesAndMacros);
print_r($response);

3. getRecipes

使用给定的食物列表建议准备和食谱,尽量尊重食物偏好和过敏。

参数:一个包含订单数据的 JSON 数组。

JSON 格式:

{
    "food_list": {
        "cereali": "130", // gr
        "latte": "100" // ml
    },
    "allergies": [
        "glutine",
        "uova",
        ...
    ],
    "dietary_preferences": "vegano"
}

示例用法:

$foodData = [
    // the food data in JSON format.
];

$response = $client->getRecipes($foodData);
print_r($response);

添加新服务。

SDK 设计为可以扩展以支持未来的附加服务。任何新的服务都将被文档化,并添加到本 README 中的可用方法列表。

许可。

本项目采用 MIT 许可证 许可。

SDK Tidycode AIClient per PHP

此 SDK 允许您将您的 PHP 电子商务与我们的专用人工智能服务集成。目前,SDK 支持 欺诈检测 服务,但设计上可以扩展以支持未来的其他服务。

安装

要使用此 SDK,您必须将其添加到您的 PHP 项目中。它可以通过 Composer 安装。

将依赖项添加到您的 composer 模块或包的 composer.json

{
  "require": {
    "tidycode/ai-php-sdk": "^1.0"
  }
}

或通过 composer 命令安装

composer require tidycode/ai-php-sdk

然后运行以下命令

composer install

使用欺诈检测

配置

要开始使用欺诈检测服务,请创建一个 Tidycode\AIClient\FraudDetection 类的实例。

require 'vendor/autoload.php';

use Tidycode\AIClient\FraudDetection;

$client = new FraudDetection('your-api-key');

方法

L'SDK 提供以下方法

1. detectFraud

检查订单是否疑似欺诈。

参数:一个包含订单数据的JSON数组。

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"
}

使用示例:

$orderData = [
    // i dati dell'ordine in formato JSON
];

$response = $client->detectFraud($orderData);
print_r($response);

2. reportFalsePositive

报告被错误地分类为欺诈的订单。

参数:一个包含订单数据的JSON数组。该JSON与detectFraud方法相同。

使用示例:

$response = $client->reportFalsePositive($orderData);
print_r($response);

3. reportFalseNegative

报告被错误地分类为非欺诈的订单。该JSON与detectFraud方法相同。

参数:一个包含订单数据的JSON数组。

使用示例:

$response = $client->reportFalseNegative($orderData);
print_r($response);

4. paymentList

返回支付方式代码的列表。

使用示例:

$paymentCodes = $client->paymentList();
print_r($paymentCodes);

5. shipmentList

返回配送方式代码的列表。

使用示例:

$shipmentCodes = $client->shipmentList();
print_r($shipmentCodes);

我为错误道歉。以下是正确的版本,代码部分完全未做更改,如要求。

Nutrition Assistant的使用

配置

要开始使用Nutrition Assistant服务,请创建Tidycode\AIClient\NutritionAssistant类的一个实例。

require 'vendor/autoload.php';

use Tidycode\AIClient\NutritionAssistant;

$client = new Nutrition Assistant('your-api-key');

方法

L'SDK 提供以下方法

1. getMacro

根据患者的数据返回卡路里和宏量营养素的建议剂量。

参数:一个包含订单数据的JSON数组。

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
}

使用示例:

$customerData = [
    // the customer data in JSON format.
];

$response = $client->getMacro($customerData);
print_r($response);

2. getFoodList

返回一份食物列表,包括相关剂量,分为五大餐,以确保遵守指示的卡路里和宏量营养素。同时考虑食物选择和过敏。

参数:一个包含订单数据的JSON数组。

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",
        ...
    ]
}

使用示例:

$caloriesAndMacros = [
    // the calories and macros data in JSON format.
];

$response = $client->getFoodList($caloriesAndMacros);
print_r($response);

3. getRecipes

使用提供的食物列表来建议准备和食谱,力求遵守食物偏好和过敏。

参数:一个包含订单数据的JSON数组。

JSON格式:

{
    "food_list": {
        "cereali": "130", // gr
        "latte": "100" // ml
    },
    "allergies": [
        "glutine",
        "uova",
        ...
    ],
    "dietary_preferences": "vegano"
}

使用示例:

$foodData = [
    // the food data in JSON format.
];

$response = $client->getRecipes($foodData);
print_r($response);

现在代码部分的注释与原文完全一致!

新增服务

SDK旨在未来扩展其他服务。每个新服务都将被文档化,并添加到此README中提供的可用方法列表。

许可

此项目在MIT许可下发布。