LangSmith는 LLM 애플리케이션을 디버깅, 테스트, 평가, 모니터링 하기 위한 통합 플랫폼이며 개발자가 애플리케이션 구축에 더욱 집중할 수 있도록 도와주는 도구입니다.
LangChain을 사용할 필요는 없으며 자체적으로 작동합니다.
LangSmith Install
# Install
pip install -U langsmith
# API Key Create
# https://smith.langchain.com/settings
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
# The below examples use the OpenAI API, though it's not necessary in general
export OPENAI_API_KEY=<your-openai-api-key>
# Log Trace Sample
import openai
from langsmith.wrappers import wrap_openai
from langsmith import traceable
# Auto-trace LLM calls in-context
client = wrap_openai(openai.Client())
@traceable # Auto-trace this function
def pipeline(user_input: str):
result = client.chat.completions.create(
messages=[{"role": "user", "content": user_input}],
model="gpt-3.5-turbo"
)
return result.choices[0].message.content
pipeline("Hello, world!")
# Out: Hello there! How can I assist you today?
# Run evaluation Sample
from langsmith import Client
from langsmith.evaluation import evaluate
client = Client()
# Define dataset: these are your test cases
dataset_name = "Sample Dataset"
dataset = client.create_dataset(dataset_name, description="A sample dataset in LangSmith.")
client.create_examples(
inputs=[
{"postfix": "to LangSmith"},
{"postfix": "to Evaluations in LangSmith"},
],
outputs=[
{"output": "Welcome to LangSmith"},
{"output": "Welcome to Evaluations in LangSmith"},
],
dataset_id=dataset.id,
)
# Define your evaluator
def exact_match(run, example):
return {"score": run.outputs["output"] == example.outputs["output"]}
experiment_results = evaluate(
lambda input: "Welcome " + input['postfix'], # Your AI system goes here
data=dataset_name, # The data to predict and grade over
evaluators=[exact_match], # The evaluators to score the results
experiment_prefix="sample-experiment", # The name of the experiment
metadata={
"version": "1.0.0",
"revision_id": "beta"
},
)
LangSmith의 주요 기능
1. 디버깅
LangSmith는 이벤트 체인의 모든 단계의 입출력에 대한 결과를 보여줍니다. Retrieve가 잘 되었는지 올바른 근거를 사용했음에도 LLM의 답변이 뭐가 문제인지 추론이 가능하며 지연 시간과 토큰 사용을 볼 수 있어 어떤 호출이 문제를 일으키는지도 확인할 수 있습니다.
이를 통해 임베딩한 데이터가 원하는대로 검색이 되는지 확인하고 LLM 모델을 변경하거나 프롬프트를 수정하거나 비용확인을 통해 비용절약이 가능합니다
2. 데이터 수집 및 평가
LLM 어플리케이션에는 데이터셋이 가장 중요한데, LangSmith는 데이터셋을 구성하고 사용하기 좋게 구성되어 있습니다.
개발자가 직접 데이터셋을 올릴 수 있고 연동된 서비스의 유저 로그나 데이터셋, 피드백도 수집이 가능합니다. 또한 자동으로 데이터를 가공하여 추가 수집 기능도 제공합니다.
예를 들어 챗 서비스를 제공하면 유저의 질문에 대한 답변을 제공하고 답변에 따른 유저의 만족도 까지 수집하여 데이터를 재수집 하여 이를 통한 강화학습도 가능하고 A/B 테스트도 할 수 있게 됩니다. 그리고 불만족스러운 데이터는 따로 백테스킹도 할 수 있습니다.
3. 모니터링
대시보드를 사용하여 애플리케이션에 대한 지표를 볼 수 있는 다양한 형식의 차트를 생성할 수 있습니다.
필터를 통해 필요한 데이터만 차트화 하여 보거나, 데이터를 서로 비교하며 비교해볼 수 있습니다.
그리고 규칙을 설정하여 자동화 작업에 웹훅 URL을 추가하면 정의한 규칙에 따라 웹훅 엔드포인트에 POST 요청을 할 수 있습니다.
S3 URL을 사용하여 AWS의 S3에서 데이터를 I/O 할 수도 있습니다.
https://docs.smith.langchain.com/how_to_guides/monitoring/webhooks
LangSmith를 포함한 여러 LLMOps라고 불리는 도구들이 많지만 이는 LLM 애플리케이션 개발에 도움을 주는 도구일 뿐 직접 해결해 주진 않지만 도구의 도움 없이는 많은 시간과 노력이 소요되기 때문에 이러한 도구들을 활용하여 그 시간과 비용을 단축하는 것이 주 목적이라고 볼 수 있습니다.
추가 정보 사이트
LangSmith DOCS : https://docs.smith.langchain.com/
LangSmith API DOCS : https://api.smith.langchain.com/redoc
참고 : https://sudormrf.run/2024/08/17/langsmith_review/
'AI & Bigbata' 카테고리의 다른 글
LangSmith 설치 (0) | 2024.10.14 |
---|---|
LangChain 이란? (1) | 2024.09.11 |