Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: AzureOpenAI.stream_chat causes AttributeError #7657

Closed
apptaro opened this issue Sep 13, 2023 · 3 comments · Fixed by #7665
Closed

[Bug]: AzureOpenAI.stream_chat causes AttributeError #7657

apptaro opened this issue Sep 13, 2023 · 3 comments · Fixed by #7665
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@apptaro
Copy link

apptaro commented Sep 13, 2023

Bug Description

PR #7646 has introduced another issue instead of fixing the bug #7640
Now, AzureOpenAI.stream_chat causes AttributeError.

Look here:
https://github.com/jerryjliu/llama_index/blob/276d976c1cadbee316e6a777b2b37cccfd1d59f0/llama_index/llms/openai.py#L229-L234
and here:
https://github.com/jerryjliu/llama_index/blob/276d976c1cadbee316e6a777b2b37cccfd1d59f0/llama_index/llms/openai.py#L448-L453

"delta" is supposed to be something like { "role": "", content: "" } instead of ""

Version

0.8.25

Steps to Reproduce

Run the following code to reproduce the issue:

import os
from llama_index.llms import OpenAI, AzureOpenAI
from llama_index.llms.base import ChatMessage

use_azure = True

if use_azure:
    os.environ["OPENAI_API_TYPE"] = "azure"
    os.environ["OPENAI_API_VERSION"] = "2023-07-01-preview"
    os.environ["OPENAI_API_BASE"] = "https://xxxx.openai.azure.com/"
    os.environ["OPENAI_API_KEY"] = "xxxxxxxxxxxxxxxxxxxxxxx"
    llm = AzureOpenAI(engine = "gpt-35-turbo")
else:
    os.environ["OPENAI_API_TYPE"] = "open_ai"
    os.environ["OPENAI_API_KEY"] = "sk-xxxxxxxxxxxxxxxxxxxxxxx"
    os.environ["OPENAI_API_BASE"] = "https://api.openai.com/v1"
    llm = OpenAI()

for delta in llm.stream_chat([ChatMessage(content = "Hello!")]):
    print(delta)

Relevant Logs/Tracbacks

$ python3 test.py
Traceback (most recent call last):
  File "/home/ubuntuuser/LlamaIndex_env/project/test.py", line 19, in <module>
    for delta in llm.stream_chat([ChatMessage(content = "Hello!")]):
  File "/home/ubuntuuser/LlamaIndex_env/lib/python3.10/site-packages/llama_index/llms/base.py", line 157, in wrapped_gen
    for x in f_return_val:
  File "/home/ubuntuuser/LlamaIndex_env/lib/python3.10/site-packages/llama_index/llms/openai.py", line 233, in gen
    role = delta.get("role", "assistant")
AttributeError: 'str' object has no attribute 'get'
@apptaro apptaro added bug Something isn't working triage Issue needs to be triaged/prioritized labels Sep 13, 2023
@dosubot
Copy link

dosubot bot commented Sep 13, 2023

🤖

Hi there,

Thanks for reporting this issue. It seems like the 'delta' object is expected to be a dictionary but it's getting a string instead, which is causing the AttributeError.

To help me investigate this further, could you please provide the following additional information:

  1. Can you confirm if this issue is happening consistently or intermittently?
  2. Are there any specific conditions under which this error occurs?
  3. Could you provide the version of Python you're using?
  4. Are there any other dependencies or packages that you're using in your environment which might be relevant to this issue?

This information will help me understand the context better and find a solution for you.

Thanks for your cooperation.


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@apptaro
Copy link
Author

apptaro commented Sep 13, 2023

  1. Happening consistently
  2. Not only for specific condition
  3. I'm using Python 3.10.11, but this issue is not python version specific
  4. No

@logan-markewich
Copy link
Collaborator

@apptaro ha whoops. I don't have access to azure, so hard to actually test it. Will fix again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants