-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python[minor]: manually set test case inputs/outputs #1362
Open
baskaryan
wants to merge
12
commits into
main
Choose a base branch
from
bagatur/rfc_set_test_vals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I like the functionality. I kinda like using a single module/object to access the methods, like
or something |
Updated from langsmith import testing
@testing.test
def test_example():
x = 0
y = 1
testing.log_inputs({"x": x, "y": y})
testing.log_reference_outputs({"product": 0})
testing.log_outputs({"product": x * y})
testing.log_feedback(key="correct", value=1.0)
assert x * y == 0 |
baskaryan
changed the title
rfc: manually set test case inputs/outputs
python[minor]: manually set test case inputs/outputs
Jan 3, 2025
I like |
updated usage LANGSMITH_TEST_SUITE="foo" pytest -n auto tests/test_foo.py # test_foo.py
import openai
import pytest
from langsmith import testing, wrappers
oai_client = wrappers.wrap_openai(openai.Client())
@testing.test
def test_openai_says_hello():
# Traced code will be included in the test case
text = "Say hello!"
response = oai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": text},
],
)
testing.log_inputs({"text": text})
testing.log_outputs({"response": response.choices[0].message.content})
testing.log_reference_outputs({"response": "hello!"})
with testing.trace_feedback():
grade = oai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "Return 1 if 'hello' is in the user message and 0 otherwise.",
},
{"role": "user", "content": response.choices[0].message.content},
],
)
testing.log_feedback(
key="llm_judge", score=float(grade.choices[0].message.content)
)
assert "hello" in response.choices[0].message.content.lower()
@testing.test(output_keys=["expected"])
@pytest.mark.parametrize(
"a, b, expected",
[
(1, 2, 3),
(3, 4, 7),
],
)
def test_addition_with_multiple_inputs(a: int, b: int, expected: int):
testing.log_outputs({"sum": a + b})
assert a + b == expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
example usage