Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into piotrm/otel_db
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmardziel committed Nov 15, 2024
2 parents c8a296a + 5f5ee16 commit 1100ea6
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 59 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ htmlcov/
# testing: parts of old trulens_eval package for backwards compatibility testing
_trulens_eval/
data/

# Build objects
**/poetry.lock
!poetry.lock
45 changes: 5 additions & 40 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ repos:
hooks:
- id: trailing-whitespace
- id: check-added-large-files
exclude: src/dashboard/trulens/dashboard/.*/dist/.*
exclude: |
(?x)^(
src/dashboard/trulens/dashboard/.*/dist/.*|
poetry.lock
)$
- id: check-yaml
exclude: meta.yaml
- id: destroyed-symlinks
Expand Down Expand Up @@ -44,42 +48,3 @@ repos:
hooks:
- id: poetry-check
name: trulens-poetry-check
- id: poetry-check
name: trulens-core-poetry-check
args: [-C src/core]
- id: poetry-check
name: trulens-benchmark-poetry-check
args: [-C src/benchmark]
- id: poetry-check
name: trulens-feedback-poetry-check
args: [-C src/feedback]
- id: poetry-check
name: trulens-apps-langchain-poetry-check
args: [-C src/apps/langchain]
- id: poetry-check
name: trulens-apps-llamaindex-poetry-check
args: [-C src/apps/llamaindex]
- id: poetry-check
name: trulens-apps-nemo-poetry-check
args: [-C src/apps/nemo]
- id: poetry-check
name: trulens-providers-bedrock-poetry-check
args: [-C src/providers/bedrock]
- id: poetry-check
name: trulens-providers-cortex-poetry-check
args: [-C src/providers/cortex]
- id: poetry-check
name: trulens-providers-huggingface-poetry-check
args: [-C src/providers/huggingface]
- id: poetry-check
name: trulens-providers-langchain-poetry-check
args: [-C src/providers/langchain]
- id: poetry-check
name: trulens-providers-litellm-poetry-check
args: [-C src/providers/litellm]
- id: poetry-check
name: trulens-providers-openai-poetry-check
args: [-C src/providers/openai]
- id: poetry-check
name: trulens-connectors-snowflake-poetry-check
args: [-C src/connectors/snowflake]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ env-tests:
jsondiff

env-tests-required:
poetry install --only required
make env-tests
poetry install --only required \
&& make env-tests

env-tests-optional: env env-tests
poetry run pip install \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Cortex Finetuning Experiments\n",
"\n",
"This notebook takes you through evaluating a series of "
"This notebook takes you through evaluating a series of fine-tuning experiments with Snowflake Cortex, and uses TruLens to evaluate the fine-tuning effectiveness."
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ classifiers = [
"License :: OSI Approved :: MIT License",
]

[[tool.poetry.source]]
name = "pypi-public"
url = "https://pypi.org/simple/"

