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

Enable azure openai engines #20

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Changes from 1 commit
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
27 changes: 18 additions & 9 deletions py/autoevals/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,21 @@ def __init__(
render_args=None,
max_tokens=None,
temperature=None,
engine=None
):
found = False
for m in SUPPORTED_MODELS:
# Prefixes are ok, because they are just time snapshots
if model.startswith(m):
found = True
break
if not found:
raise ValueError(f"Unsupported model: {model}. Currently only supports OpenAI chat models.")
if engine is None:
for m in SUPPORTED_MODELS:
# Prefixes are ok, because they are just time snapshots
if model.startswith(m):
found = True
break
if not found:
raise ValueError(f"Unsupported model: {model}. Currently only supports OpenAI chat models.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to just remove this check altogether — we definitely support more than the listed models, and "non-chat" flavored models are all deprecated at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


self.name = name
self.model = model
self.engine = engine
self.messages = messages
self.choice_scores = choice_scores
self.classification_functions = classification_functions
Expand Down Expand Up @@ -136,6 +139,7 @@ def _request_args(self, output, expected, **kwargs):
return dict(
Completion=openai.ChatCompletion,
model=self.model,
engine=self.engine,
messages=self._render_messages(output=output, expected=expected, **kwargs),
functions=self.classification_functions,
function_call={"name": "select_choice"},
Expand Down Expand Up @@ -176,6 +180,7 @@ class ModelGradedSpec:
prompt: str
choice_scores: dict[str, float]
model: Optional[str] = None
engine: Optional[str] = None
use_cot: Optional[bool] = None
temperature: Optional[float] = None

Expand All @@ -195,6 +200,7 @@ def __init__(
use_cot=True,
max_tokens=512,
temperature=0,
engine=None
):
choice_strings = list(choice_scores.keys())

Expand All @@ -214,12 +220,13 @@ def __init__(
classification_functions=build_classification_functions(use_cot),
max_tokens=max_tokens,
temperature=temperature,
engine=engine,
render_args={"__choices": choice_strings},
)

@classmethod
def from_spec(cls, name: str, spec: ModelGradedSpec, **kwargs):
return cls(name, spec.prompt, spec.choice_scores, **kwargs)
return cls(name, spec.prompt, spec.choice_scores, **kwargs)

@classmethod
def from_spec_file(cls, name: str, path: str, **kwargs):
Expand All @@ -229,10 +236,12 @@ def from_spec_file(cls, name: str, path: str, **kwargs):


class SpecFileClassifier(LLMClassifier):
def __new__(cls, model=None, use_cot=None, max_tokens=None, temperature=None):
def __new__(cls, model=None, engine=None, use_cot=None, max_tokens=None, temperature=None):
kwargs = {}
if model is not None:
kwargs["model"] = model
if engine is not None:
kwargs["engine"] = engine
if use_cot is not None:
kwargs["use_cot"] = use_cot
if max_tokens is not None:
Expand Down