
ทดสอบประเมินและตรวจสอบแอปพลิเคชัน AI ของคุณ
- Twitter/X • ? Discord • Parea ai • ? เอกสาร
Parea AI จัดเตรียม SDK เพื่อประเมินและตรวจสอบแอปพลิเคชัน AI ของคุณ ด้านล่างคุณสามารถดู Quickstarts ถึง:
เอกสารเต็มของเราอยู่ที่นี่
pip install -U parea-ai หรือติดตั้งด้วย Poetry
poetry add parea-aiการทดสอบแอพ AI ของคุณหมายถึงการดำเนินการผ่านชุดข้อมูลและให้คะแนนด้วยฟังก์ชั่นการประเมินผล สิ่งนี้ทำใน 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 ) ผ่านชุดข้อมูล (นี่คือรายการพจนานุกรม) ในที่สุด run เรียกใช้การเรียกใช้จะดำเนินการทดสอบและสร้างรายงานเอาต์พุตคะแนนและร่องรอยสำหรับตัวอย่างของชุดข้อมูล คุณสามารถค้นหาลิงค์ไปยังการทดลองที่ดำเนินการได้ที่นี่ (TODO: การทดลองเติมเต็ม)
อ่านเพิ่มเติมเกี่ยวกับวิธีการเขียนเรียกใช้และวิเคราะห์การทดลองในเอกสารของเรา
โดยการห่อไคลเอนต์ที่เกี่ยวข้องคุณสามารถบันทึกการโทร LLM ทั้งหมดของคุณทั้งหมดไปยัง OpenAI และมานุษยวิทยา นอกจากนี้การใช้ร่องรอย trace คุณสามารถสร้างร่องรอยแบบลำดับชั้นของแอปพลิเคชัน LLM ของคุณไปยัง EG Associate LLM Call ด้วยขั้นตอนการดึงข้อมูลของท่อส่งเศษผ้า คุณสามารถดูเอกสารการสังเกตได้อย่างเต็มรูปแบบที่นี่และการรวมเข้ากับ Langchain, ผู้สอน, DSPY, Litellm และอื่น ๆ ที่นี่
ในการบันทึกการโทร OpenAI ใด ๆ โดยอัตโนมัติคุณสามารถห่อไคลเอนต์ OpenAI ด้วยไคลเอนต์ Parea โดยใช้วิธี wrap_openai_client
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 ) ในการบันทึกการโทรมานุษยวิทยาโดยอัตโนมัติคุณสามารถห่อไคลเอนต์มานุษยวิทยาด้วยไคลเอนต์ Parea โดยใช้วิธี wrap_anthropic_client
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} }
}