Skip to content

Commit

Permalink
add base_url option
Browse files Browse the repository at this point in the history
  • Loading branch information
andre15silva committed Feb 13, 2025
1 parent fdd63f4 commit 0b8df61
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions elleelleaime/generate/strategies/models/openai/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ def __init__(self, model_name: str, **kwargs) -> None:
self.temperature = kwargs.get("temperature", 0.0)
self.n_samples = kwargs.get("n_samples", 1)
self.reasoning_effort = kwargs.get("reasoning_effort", "high")
self.base_url = kwargs.get("base_url", None)
self.batching = kwargs.get("batching", True)

load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
self.client = openai.OpenAI(api_key=openai.api_key)
self.client = openai.OpenAI(api_key=openai.api_key, base_url=self.base_url)

@backoff.on_exception(backoff.expo, Exception)
def _completions_with_backoff(self, **kwargs):
Expand All @@ -27,8 +29,7 @@ def _generate_impl(self, chunk: List[str]) -> Any:
result = []

for prompt in chunk:
# TODO: Temporary fix to handle beta version of "oX" family of models
if self.model_name.startswith("o"):
if not self.batching:
result_sample = []
for _ in range(self.n_samples):
completion = self._completions_with_backoff(
Expand Down

0 comments on commit 0b8df61

Please sign in to comment.