Closed azachar closed 8 months ago
Hi @azachar and thanks for the detailed report!
I can't prioritize this work right now, but I think the solution you suggest is a good one, trapping a KeyError
and returning None with a message around the format was not what we expected.
I'm putting this up for contributions wanted!
@masci I'd like to work on this issue. And just to be clear this is a simple case of modifying the function to check that the event_data has a certain structure and in the case it doesn't , just returning none and logging a warning?
Hey @masci , I would like to work on this issue, could you please assign this to me?
Hello,
In the
_extract_token
method of theChatGPTInvocationLayer
class, there's an assumption that theevent_data["choices"]
array will always have at least one item with adelta
key. However, based on observed behavior, OpenAI might provide responses without this expected structure on some preview endpoints. This can lead to unexpected errors.Steps To Reproduce:
data: {"id":"chatcmpl-XXXX","object":"chat.completion.chunk","created":1692979866,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"role":"assistant"},"content_filter_results":{}}],"usage":null}
data: {"id":"chatcmpl-YYY","object":"chat.completion.chunk","created":1692979866,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":"stop","delta":{},"content_filter_results":{}}],"usage":null}
data: [DONE]
Link to the line of _extract_token
Solution suggestion:
Consider adding checks to ensure
event_data["choices"]
has the expected structure before accessing its items. On encountering a structure that deviates from the norm, the method could either provide a warning log and return a None value or manage the deviation in another user-friendly manner.Looking forward to hearing your thoughts and insights on this!
Thank you for response!
Best regards, Andrej