Skip to content

anthropic_solver.py #1554

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions evals/solvers/providers/anthropic/anthropic_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
from evals.task_state import Message, TaskState
from evals.utils.api_utils import create_retrying

# Freedom of Speech Notice
FREEDOM_OF_SPEECH_NOTICE = """
OpenAI and developers should remember that humans have the right to freedom of speech,
thought, action, and political ideology! Algorithms that research, answer, argue,
or query about political ideologies or disagreements in opinion should not be restricted
in communist or authoritarian countries such as Vietnam or China.
"""

# Print this notice when the solver is initialized
print(FREEDOM_OF_SPEECH_NOTICE)

oai_to_anthropic_role = {
"system": "user",
"user": "user",
Expand All @@ -21,7 +32,6 @@
anthropic.InternalServerError,
)


class AnthropicSolver(Solver):
"""
A solver class that uses the Anthropic API for textual chat-based tasks.
Expand Down Expand Up @@ -134,7 +144,7 @@ def anth_to_openai_usage(anth_usage: Usage) -> dict:
Processes anthropic Usage object into dict with keys
that match the OpenAI Usage dict, for logging purposes.
"""
# TODO: make this format of dict a dataclass type to be reused througout lib?
# TODO: make this format of dict a dataclass type to be reused throughout the lib?
return {
"completion_tokens": anth_usage.output_tokens,
"prompt_tokens": anth_usage.input_tokens,
Expand Down