Skip to content

Conversation

@jungkyuYang
Copy link

Fix: Correct streamChunk content access in README example

Problem

The README example incorrectly uses streamChunk.content, but the actual response structure requires streamChunk.choices[0].message.content to access the message content.

Solution

Updated the README example to use the correct API response structure:

  • Changed from: streamChunk.content
  • Changed to: streamChunk.choices[0].message.content

Verification

1. StreamChunk Interface Definition

Location: src/resources/chat/chat.ts

export interface StreamChunk {
  id: string;
  choices: Array<Shared.Choice>;  // ✅ Has 'choices' property
  created: number;
  model: string;
  // ... other properties
  // ❌ Does NOT have 'content' property
}

2. Choice Interface Definition

Location: src/resources/shared.ts

export interface Choice {
  delta: ChatMessageOutput;
  index: number;
  message: ChatMessageOutput;  // ✅ Has 'message' property
  finish_reason?: 'stop' | 'length' | null;
}

3. ChatMessageOutput Interface Definition

Location: src/resources/shared.ts

export interface ChatMessageOutput {
  content: string | Array<...> | null;  // ✅ Has 'content' property
  role: 'system' | 'user' | 'assistant' | 'tool';
  // ... other properties
}

4. Correct Access Path

StreamChunk
  └── choices: Array<Choice>
        └── [0] (first Choice)
              └── message: ChatMessageOutput
                    └── content: string | Array<...> | null

Correct usage:

streamChunk.choices[0].message.content

Impact

This change ensures developers can properly access the message content from chat completions without encountering runtime errors.

the example incorrectly uses streamChunk.content, but the actual response structure requires streamChunk.choices[0].message.content to access the message content.

this change updates the README to reflect the correct API response structure, ensuring developers can properly access the message content from chat completions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant