Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit276bb9b

Browse files
committed
Add optional chaining for choices array access
1 parentf6b2bee commit276bb9b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

‎src/lib/server/endpoints/openai/openAIChatToTextGenerationStream.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export async function* openAIChatToTextGenerationStream(
6161
:typeofdelta?.reasoning_content==="string"
6262
?(delta.reasoning_contentasstring)
6363
:"";
64-
constlast=choices[0]?.finish_reason==="stop"||choices[0]?.finish_reason==="length";
64+
constlast=choices?.[0]?.finish_reason==="stop"||choices?.[0]?.finish_reason==="length";
6565

6666
// if the last token is a stop and the tool buffer is not empty, yield it as a generated_text
67-
if(choices[0]?.finish_reason==="stop"&&toolBuffer.length>0){
67+
if(choices?.[0]?.finish_reason==="stop"&&toolBuffer.length>0){
6868
yield{
6969
token:{
7070
id:tokenId++,
@@ -79,7 +79,7 @@ export async function* openAIChatToTextGenerationStream(
7979
}
8080

8181
// weird bug where the parameters are streamed in like this
82-
if(choices[0]?.delta?.tool_calls){
82+
if(choices?.[0]?.delta?.tool_calls){
8383
constcalls=Array.isArray(choices[0].delta.tool_calls)
8484
?choices[0].delta.tool_calls
8585
:[choices[0].delta.tool_calls];

‎src/lib/server/endpoints/openai/openAICompletionToTextGenerationStream.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export async function* openAICompletionToTextGenerationStream(
1212
lettokenId=0;
1313
forawait(constcompletionofcompletionStream){
1414
const{ choices}=completion;
15-
consttext=choices[0]?.text??"";
16-
constlast=choices[0]?.finish_reason==="stop"||choices[0]?.finish_reason==="length";
15+
consttext=choices?.[0]?.text??"";
16+
constlast=choices?.[0]?.finish_reason==="stop"||choices?.[0]?.finish_reason==="length";
1717
if(text){
1818
generatedText=generatedText+text;
1919
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp