
AIアプリケーションをテスト、評価、監視します
? Twitter/x • ?不一致•パレアアイ• ?ドキュメント
Parea AIは、AIアプリケーションを評価および監視するためのSDKを提供します。以下に、QuickStartsをご覧ください。
私たちの完全なドキュメントはこちらです。
pip install -U parea-aiまたはPoetryでインストールします
poetry add parea-aiAIアプリをテストするということは、データセットを介してそれを実行し、評価関数でスコアを付けることを意味します。これは、実験を定義して実行することにより、Pareaで行われます。以下に、レーベンシュテイン距離メトリックでグリーティングボットをテストする方法の例を参照してください。
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コールを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} }
}