-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add langkit metadata to schema for inclusion in whylogs profiles (#186)
- Loading branch information
Showing
19 changed files
with
91 additions
and
60 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
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
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
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,41 @@ | ||
from langkit import __version__ | ||
from logging import getLogger | ||
|
||
from typing import Any, Dict, Optional | ||
|
||
|
||
_LANGKIT_VERSION_METADATA_KEY = "langkit.version" | ||
_LANGKIT_METRIC_COLLECTION_KEY = "langkit.metric_collection" | ||
diagnostic_logger = getLogger(__name__) | ||
|
||
|
||
def _check_for_metadata(schema: Any) -> Optional[Dict[str, str]]: | ||
if schema is not None and hasattr(schema, "metadata"): | ||
metadata = getattr(schema, "metadata") | ||
if metadata is not None and isinstance(metadata, dict): | ||
return metadata | ||
return None | ||
|
||
|
||
def _add_langkit_version_metadata( | ||
metadata: Dict[str, str], metric_collection_name: Optional[str] | ||
) -> Dict[str, str]: | ||
if metadata is None: | ||
diagnostic_logger.warning("metadata is None, LangKit won't update metadata") | ||
else: | ||
metadata[_LANGKIT_VERSION_METADATA_KEY] = __version__ | ||
if metric_collection_name: | ||
metadata[_LANGKIT_METRIC_COLLECTION_KEY] = metric_collection_name | ||
return metadata | ||
|
||
|
||
def attach_schema_metadata(schema: Any, metric_collection_name: Optional[str]) -> Any: | ||
metadata = _check_for_metadata(schema) | ||
if metadata is None: | ||
diagnostic_logger.warning( | ||
"schema does not contain metadata, LangKit won't update metadata" | ||
) | ||
return schema | ||
_add_langkit_version_metadata(metadata, metric_collection_name) | ||
|
||
return schema |
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
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
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,17 @@ | ||
def test_metadata_langkit_version(): | ||
import whylogs as why | ||
from langkit import __version__ | ||
from langkit.metadata import ( | ||
_LANGKIT_VERSION_METADATA_KEY, | ||
_LANGKIT_METRIC_COLLECTION_KEY, | ||
) | ||
from langkit import light_metrics # noqa | ||
|
||
expected_metric_collection_name = "light_metrics" | ||
text_schema = light_metrics.init() | ||
results = why.log({"prompt": "hello", "response": "goodbye"}, schema=text_schema) | ||
version = results.metadata[_LANGKIT_VERSION_METADATA_KEY] | ||
metric_collection_name = results.metadata[_LANGKIT_METRIC_COLLECTION_KEY] | ||
assert results.metadata | ||
assert version == __version__ | ||
assert metric_collection_name == expected_metric_collection_name |
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import os | ||
from . import lang_config | ||
from langkit import lang_config | ||
|
||
|
||
def _get_data_home() -> str: | ||
|
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