Skip to content

Conversation

michaelAlvarino
Copy link
Contributor

This PR removes OpenAI initialization calls that happen at import time so developers who want to use Evals as a library rather than a CLI tool, without the OPENAI_API_KEY environment variable specified, can do so.

Importing Evals libraries from python for use as a library rather
than a CLI tool fails if the OPENAI_API_KEY is not specified.
Normally this wouldn't be a problem, if we were evaluating an OpenAI
model, however there are cases where we may not be evaluating an
OpenAI model. In those cases we may not set the OPENAI_API_KEY in
advance.

In addition, this PR makes changes to some unit tests either to
pass, or skip those tests when the necessary API keys are not in
the environment.

def openai_chatcompletion_create(*args, **kwargs):
return client.chat.completions.create(*args, **kwargs)
return OpenAI(api_key=os.environ.get("OPENAI_API_KEY")).chat.completions.create(*args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of creating the client fresh on every call of this function, can we pass it in from the caller? Ideally it would be instantiated in an __init__ in a class like the changes you made in other files

logging.info(f"Final report: {final_report}. Not writing anywhere.")


def _green(str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

i assume we don't want these deletions in this file?

def __init__(self, registry_paths: Sequence[Union[str, Path]] = DEFAULT_PATHS):
self._registry_paths = [Path(p) if isinstance(p, str) else p for p in registry_paths]
try:
self.client = OpenAI()
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))?

A list of Embedding namedtuples where each Embedding
represents the input string and its corresponding vector.
"""
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's move this to an __init__ like in the GPTValidator?

import anthropic
from anthropic import Anthropic
from anthropic.types import ContentBlock, MessageParam, Usage
from anthropic.types import TextBlock, MessageParam, Usage
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems unrelated to this PR, maybe let's pull it into a different one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants