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

Fix OpenAiInferenceEngine #1193

Merged
merged 6 commits into from
Sep 8, 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
19 changes: 13 additions & 6 deletions src/unitxt/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ class OpenAiInferenceEngineParamsMixin(Artifact):
top_p: Optional[float] = None
top_logprobs: Optional[int] = 20
logit_bias: Optional[Dict[str, int]] = None
logprobs: Optional[bool] = None
logprobs: Optional[bool] = True
n: Optional[int] = None
parallel_tool_calls: bool = None
parallel_tool_calls: Optional[bool] = None
service_tier: Optional[Literal["auto", "default"]] = None


Expand All @@ -278,9 +278,9 @@ class OpenAiInferenceEngineParams(Artifact):
top_p: Optional[float] = None
top_logprobs: Optional[int] = 20
logit_bias: Optional[Dict[str, int]] = None
logprobs: Optional[bool] = None
logprobs: Optional[bool] = True
n: Optional[int] = None
parallel_tool_calls: bool = None
parallel_tool_calls: Optional[bool] = None
service_tier: Optional[Literal["auto", "default"]] = None


Expand Down Expand Up @@ -312,6 +312,13 @@ def prepare_engine(self):

self._set_inference_parameters()

def _get_completion_kwargs(self):
return {
k: v
for k, v in self.to_dict([OpenAiInferenceEngineParamsMixin]).items()
if v is not None
}

def _infer(self, dataset):
outputs = []
for instance in tqdm(dataset, desc="Inferring with openAI API"):
Expand All @@ -327,7 +334,7 @@ def _infer(self, dataset):
}
],
model=self.model_name,
**self.to_dict([OpenAiInferenceEngineParamsMixin]),
**self._get_completion_kwargs(),
)
output = response.choices[0].message.content

Expand All @@ -350,7 +357,7 @@ def _infer_log_probs(self, dataset):
}
],
model=self.model_name,
**self.to_dict([OpenAiInferenceEngineParamsMixin]),
**self._get_completion_kwargs(),
)
top_logprobs_response = response.choices[0].logprobs.content
output = [
Expand Down
Loading