
اختبار وتقييم ومراقبة تطبيق الذكاء الاصطناعى الخاص بك
؟ Twitter/X • ؟ Discord • Parea AI • ؟ الوثائق
يوفر Parea AI SDK لتقييم ومراقبة تطبيقات AI الخاصة بك. أدناه يمكنك رؤية Quickstarts إلى:
مستنداتنا الكاملة هنا.
pip install -U parea-ai أو التثبيت مع Poetry
poetry add parea-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 لالتقاط أي مدخلات ومخرجات للوظيفة. يمكّن هذا الديكور أيضًا من تسجيل الإخراج من خلال تنفيذ Eval levenshtein في الخلفية. بعد ذلك ، حددنا تجربة عبر p.experiment لتقييم وظيفتنا ( greeting ) على مجموعة بيانات (هنا قائمة بالقواميس). أخيرًا ، سيقوم Calling run بتنفيذ التجربة ، وإنشاء تقرير عن المخرجات والنتائج والآثار لأي عينة من مجموعة البيانات. يمكنك العثور على رابط للتجربة المنفذة هنا. (تودو: تجربة التعبئة)
اقرأ المزيد حول كيفية الكتابة وتشغيل وتحليل التجارب في مستنداتنا.
من خلال لف العملاء المعنيين ، يمكنك تسجيل جميع مكالمات LLM تلقائيًا إلى Openai & Anthropic. بالإضافة إلى ذلك ، باستخدام Decorator trace ، يمكنك إنشاء آثار هرمية لتطبيق LLM الخاص بك على مكالمات LLM Associate مع خطوة استرجاع خط أنابيب الخرقة. يمكنك رؤية وثائق قابلية الملاحظة الكاملة هنا وتكاملنا في 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} }
}