Skip to content

Commit d7333af

Browse files
authored
Merge pull request #1 from jmhessel/jack/merge_the_azure_support
Update openai_chat_completions_client.py
2 parents 03872a4 + 5466fd9 commit d7333af

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/llmperf/ray_clients/openai_chat_completions_client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def llm_request(self, request_config: RequestConfig) -> Dict[str, Any]:
5959
if not address.endswith("/"):
6060
address = address + "/"
6161
address += "chat/completions"
62+
if "openai.azure.com" in address:
63+
api_version = os.environ.get("OPENAI_API_VERSION")
64+
if not api_version:
65+
raise ValueError("the environment variable OPENAI_API_VERSION must be set for Azure OpenAI service.")
66+
address = f"{address}?api-version={api_version}"
67+
headers = {"api-key": key} # replace with Authorization: Bearer
68+
6269
try:
6370
with requests.post(
6471
address,
@@ -87,7 +94,10 @@ def llm_request(self, request_config: RequestConfig) -> Dict[str, Any]:
8794
error_msg = data["error"]["message"]
8895
error_response_code = data["error"]["code"]
8996
raise RuntimeError(data["error"]["message"])
90-
97+
98+
if len(data["choices"]) == 0: # azure returns no choices at first
99+
continue
100+
91101
delta = data["choices"][0]["delta"]
92102
if delta.get("content", None):
93103
if not ttft:

0 commit comments

Comments
 (0)