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

Fix azure streaming #7646

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bug Fixes / Nits
- Allowed `simple` mode to work with `as_chat_engine()` (#7637)
- Fixed index error in azure streaming (#7646)

## [0.8.24] - 2023-09-11

Expand Down
3 changes: 1 addition & 2 deletions llama_index/llms/azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from llama_index.llms.openai import OpenAI

AZURE_OPENAI_API_TYPE = "azure"
AZURE_OPENAI_VERSION = "2023-08-01-preview"


class AzureOpenAI(OpenAI):
Expand Down Expand Up @@ -47,7 +46,7 @@ def __init__(
api_key: Optional[str] = None,
api_type: Optional[str] = AZURE_OPENAI_API_TYPE,
api_base: Optional[str] = None,
api_version: Optional[str] = AZURE_OPENAI_VERSION,
api_version: Optional[str] = None,
callback_manager: Optional[CallbackManager] = None,
**kwargs: Any,
) -> None:
Expand Down
20 changes: 16 additions & 4 deletions llama_index/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ def gen() -> ChatResponseGen:
stream=True,
**all_kwargs,
):
delta = response["choices"][0]["delta"]
if len(response["choices"]) > 0:
delta = response["choices"][0]["delta"]
else:
delta = ""
role = delta.get("role", "assistant")
content_delta = delta.get("content", "") or ""
content += content_delta
Expand Down Expand Up @@ -302,7 +305,10 @@ def gen() -> CompletionResponseGen:
stream=True,
**all_kwargs,
):
delta = response["choices"][0]["text"]
if len(response["choices"]) > 0:
delta = response["choices"][0]["text"]
else:
delta = ""
text += delta
yield CompletionResponse(
delta=delta,
Expand Down Expand Up @@ -439,7 +445,10 @@ async def gen() -> ChatResponseAsyncGen:
stream=True,
**all_kwargs,
):
delta = response["choices"][0]["delta"]
if len(response["choices"]) > 0:
delta = response["choices"][0]["delta"]
else:
delta = ""
role = delta.get("role", "assistant")
content_delta = delta.get("content", "") or ""
content += content_delta
Expand Down Expand Up @@ -517,7 +526,10 @@ async def gen() -> CompletionResponseAsyncGen:
stream=True,
**all_kwargs,
):
delta = response["choices"][0]["text"]
if len(response["choices"]) > 0:
delta = response["choices"][0]["text"]
else:
delta = ""
text += delta
yield CompletionResponse(
delta=delta,
Expand Down