softcreatr/php-mistral-ai-sdk

Mistral AI API的强大且易于使用的PHP SDK,允许无缝集成高级AI功能到您的PHP项目中。

1.1.0 2024-07-12 19:19 UTC

This package is auto-updated.

Last update: 2024-09-12 19:42:56 UTC


README

Build Latest Release ISC licensed Plant Tree Codecov branch Code Climate maintainability

此PHP库为Mistral API提供简单的包装,允许您轻松将Mistral API集成到PHP项目中。

特性

  • 易于与Mistral API集成
  • 支持所有Mistral API端点
  • 使用PSR-17和PSR-18兼容的HTTP客户端和工厂来制作API请求

要求

安装

您可以通过Composer安装库

composer require softcreatr/php-mistral-ai-sdk

用法

首先,将库包含到您的项目中

<?php

require_once 'vendor/autoload.php';

然后,使用API密钥、组织(可选)、HTTP客户端、HTTP请求工厂和HTTP流工厂创建一个MistralAI类的实例

use SoftCreatR\MistralAI\MistralAI;

$apiKey = 'your_api_key';

// Replace these lines with your chosen PSR-17 and PSR-18 compatible HTTP client and factories
$httpClient = new YourChosenHttpClient();
$requestFactory = new YourChosenRequestFactory();
$streamFactory = new YourChosenStreamFactory();
$uriFactory = new YourChosenUriFactory();

$mistral = new MistralAI($requestFactory, $streamFactory, $uriFactory, $httpClient, $apiKey);

现在您可以使用魔术方法__call调用任何受支持的MistralAI API端点

$response = $mistral->createChatCompletion([
    'model' => 'mistral-tiny',
    'messages' => [
        [
            'role' => 'user',
            'content' => 'Who is the most renowned French painter?'
        ],
    ],
]);

// Process the API response
if ($response->getStatusCode() === 200) {
    $responseObj = json_decode($response->getBody()->getContents(), true);
    
    print_r($responseObj);
} else {
    echo "Error: " . $response->getStatusCode();
}

有关每个端点的更多详细信息,请参阅Mistral API文档以及存储库中提供的示例

支持的方法

聊天完成

嵌入

模型

变更日志

有关更改和更新的详细列表,请参阅CHANGELOG.md文件。我们遵循语义版本控制并为每个版本记录显著更改。

已知问题和限制

流支持

目前,不支持流。我们计划尽快解决这个问题。目前,请注意,这些方法不能用于流式传输目的。

如果您需要流功能,请考虑使用替代实现或关注此库的未来更新。

许可

此库采用ISC许可。有关更多信息,请参阅LICENSE文件。

维护者 🛠️

贡献者 ✨