omeratagunn / openai
用于openAI cli的Composer包
v1
2020-10-29 19:49 UTC
Requires
- guzzlehttp/guzzle: ^7.2
This package is auto-updated.
Last update: 2024-09-29 06:08:33 UTC
README
#OpenAI-php
PHP客户端,用于https://beta.openai.com/docs/api-reference
- Guzzle客户端。查看示例以按您希望的方式解析响应。
只需调用composer
composer require omeratagunn/openai
#示例用法
$test = new OpenAI('your-key');
// default davinci, to see other engines please visit openAI documentation//
$test->setEngineId('davinci');
try {
$a = $test->postCompletions([
'prompt' => "I wish i had a flying fish",
'max_tokens' => 5,
'temperature' => 1,
'top_p' => 1,
'n' => 1,
'stream' => false,
'logprobs' => null,
'stop' => "\n"
]);
$response = $a->getBody()->getContents();
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
$e->getMessage();
}
try {
$b = $test->search([
'documents' => [
'white house',
'hospital',
'school'
],
'query' => "the president"
]);
$response = $b->getBody()->getContents();
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
$e->getMessage();
}
#许可协议在MIT许可下发布