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

Refactor to use yarl package for safe URL manipulation #74

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/llmperf/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict, Optional, Tuple
from pydantic import BaseModel


Expand Down
8 changes: 2 additions & 6 deletions src/llmperf/ray_clients/openai_chat_completions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import ray
import requests
from yarl import URL

from llmperf.ray_llm_client import LLMClient
from llmperf.models import RequestConfig
Expand Down Expand Up @@ -54,14 +55,9 @@ def llm_request(self, request_config: RequestConfig) -> Dict[str, Any]:
if not key:
raise ValueError("the environment variable OPENAI_API_KEY must be set.")
headers = {"Authorization": f"Bearer {key}"}
if not address:
raise ValueError("No host provided.")
if not address.endswith("/"):
address = address + "/"
address += "chat/completions"
try:
with requests.post(
address,
URL(address).with_path("/chat/completions"),
json=body,
stream=True,
timeout=180,
Expand Down