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

feat: support anthropic api with api_dict #2879

Merged
merged 2 commits into from
Jan 8, 2024
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
8 changes: 6 additions & 2 deletions fastchat/llm_judge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,15 @@ def chat_completion_openai_azure(model, conv, temperature, max_tokens, api_dict=
return output


def chat_completion_anthropic(model, conv, temperature, max_tokens):
def chat_completion_anthropic(model, conv, temperature, max_tokens, api_dict=None):
api_key = os.environ["ANTHROPIC_API_KEY"]
if api_dict is not None and "api_key" in api_dict:
api_key = api_dict["api_key"]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
api_key = os.environ["ANTHROPIC_API_KEY"]
if api_dict is not None and "api_key" in api_dict:
api_key = api_dict["api_key"]
if api_dict is not None and "api_key" in api_dict:
api_key = api_dict["api_key"]
else:
api_key = os.environ["ANTHROPIC_API_KEY"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just fix it


output = API_ERROR_OUTPUT
for _ in range(API_MAX_RETRY):
try:
c = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
c = anthropic.Anthropic(api_key=api_key)
prompt = conv.get_prompt()
response = c.completions.create(
model=model,
Expand Down