simonw / simonw/llm

Error: list index out of range with 2023-07-01-preview version

Open
#294 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
12.5k
Forks
998
Avg merge
3d 13h
Merged PRs (30d)
10

Description

Streaming response doesn't work with Azure models. This can be fixed by handling the JSON chunks differently.

There is an issue with AzureChatOpenAI Streaming first response chunk
response["choices"][0] is causing the issue because the server returns an empty array.

This doesn't occur for 2023-03-15-preview version

During streaming, the first chunk may only contain the name of an OpenAI function and not any arguments. In this case, the current code presumes there is a streaming response and tries to append to it, but gets a KeyError.

This can be fixed by checking if the arguments key exists, and if not, creates a new entry instead of appending.

Example:

llm -m azure 'Tell me a quantum entaglement joke' --system 'You are Albert Einstein' --no-stream

Why don't quantum physicists make jokes about entanglement?
Because when they do, they instantly become the subject of someone else's humor halfway around the world!

llm -m azure 'Tell me a quantum entaglement joke' --system 'You are Albert Einstein'

Error: list index out of range

Please refer:
https://github.com/jerryjliu/llama_index/issues/7640

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the provided llm -m azure streaming command, then inspect the AzureChatOpenAI streaming response handling around response["choices"][0] and function-call chunks. Done means the 2023-07-01-preview response streams without an index or key error, including chunks that contain only a function name or arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, python
Domain
backend, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.