Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions fastchat/llm_judge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import time
from typing import Optional

import openai
from openai import OpenAI, OpenAIError

import anthropic

from fastchat.model.model_adapter import get_conversation_template
Expand Down Expand Up @@ -398,20 +399,21 @@ def play_a_match_pair(match: MatchPair, output_file: str):


def chat_compeletion_openai(model, conv, temperature, max_tokens):
client = OpenAI()
output = API_ERROR_OUTPUT
for _ in range(API_MAX_RETRY):
try:
messages = conv.to_openai_api_messages()
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model=model,
messages=messages,
n=1,
temperature=temperature,
max_tokens=max_tokens,
max_tokens=max_tokens
)
output = response["choices"][0]["message"]["content"]
output = response.choices[0].message.content
break
except openai.error.OpenAIError as e:
except OpenAIError as e:
print(type(e), e)
time.sleep(API_RETRY_SLEEP)

Expand Down
2 changes: 1 addition & 1 deletion fastchat/llm_judge/gen_api_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_answer(
args = parser.parse_args()

if args.openai_api_base is not None:
openai.api_base = args.openai_api_base
raise ValueError("The 'openai.api_base' option is not available in openai>=1.0, pass it when you instantiate the client, e.g. 'OpenAI(base_url=args.openai_api_base)")

question_file = f"data/{args.bench_name}/question.jsonl"
questions = load_questions(question_file, args.question_begin, args.question_end)
Expand Down