
AI 응용 프로그램을 테스트, 평가 및 모니터링합니다
? 트위터/x • ? 불화 • parea ai • ? 선적 서류 비치
Parea AI는 AI 응용 프로그램을 평가하고 모니터링하기위한 SDK를 제공합니다. 아래는 다음과 같은 QuickStarts를 참조하십시오.
우리의 전체 문서가 여기 있습니다.
pip install -U parea-ai 또는 Poetry 설치하십시오
poetry add parea-aiAI 앱을 테스트하는 것은 데이터 세트를 통해이를 실행하고 평가 기능으로 점수를 매기는 것을 의미합니다. 이것은 실험을 정의하고 실행하여 Parea에서 수행됩니다. 아래는 Levenshtein 거리 메트릭으로 인사 봇을 테스트하는 방법의 예를 볼 수 있습니다.
from parea import Parea , trace
from parea . evals . general import levenshtein
p = Parea ( api_key = "<<PAREA_API_KEY>>" ) # replace with Parea AI API key
# use the trace decorator to score the output with the Levenshtein distance
@ trace ( eval_funcs = [ levenshtein ])
def greeting ( name : str ) -> str :
return f"Hello { name } "
data = [
{ "name" : "Foo" , "target" : "Hi Foo" },
{ "name" : "Bar" , "target" : "Hello Bar" },
]
p . experiment (
name = "Greeting" ,
data = data ,
func = greeting ,
). run () 위의 스 니펫에서 trace 데코레이터를 사용하여 기능의 입력 및 출력을 캡처했습니다. 이 데코레이터를 사용하면 백그라운드에서 levenshtein Eval을 실행하여 출력을 점수 할 수 있습니다. 그런 다음 p.experiment 통해 실험을 정의하여 데이터 세트 (여기서 사전 목록)를 통해 기능 ( greeting )을 평가했습니다. 마지막으로, Call run 실험을 실행하고 데이터 세트의 샘플에 대한 출력, 점수 및 흔적에 대한 보고서를 만듭니다. 실행 된 실험에 대한 링크를 여기에서 찾을 수 있습니다. (TODO : 채우기 실험)
문서의 실험을 작성, 실행 및 분석하는 방법에 대해 자세히 알아보십시오.
해당 클라이언트를 마무리하면 모든 LLM 호출을 OpenAI 및 Anthropic에 자동으로 로그인 할 수 있습니다. 또한 trace Decorator를 사용하여 LLM 응용 프로그램의 계층 적 흔적을 생성하여 EG LLM 호출을 RAG 파이프 라인의 검색 단계와 연관시킬 수 있습니다. 여기에서 전체 관찰 가능성 문서와 Langchain, 강사, DSPY, Litellm 등으로의 통합을 볼 수 있습니다.
OpenAI 통화를 자동으로 로그인하려면 wrap_openai_client 메소드를 사용하여 OpenAI 클라이언트를 PAREA 클라이언트로 랩핑 할 수 있습니다.
from openai import OpenAI
from parea import Parea
client = OpenAI ( api_key = "OPENAI_API_KEY" )
# All you need to do is add these two lines
p = Parea ( api_key = "PAREA_API_KEY" ) # replace with your API key
p . wrap_openai_client ( client )
response = client . chat . completions . create (
model = "gpt-4o" ,
messages = [
{
"role" : "user" ,
"content" : "Write a Hello World program in Python using FastAPI." ,
}
],
)
print ( response . choices [ 0 ]. message . content ) 모든 의인성 통화를 자동으로 기록하려면 wrap_anthropic_client 메소드를 사용하여 Parea 클라이언트로 인류 클라이언트를 랩핑 할 수 있습니다.
import anthropic
from parea import Parea
p = Parea ( api_key = "PAREA_API_KEY" ) # replace with your API key
client = anthropic . Anthropic ()
p . wrap_anthropic_client ( client )
message = client . messages . create (
model = "claude-3-opus-20240229" ,
max_tokens = 1024 ,
messages = [
{
"role" : "user" ,
"content" : "Write a Hello World program in Python using FastAPI." ,
}
],
)
print ( message . content [ 0 ]. text ) trace 데코레이터를 사용하면 LLM 응용 프로그램의 계층 적 흔적을 만들 수 있습니다.
from openai import OpenAI
from parea import Parea , trace
client = OpenAI ( api_key = "OPENAI_API_KEY" ) # replace with your API key
p = Parea ( api_key = "PAREA_API_KEY" ) # replace with your API key
p . wrap_openai_client ( client )
# We generally recommend creating a helper function to make LLM API calls.
def llm ( messages : list [ dict [ str , str ]]) -> str :
response = client . chat . completions . create ( model = "gpt-4o" , messages = messages )
return response . choices [ 0 ]. message . content
# This will give the Span the name of the function.
# Without the decorator the default name for all LLM call logs is `llm-openai`
@ trace
def hello_world ( lang : str , framework : str ):
return llm ([{ "role" : "user" , "content" : f"Write a Hello World program in { lang } using { framework } ." }])
@ trace
def critique_code ( code : str ):
return llm ([{ "role" : "user" , "content" : f"How can we improve this code: n { code } " }])
# Our top level function is called chain. By adding the trace decorator here,
# all sub-functions will automatically be logged and associated with this trace.
# Notice, you can also add metadata to the trace, we'll revisit this functionality later.
@ trace ( metadata = { "purpose" : "example" }, end_user_identifier = "John Doe" )
def chain ( lang : str , framework : str ) -> str :
return critique_code ( hello_world ( lang , framework ))
print ( chain ( "Python" , "FastAPI" ))배포 된 프롬프트는 제품 관리자 및 과목 전문가와 같은 비 엔지니어와의 협력을 가능하게합니다. 사용자는 Parea의 놀이터에서 프롬프트를 반복, 정제 및 테스트 할 수 있습니다. 땜질 후 해당 프롬프트를 배포 할 수 있습니다. 즉, API 엔드 포인트를 통해 노출되어 응용 프로그램에 통합됩니다. 여기에서 전체 문서를 확인하십시오.
from parea import Parea
from parea . schemas . models import Completion , UseDeployedPrompt , CompletionResponse , UseDeployedPromptResponse
p = Parea ( api_key = "<PAREA_API_KEY>" )
# You will find this deployment_id in the Parea dashboard
deployment_id = '<DEPLOYMENT_ID>'
# Assuming your deployed prompt's message is:
# {"role": "user", "content": "Write a hello world program using {{x}} and the {{y}} framework."}
inputs = { "x" : "Golang" , "y" : "Fiber" }
# You can easily unpack a dictionary into an attrs class
test_completion = Completion (
** {
"deployment_id" : deployment_id ,
"llm_inputs" : inputs ,
"metadata" : { "purpose" : "testing" }
}
)
# By passing in my inputs, in addition to the raw message with unfilled variables {{x}} and {{y}},
# you we will also get the filled-in prompt:
# {"role": "user", "content": "Write a hello world program using Golang and the Fiber framework."}
test_get_prompt = UseDeployedPrompt ( deployment_id = deployment_id , llm_inputs = inputs )
def main ():
completion_response : CompletionResponse = p . completion ( data = test_completion )
print ( completion_response )
deployed_prompt : UseDeployedPromptResponse = p . get_prompt ( data = test_get_prompt )
print ( " n n " )
print ( deployed_prompt ) 이 프로젝트는 Apache Software License 2.0 라이센스의 조건에 따라 라이센스가 부여됩니다. 자세한 내용은 라이센스를 참조하십시오.
@misc { parea-sdk ,
author = { joel-parea-ai,joschkabraun } ,
title = { Parea python sdk } ,
year = { 2023 } ,
publisher = { GitHub } ,
journal = { GitHub repository } ,
howpublished = { url{https://github.com/parea-ai/parea-sdk} }
}