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

Update openai_chat_completions_client.py #1

Merged
merged 4 commits into from
Aug 14, 2024
Merged
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
12 changes: 11 additions & 1 deletion src/llmperf/ray_clients/openai_chat_completions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def llm_request(self, request_config: RequestConfig) -> Dict[str, Any]:
if not address.endswith("/"):
address = address + "/"
address += "chat/completions"
if "openai.azure.com" in address:
api_version = os.environ.get("OPENAI_API_VERSION")
if not api_version:
raise ValueError("the environment variable OPENAI_API_VERSION must be set for Azure OpenAI service.")
address = f"{address}?api-version={api_version}"
headers = {"api-key": key} # replace with Authorization: Bearer

try:
with requests.post(
address,
Expand Down Expand Up @@ -87,7 +94,10 @@ def llm_request(self, request_config: RequestConfig) -> Dict[str, Any]:
error_msg = data["error"]["message"]
error_response_code = data["error"]["code"]
raise RuntimeError(data["error"]["message"])


if len(data["choices"]) == 0: # azure returns no choices at first
continue

delta = data["choices"][0]["delta"]
if delta.get("content", None):
if not ttft:
Expand Down