leandroferreirama/openai-php
最新稳定版本:v1.0.5
Composer 安装命令:
composer require leandroferreirama/openai-php
包简介
OpenAI PHP Assistant API
README 文档
README
This is a simple PHP client for interacting with the OpenAI API, allowing you to create assistants, manage threads, and send messages.
Installation
You can install the package via Composer. Run the following command in your terminal:
composer require leandroferreirama/openai-php
Environment Configuration
Before you start using the package, create a copy of the .env.example file and rename it to .env. Then, paste your OpenAI API key into the .env file.
Usage
Creating an Assistant
You can create an assistant using the following code:
$client = new OpenAIClient(); $assistant = $client->getAssistant()->create(Model::GPT_4, 'Answer as if you were a tour guide.');
Creating a Thread
To create a thread, use the following:
$thread = $client->getThread()->create();
Sending Messages
Send messages to the assistant like this:
$response = $client->askAssistant($assistantId, $threadId, 'What are the best places to visit in Argentina?');
Getting Responses
The assistant's response will be returned as a string:
echo $response;
Example
You can find an example of usage in the example/index.php file.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Cliente PHP para OpenAI
Este é um cliente PHP simples para interagir com a API da OpenAI, permitindo que você crie assistentes, gerencie threads e envie mensagens.
Instalação
Você pode instalar o pacote via Composer. Execute o seguinte comando no seu terminal:
composer require leandroferreirama/openai-php
Configuração do Ambiente
Antes de começar a usar o pacote, crie uma cópia do arquivo .env.example e renomeie para .env. Em seguida, cole sua chave da API da OpenAI no arquivo .env.
Uso
Criando um Assistente
Você pode criar um assistente usando o seguinte código:
$client = new OpenAIClient(); $assistant = $client->getAssistant()->create(Model::GPT_4, 'Responda como se você fosse um guia turístico.');
Criando uma Thread
Para criar uma thread, use o seguinte:
$thread = $client->getThread()->create();
Enviando Mensagens
Envie mensagens ao assistente assim:
$response = $client->askAssistant($assistantId, $threadId, 'Quais são os melhores lugares para visitar na Argentina?');
Obtendo Respostas
A resposta do assistente será retornada como uma string:
echo $response;
Exemplo
Você pode encontrar um exemplo de uso no arquivo example/index.php.
Licença
Este projeto é licenciado sob a Licença MIT. Veja o arquivo LICENSE para detalhes.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-21