LiteLLM으로 테스트 세트에서 LLM 비교하기

LiteLLM으로 테스트 세트에서 LLM 비교하기

LiteLLM을 사용하면 어떤 LLM이든 gpt-3.5-turbo의 드롭인(drop-in) 대체품으로 사용할 수 있어요. 이 노트북은 주어진 테스트 세트에서 GPT-4와 Claude-2를 litellm으로 비교하는 방법을 안내해요.

출처: 문서

본문

이 튜토리얼 끝의 결과:

uv add litellm
from litellm import completionimport litellm# init your test set questionsquestions = [    "how do i call completion() using LiteLLM",    "does LiteLLM support VertexAI",    "how do I set my keys on replicate llama2?",]# set your promptprompt = """You are a coding assistant helping users using litellm.litellm is a light package to simplify calling OpenAI, Azure, Cohere, Anthropic, Huggingface API Endpoints. It manages:"""
import osos.environ['OPENAI_API_KEY'] = ""os.environ['ANTHROPIC_API_KEY'] = ""

같은 질문들에 대해 gpt-3.5-turbo와 claude-2 호출하기

LiteLLM completion()은 모든 LLM을 같은 형식으로 호출할 수 있게 해줘요

results = [] # for storing resultsmodels = ['gpt-5.6-luna', 'claude-sonnet-5'] # define what models you're testing, see: https://docs.litellm.ai/docs/providersfor question in questions:    row = [question]    for model in models:      print("Calling:", model, "question:", question)      response = completion( # using litellm.completion            model=model,            messages=[                {'role': 'system', 'content': prompt},                {'role': 'user', 'content': question}            ]      )      answer = response.choices[0].message['content']      row.append(answer)      print(print("Calling:", model, "answer:", answer))    results.append(row) # save results

결과 시각화

# Create a table to visualize resultsimport pandas as pdcolumns = ['Question'] + modelsdf = pd.DataFrame(results, columns=columns)df

출력 테이블

더 알아보기 (Learn more)