-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to consistently get project (#289)
We plan to introduce an environment variable in hosted langserve that will overwrite the project used for traces from hosted deployments. We don't centralize how we refer to projects in any of our repos, so in order to ensure that our tracing works properly and our project selection is consistent, we need to introduce a shared method for getting the project that we can use throughout our different repos
- Loading branch information
1 parent
661aae9
commit 94c23cd
Showing
5 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import unittest | ||
|
||
import pytest | ||
|
||
import langsmith.utils as ls_utils | ||
|
||
|
||
class LangSmithProjectNameTest(unittest.TestCase): | ||
class GetTracerProjectTestCase: | ||
def __init__( | ||
self, test_name, envvars, expected_project_name, return_default_value=None | ||
): | ||
self.test_name = test_name | ||
self.envvars = envvars | ||
self.expected_project_name = expected_project_name | ||
self.return_default_value = return_default_value | ||
|
||
def test_correct_get_tracer_project(self): | ||
cases = [ | ||
self.GetTracerProjectTestCase( | ||
test_name="default to 'default' when no project provided", | ||
envvars={}, | ||
expected_project_name="default", | ||
), | ||
self.GetTracerProjectTestCase( | ||
test_name="default to 'default' when " | ||
+ "return_default_value=True and no project provided", | ||
envvars={}, | ||
expected_project_name="default", | ||
), | ||
self.GetTracerProjectTestCase( | ||
test_name="do not default if return_default_value=False " | ||
+ "when no project provided", | ||
envvars={}, | ||
expected_project_name=None, | ||
return_default_value=False, | ||
), | ||
self.GetTracerProjectTestCase( | ||
test_name="use session_name for legacy tracers", | ||
envvars={"LANGCHAIN_SESSION": "old_timey_session"}, | ||
expected_project_name="old_timey_session", | ||
), | ||
self.GetTracerProjectTestCase( | ||
test_name="use LANGCHAIN_PROJECT over SESSION_NAME", | ||
envvars={ | ||
"LANGCHAIN_SESSION": "old_timey_session", | ||
"LANGCHAIN_PROJECT": "modern_session", | ||
}, | ||
expected_project_name="modern_session", | ||
), | ||
self.GetTracerProjectTestCase( | ||
test_name="hosted projects get precedence over all other defaults", | ||
envvars={ | ||
"HOSTED_LANGSERVE_PROJECT_NAME": "hosted_project", | ||
"LANGCHAIN_SESSION": "old_timey_session", | ||
"LANGCHAIN_PROJECT": "modern_session", | ||
}, | ||
expected_project_name="hosted_project", | ||
), | ||
] | ||
|
||
for case in cases: | ||
with self.subTest(msg=case.test_name): | ||
with pytest.MonkeyPatch.context() as mp: | ||
for k, v in case.envvars.items(): | ||
mp.setenv(k, v) | ||
|
||
project = ( | ||
ls_utils.get_tracer_project() | ||
if case.return_default_value is None | ||
else ls_utils.get_tracer_project(case.return_default_value) | ||
) | ||
self.assertEqual(project, case.expected_project_name) |