Skip to content

Commit 84aaa5a

Browse files
committed
fix(generator): fix JSON decoding error
- Fix JSON decoding error in OpenAIGenerator.php
1 parent eaf9606 commit 84aaa5a

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

README-zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ composer require guanguans/ai-commit --dev -v
4343

4444
```shell
4545
# 配置 OpenAI API key(https://platform.openai.com/account/api-keys)
46+
./ai-commit config set generators.openaichat.api_key sk-... --global
4647
./ai-commit config set generators.openai.api_key sk-... --global
4748

4849
# 生成且提交信息

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ composer require guanguans/ai-commit --dev -v
4343

4444
```shell
4545
# Config OpenAI API key(https://platform.openai.com/account/api-keys)
46+
./ai-commit config set generators.openaichat.api_key sk-... --global
4647
./ai-commit config set generators.openai.api_key sk-... --global
4748

4849
# Generate and commit message

app/Generators/OpenAIGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function getWriter(?string &$messages): \Closure
9292
}
9393

9494
// (正常|错误|流)响应
95-
$rowResponse = (array) json_decode($this->openAI::hydrateData($data), true, 512, JSON_THROW_ON_ERROR);
95+
$rowResponse = (array) json_decode($this->openAI::hydrateData($data), true);
9696
$messages .= $text = static::extractCompletion($rowResponse);
9797
$this->output->write($text);
9898
};

config/ai-commit.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,45 +80,45 @@
8080
* The list of generators.
8181
*/
8282
'generators' => [
83-
'openai' => [
83+
'openaichat' => [
8484
'driver' => 'openai',
8585
'http_options' => [
86-
// GuzzleHttp\RequestOptions::PROXY => 'http://localhost:8125/v1',
86+
// guzzlehttp\requestoptions::proxy => 'https://proxy.com/v1',
8787
],
8888
'api_key' => env('OPENAI_API_KEY', 'sk-...'),
8989
'completion_parameters' => [
90-
'model' => 'text-davinci-003', // ['text-davinci-003', 'text-davinci-002']
91-
// 'prompt' => $prompt,
92-
'suffix' => null,
90+
'model' => 'gpt-3.5-turbo', // ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']
91+
// 'messages' => 'required|array',
9392
'max_tokens' => 500,
9493
'temperature' => 0.0,
9594
'top_p' => 1.0,
9695
'n' => 1,
9796
'stream' => true,
98-
'logprobs' => null,
99-
'echo' => false,
10097
'stop' => null,
10198
'presence_penalty' => 0,
10299
'frequency_penalty' => 0,
103-
'best_of' => 1,
104100
// 'logit_bias' => null,
105101
'user' => Illuminate\Support\Str::uuid()->toString(),
106102
],
107103
],
108-
'openaichat' => [
104+
'openai' => [
109105
'driver' => 'openai',
110106
'api_key' => env('OPENAI_API_KEY', 'sk-...'),
111107
'completion_parameters' => [
112-
'model' => 'gpt-3.5-turbo', // ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']
113-
// 'messages' => $messages,
108+
'model' => 'text-davinci-003', // ['text-davinci-003', 'text-davinci-002']
109+
// 'prompt' => 'string|array',
110+
'suffix' => null,
114111
'max_tokens' => 500,
115112
'temperature' => 0.0,
116113
'top_p' => 1.0,
117114
'n' => 1,
118115
'stream' => true,
116+
'logprobs' => null,
117+
'echo' => false,
119118
'stop' => null,
120119
'presence_penalty' => 0,
121120
'frequency_penalty' => 0,
121+
'best_of' => 1,
122122
// 'logit_bias' => null,
123123
'user' => Illuminate\Support\Str::uuid()->toString(),
124124
],

0 commit comments

Comments
 (0)