[tool.poetry.dependencies]
python = "^3.8.1,!=3.9.7"
trulens-core = { version = "^1.0.0", extras = [
Expand Down Expand Up @@ -91,10 +95,6 @@ trulens-semconv = { path = "src/semconv", develop = true }
# Remove after deprecation period.
trulens_eval = { path = "src/trulens_eval", develop = true }

[[tool.poetry.source]]
name = "pypi-public"
url = "https://pypi.org/simple/"

[tool.ruff]
line-length = 80
extend-exclude = [
Expand Down
15 changes: 15 additions & 0 deletions src/connectors/snowflake/trulens/connectors/snowflake/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ def _validate_snowpark_session_with_connection_parameters(
self.password_known = True
return snowpark_session_connection_parameters

@staticmethod
def _validate_snowpark_session_paramstyle(
snowpark_session: Session,
) -> None:
if snowpark_session.connection._paramstyle == "pyformat":
# If this is the case, sql executions with bindings will fail later
# on so we fail fast here.
raise ValueError(
"The Snowpark session must have paramstyle 'qmark'! To ensure"
" this, during `snowflake.connector.connect` pass in"
" `paramstyle='qmark'` or set"
" `snowflake.connector.paramstyle = 'qmark'` beforehand."
)

def _init_with_snowpark_session(
self,
snowpark_session: Session,
Expand All @@ -166,6 +180,7 @@ def _init_with_snowpark_session(
database_check_revision: bool,
connection_parameters: Dict[str, str],
):
self._validate_snowpark_session_paramstyle(snowpark_session)
database_args = self._set_up_database_args(
database_args,
snowpark_session,
Expand Down
18 changes: 10 additions & 8 deletions src/core/trulens/experimental/otel_tracing/core/trace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
Modules in this folder depend on each other than makes it impossible to import
them linearly. Because of this, they need to be imported here and the delayed
typing information needs to be filled in afterwards with model_rebuild`.
Modules in this folder depend on each other which makes it impossible to import
them without circular import errors. Because of this, some imports need to be
put into `if TYPE_CHECKING` blocks and classes that depend on those imports need
to be "rebuilt" with `model_rebuild`. This only applies to `pydantic.BaseModel`
classes.
"""

from . import context as core_context
Expand All @@ -10,12 +12,12 @@
from . import span as core_span
from . import trace as core_trace

core_trace.Tracer.model_rebuild()
core_span.Span.model_rebuild()
core_otel.Span.model_rebuild()
core_context.SpanContext.model_rebuild()
core_context.TraceState.model_rebuild()
core_sem.TypedSpan.model_rebuild()
core_trace.TracerProvider.model_rebuild()
core_otel.Span.model_rebuild()
core_otel.Tracer.model_rebuild()
core_otel.TracerProvider.model_rebuild()
core_span.Span.model_rebuild()
core_sem.TypedSpan.model_rebuild()
core_trace.Tracer.model_rebuild()
core_trace.TracerProvider.model_rebuild()
34 changes: 34 additions & 0 deletions tests/e2e/test_snowflake_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from unittest import main
import uuid

import snowflake.connector
from snowflake.snowpark import Session
from trulens.connectors.snowflake import SnowflakeConnector
from trulens.dashboard import run_dashboard
from trulens.dashboard import stop_dashboard

Expand Down Expand Up @@ -68,6 +71,37 @@ def test_run_leaderboard_without_password(self):
except Exception:
pass

@optional_test
def test_paramstyle_pyformat(self):
default_paramstyle = snowflake.connector.paramstyle
try:
# pyformat paramstyle should fail fast.
snowflake.connector.paramstyle = "pyformat"
schema_name = self.create_and_use_schema(
"test_paramstyle_pyformat", append_uuid=True
)
snowflake_connection = snowflake.connector.connect(
**self._snowflake_connection_parameters, schema=schema_name
)
snowpark_session = Session.builder.configs({
"connection": snowflake_connection
}).create()
with self.assertRaisesRegex(
ValueError, "The Snowpark session must have paramstyle 'qmark'!"
):
SnowflakeConnector(snowpark_session=snowpark_session)
# qmark paramstyle should be fine.
snowflake.connector.paramstyle = "qmark"
snowflake_connection = snowflake.connector.connect(
**self._snowflake_connection_parameters, schema=schema_name
)
snowpark_session = Session.builder.configs({
"connection": snowflake_connection
}).create()
SnowflakeConnector(snowpark_session=snowpark_session)
finally:
snowflake.connector.paramstyle = default_paramstyle


if __name__ == "__main__":
main()
4 changes: 1 addition & 3 deletions tests/e2e/test_snowflake_notebooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import tempfile
from typing import Sequence
from unittest import main
import uuid

from trulens.connectors.snowflake.utils.server_side_evaluation_artifacts import (
_TRULENS_PACKAGES,
Expand All @@ -18,8 +17,7 @@

class TestSnowflakeNotebooks(SnowflakeTestCase):
def test_simple(self) -> None:
schema_name = f"test_simple_{str(uuid.uuid4()).replace('-', '_')}"
self.create_and_use_schema(schema_name)
self.create_and_use_schema("test_simple", append_uuid=True)
self._upload_and_run_notebook("simple", _TRULENS_PACKAGES)

def test_staged_packages(self) -> None:
Expand Down
11 changes: 10 additions & 1 deletion tests/util/snowflake_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,19 @@ def run_query(
) -> List[Row]:
return self._snowpark_session.sql(q, bindings).collect()

def create_and_use_schema(self, schema_name: str) -> None:
def create_and_use_schema(
self, schema_name: str, append_uuid: bool = False
) -> str:
schema_name = schema_name.upper()
if append_uuid:
schema_name = (
f"{schema_name}__{str(uuid.uuid4()).replace('-', '_')}"
)
self._schema = schema_name
self.run_query("CREATE SCHEMA IDENTIFIER(?)", [schema_name])
self._snowflake_schemas_to_delete.add(schema_name)
self._snowpark_session.use_schema(schema_name)
return schema_name


if __name__ == "__main__":
Expand Down

0 comments on commit 1100ea6

Please sign in to comment.