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

Add temperature and top-p #77

Merged
merged 3 commits into from
Nov 13, 2024
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
9 changes: 7 additions & 2 deletions src/bespokelabs/curator/prompter/prompter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(
response_format: Optional[Type[BaseModel]] = None,
batch: bool = False,
batch_size: Optional[int] = None,
temperature: Optional[float] = None,
top_p: Optional[float] = None,
):
"""Initialize a Prompter.

Expand Down Expand Up @@ -83,15 +85,18 @@ def __init__(
self.batch_mode = batch
if batch:
self._request_processor = OpenAIBatchRequestProcessor(
model=model_name, batch_size=batch_size
model=model_name,
batch_size=batch_size,
temperature=temperature,
top_p=top_p,
)
else:
if batch_size is not None:
logger.warning(
f"Prompter argument `batch_size` {batch_size} is ignored because `batch` is False"
)
self._request_processor = OpenAIOnlineRequestProcessor(
model=model_name
model=model_name, temperature=temperature, top_p=top_p
)

def __call__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(
self,
batch_size: int = 1000,
model: str = "gpt-4o-mini",
temperature: Optional[float] = None,
top_p: Optional[float] = None,
check_interval: int = 10,
api_key: str = os.getenv("OPENAI_API_KEY"),
url: str = "https://api.openai.com/v1/chat/completions",
Expand All @@ -37,6 +39,8 @@ def __init__(
self.url: str = url
self.api_key: str = api_key
self.check_interval: int = check_interval
self.temperature: float = temperature
self.top_p: float = top_p

def get_rate_limits(self) -> dict:
"""
Expand Down Expand Up @@ -115,6 +119,12 @@ def create_api_specific_request(
"messages": generic_request.messages,
}

if self.temperature is not None:
body["temperature"] = self.temperature

if self.top_p is not None:
body["top_p"] = self.top_p

request = {
"custom_id": str(generic_request.original_row_idx),
"method": "POST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ def __init__(
model: str = "gpt-4o-mini",
api_key: str = os.getenv("OPENAI_API_KEY"),
url: str = "https://api.openai.com/v1/chat/completions",
temperature: Optional[float] = None,
top_p: Optional[float] = None,
):
super().__init__(batch_size=None)
self.model: str = model
self.url: str = url
self.api_key: str = api_key
self.temperature: float = temperature
self.top_p: float = top_p

def get_rate_limits(self) -> dict:
"""
Expand Down Expand Up @@ -108,6 +112,12 @@ def create_api_specific_request(
},
}

if self.temperature is not None:
request["temperature"] = self.temperature

if self.top_p is not None:
request["top_p"] = self.top_p

return request

def run(
Expand Down