Unit Tests | LangSmith Evaluations - Part 10
Summary
TLDRランス氏が、コード生成の流れに関する10本目のビデオを紹介しています。この流れでは、大規模なドキュメントやユーザーの質問を入力として、コードソリューションを生成します。生成されたコードは、プリアンブル、インポート、コードの3つの要素を含む構造化されたオブジェクトです。ランス氏は、ユニットテストの重要性を強調し、特にインポートとコードが実行可能であることを確認するテストを提案しています。また、CIフローの一部として実行されるユニットテストの実行方法と、LangSmithを使用してテスト結果を記録する方法についても説明しています。LangSmithのデコレーターを使用することで、テスト結果をLangSmithに記録し、データセットに分類して管理することができます。
Takeaways
- 📈 ユニットテストは、CI(継続的インテグレーション)の一部として実行される単純なアサーションであることが多いです。
- 🔍 Lanceは、コード生成のフローに沿って、自然言語の質問を構造化された回答オブジェクトに変換する作業を行っています。
- 🛠️ ユニットテストは、生成されたコードオブジェクトが正しくインポートとコードを含んでいるかどうかを確認するのに役立ちます。
- 📄 ユニットテストはオフラインで実行でき、CIフローの一部として実行されることがあります。
- 🔗 LangSmithは、一般的なフレームワーク(例:pytest)と組み合わせて使用して、テストを計装することができる。
- 📝 main.pyファイルには、コード生成ロジックが定義されており、テストは独立したファイルとしてtestサブディレクトリに配置されます。
- 🧩 テストでは、インポートとコードの実行を試み、エラーが発生した場合はpytest.failを使用してテストを失敗させます。
- 📚 LangSmithのデコレーター@unitを使用すると、ユニットテストをLangSmithに記録できます。
- 📊 LangSmithを使用してユニットテストを記録すると、テスト結果とメタデータが独立したデータセットに記録されます。
- 📈 記録されたテスト結果では、レイテンシーやフィードバックスコア、使用されたトークンなどの詳細を確認できます。
- 🔄 LangSmithを使用してユニットテストを記録することで、CIフローの一部として実行しやすくなります。
Q & A
ランスが紹介するlsmith評価シリーズの10番目のビデオは、何について説明していますか?
-ランスが紹介するlsmith評価シリーズの10番目のビデオは、ユニットテストに焦点を当てています。ユニットテストは、CIの一部としてアプリケーション機能を実行する単純なアサーションになり得ます。
コード生成ノードが受け取る入力とは何ですか?
-コード生成ノードは、大規模なドキュメンテーションセットを入力として受け取ります。たとえば、ラインチェーンのドキュメントやユーザーの質問などが挙げられます。
コード生成ノードが生成する構造化された回答オブジェクトには何が含まれますか?
-コード生成ノードが生成する構造化された回答オブジェクトには、3つの要素が含まれます。これらは、プレアンブル、インポート、およびコードです。
ユニットテストで確認すべき内容とは何ですか?
-ユニットテストでは、インポートとコードが実行可能かどうかを確認することが重要です。これは、生成された構造化コードオブジェクトが正しく、かつ期待通りに機能することを確認するためです。
ランスが使用しているデータモデルは何を含んでいますか?
-ランスが使用しているデータモデルは、プレフィックスインポートとコードを含んでいます。これは、llm(Large Language Model)にバインドされ、構造化出力メソッドを使用して定義されています。
テストを実行する際に使用しているフレームワークは何ですか?
-テストを実行する際に使用しているフレームワークは、pytestです。これは、Pythonで広く使用されるテストフレームワークです。
ランスが示すテストコードの例では、何をテストしていますか?
-ランスが示すテストコードの例では、生成されたコードのインポートとコードブロックの実行可能性をテストしています。
lsmithのデコレーターを使用する利点は何ですか?
-lsmithのデコレーターを使用することで、ユニットテストの結果をlsmithに記録できます。これにより、テスト結果のメタデータが得られ、テストの結果をデータセットとして分離して保管することが可能です。
lsmithのデータセットとテスト結果を確認するにはどうすればよいですか?
-lsmithのデータセットとテスト結果を確認するには、lsmithのウェブインターフェースにアクセスし、データセットとテスト結果を閲覧します。各テスト結果は独立したデータセットとして記録され、詳細な情報を見ることができます。
CIフローにユニットテストを含める理由は何ですか?
-CIフローにユニットテストを含めることで、アプリケーションの各機能が期待通りに動作することを継続的に確認できます。また、コードの変更や追加によって生じる可能性のある問題を早期に検出することができます。
ランスが使用しているメインのPythonファイルは何を定義していますか?
-ランスが使用しているメインのPythonファイル、main.pyは、コード生成ロジックを定義しています。具体的には、テキストを入力として受け取り、インポート、機能的なコードブロック、およびプレアンブルを含む構造化コードオブジェクトを生成するgenerate_code_solution関数を定義しています。
lsmithのユニットテストデコレーターの機能は何ですか?
-lsmithのユニットテストデコレーターは、ユニットテストをlsmithに記録する機能を提供します。これにより、テストが実行されたときの詳細なメタデータとともにテスト結果をlsmithに記録し、後で分析や参照が容易になります。
Outlines
📝 ユニットテストの重要性と実装
Lanceは、Lang Chainの10番目のビデオで、ユニットテストの重要性を説明しています。ユニットテストは、CI(継続的インテグレーション)の一部として実行される単純なアサーションであり、アプリケーションの機能性に対して行われます。彼は、コード生成のフローを通じて、自然言語の質問を構造化された回答オブジェクトに変換するプロセスを紹介しました。そのオブジェクトには、preamble、imports、コードの3つの要素が含まれています。ユニットテストは、これらの要素が期待どおりに実行されることを確認するために行われます。また、Lang Smithを用いてユニットテストを記録し、CIフローの一部として実行することができると述べています。
🔍 Lang Smithによるユニットテストの記録
Lanceは、Lang Smithのデコレータを使用して、ユニットテストを記録する方法を紹介しました。テストは標準的なユニットテストであり、pytestを使用して実行されますが、Lang Smithのデコレータを追加することで、テスト結果をLang Smithに記録できます。これにより、テスト結果が独立したデータセットに記録され、メタデータとともに確認・分析が可能になります。また、Lang Smithのデータセットとテスト機能を使用することで、テストの結果を詳細に把握し、CIフローで簡単に使用できる利便性が得られます。
Mindmap
Keywords
💡ユニットテスト
💡CI(継続的インテグレーション)
💡コード生成
💡pandocオブジェクト
💡ランダムテスト
💡pytest
💡LangSmith
💡データセット
💡構造化出力
💡ランダム性
💡メタデータ
Highlights
Unit tests are often simple assertions that can run as part of CI for app functionality.
The motivating example involves code generation that takes in documentation and user questions to produce code solutions.
The code generation process converts a natural language question into a structured answer object with a preamble, imports, and code.
The goal is to instrument unit tests to check if the imports and code are executable and work as expected.
The unit test setup includes a standalone dataset, a heuristic, and a reference for expected code executability.
Unit tests can be run offline as part of a CI flow or online.
LangSmith works with conventional frameworks like pytest for instrumenting tests.
A simple main.py file is set up to instrument the code generation logic.
Independent test files are created in a test subdirectory to implement checks for imports and code execution.
The unit tests use a decorator from LangSmith to log the test results to LangSmith.
Running the unit tests with pytest executes the tests and logs the results to LangSmith datasets.
Each test is logged to an independent dataset, allowing for compartmentalization.
The logged test results in LangSmith include metadata such as latency, feedback score, and tokens used.
The input passed to the unit test is also logged in LangSmith.
Using LangSmith to log unit tests provides a convenient way to monitor test results as part of CI.
The process demonstrates how to integrate LangSmith with standard unit testing frameworks like pytest.
Logging unit test results to LangSmith provides valuable insights into test performance and code quality.
The approach allows developers to easily track unit test results over time and identify trends or issues.
Overall, the integration of LangSmith with unit testing enables more effective test result monitoring and analysis.
Transcripts
hi this is Lance from Lang chain this is
the 10th video on our lsmith evaluation
series focused on unit tests so unit
tests are often simple assertions uh for
example they can run as part of CI uh
for app functionality now let me give a
motivating example here so I've done
some recent work on code generation and
it follows a flow kind of like you see
here so I have this code generation node
uh that takes in some large set of
documentation like for example a bunch
of line chain Docs takes in user
questions and produces code Solutions
based on the user question and the
documentation now in this flow I
typically do something uh to the output
where I convert it into this pantic
object that contains three things a
preamble Imports and code and I do
Downstream stuff with that which you
don't have to worry about here the key
point is I basically convert a natural
language question into a structured
answer object that has these three
things so how can instrument unit tests
for example that check whether like
Imports and the code are are executable
that's like a very sane unit test you
might want to do uh just to convince
yourself that you're able to produce
like a structured code object correctly
and that the Imports and code actually
work as expected right so that's like a
pretty sane unit test that we we may
want and again if we look at our overall
framing where does this sit so in this
case um we don't necessarily have like a
standalone data set of examples we have
um you know a heuristic like a
hard-coded decision or a hard-coded
assertion um and we have some reference
um that we expect um for example in this
particular case I expect that the code
is executable correctly um that's really
it and of course unit tests they they
can be run offline um you know as part
of a CI flow or they can be run online
and we're going to talk about the
offline case and how you can instrument
this with lsmith so what we're going to
do is we're going to show the Langs
Smith works with conventional Frameworks
like Pi test for instrumenting tests and
we're going to set up a few things we're
just going to set up a very simple
main.py file and I'll go over there and
show you that right now which is
basically going to instrument uh my kind
of generation logic and then we're going
to set up um a few different test as
independent files in this test
subdirectory uh that'll implement the
various checks we want to do in this
case to check that Imports and code are
executed correctly so I'm going to hop
over here to my VSS code so you can see
it now and you can see here I'll move
this over um that I'm in this
introduction folder so this is in Langs
withth cookbooks and I've set up an app
so here's my app and main.py you can see
right here now this is where the logic
of my chain is going to be defined so in
this particular case this generate code
solution just takes in text and what's
going to do is here's my generation
prompt which basically says you're an
expert in L expression language um
here's a document related to lch
expression language here and um produce
an output that contains Imports a
functioning code block and a preamble
um which I will uh State somewhere in
here um yeah description of the code
solution the Imports and then a
functioning code block so those are the
three pieces now here I'm actually going
to Define data model so this is a pantic
object that contains prefix Imports and
code and I'm going to bind that to my
llm using with with structured output um
method which is very convenient and this
code gen chain should output a solution
object that has a prefix import and code
so that's kind of step
one now this is just a module so this is
what I'm calling my app and that's all
it has now if I look at my tests here
I've defined two tests so one is test
code so this is going to take in or it's
going to it has one um kind of piece of
L transpression language documentation
here um so this is like an example input
to our
function and this text execution simply
will take that input right here it'll
invoke our gen code solution which we
defined over here so that's this guy
right here there we go it will um
yep it will invoke that it will produce
a solution and now we're going to test
we're going to try to execute the
Imports there and uh basically if that
fails we're going to we're going to flag
the py test. fail and we're going to
return the error so that's the setup
here likewise with code execution same
flow um in this case though we're just
going to grab both the Imports and the
code itself we'll try to execute all of
it and again we'll return an error so
these are our two tests
now this looks like standard unit
testing there's nothing that's you know
Lang Smith specific here but I want to
call your attention to one thing this
decorator unit which we import from
Langs smith. unit allows you then to log
this unit test to Langs Smith um so we
have that in both cases so there's just
a simple decorator on top of this
function that's going to perform our
unit test with from lsmith we import
unit so we do that in both cases and all
we have to do then is just say run P
test so we're in our Dory we're in this
introduction directory right here so I
can just show you so we have my app and
my test here that's it so we can kick
off uh we can run P test and this will
kick off the unit test so this is just
standard stuff there's nothing that's
pretty that that's kind of very specific
to lsmith here other than I've added
this little decorator unit to my uh unit
tests here that's all's going on so it's
running both of them you can see this is
kind of churning along so that's cool
um and here's my other one so I have
test Imports test code these are my two
unit tests it looks like two PA so this
is great this is just using p test and
running unit test but there's one nice
trick because I've run these with that
Langs Smith decorator if I go over to my
Langs Smith so if I go to data sets and
testing so I can see now I have data
sets for the directory name and then my
unit test name test Imports test code if
I go in here I can actually see that the
results of the unit test are logged and
what's pretty nice is that um you get
all this metadata here which is pretty
good
um and yep I can see the names of the
various runs I can see the result um so
this is again pretty convenient
basically it's allowing me to log the
results of the unit test to Langs Smith
and each test then is logged to an
independent data set so I can keep them
compartmentalized which again is also
quite nice um let's actually click on
one and kind of see
uh actually let's go ahead and use
comparison mode to look at a few of them
so here we go this is pretty nice so I
can look at things like latency I can
look at the feedback score I can look at
the tokens used again in each case I get
logged input so this is the input that I
passed to the unit test
um
and there we go so this is each one of
them each each of the unit tests all
pass uh and I can see latency and
everything so anyway this is a pretty
nice and easy way to use Langs Smith to
log unit tests um and this is a very
convenient thing to to run as part of
your CI thanks
تصفح المزيد من مقاطع الفيديو ذات الصلة
5.0 / 5 (0 votes)