trustwise 0.1.0a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. trustwise-0.1.0a1/.githooks/pre-push +48 -0
  2. trustwise-0.1.0a1/.github/workflows/build-and-test.yml +56 -0
  3. trustwise-0.1.0a1/.github/workflows/ci.yml +102 -0
  4. trustwise-0.1.0a1/.github/workflows/static.yml +43 -0
  5. trustwise-0.1.0a1/.gitignore +174 -0
  6. trustwise-0.1.0a1/PKG-INFO +268 -0
  7. trustwise-0.1.0a1/README.md +231 -0
  8. trustwise-0.1.0a1/docs/source/alignment_metrics.rst +192 -0
  9. trustwise-0.1.0a1/docs/source/api.rst +447 -0
  10. trustwise-0.1.0a1/docs/source/changelog.rst +55 -0
  11. trustwise-0.1.0a1/docs/source/conf.py +78 -0
  12. trustwise-0.1.0a1/docs/source/guardrails.rst +63 -0
  13. trustwise-0.1.0a1/docs/source/index.rst +67 -0
  14. trustwise-0.1.0a1/docs/source/installation.rst +16 -0
  15. trustwise-0.1.0a1/docs/source/performance_metrics.rst +307 -0
  16. trustwise-0.1.0a1/docs/source/safety_metrics.rst +170 -0
  17. trustwise-0.1.0a1/docs/source/usage.rst +163 -0
  18. trustwise-0.1.0a1/docs/source/versioning.rst +89 -0
  19. trustwise-0.1.0a1/examples/getting_started.py +546 -0
  20. trustwise-0.1.0a1/examples/quickstart.ipynb +392 -0
  21. trustwise-0.1.0a1/langchain_test.py +256 -0
  22. trustwise-0.1.0a1/pyproject.toml +126 -0
  23. trustwise-0.1.0a1/quickstart.ipynb +1 -0
  24. trustwise-0.1.0a1/scripts/install-hooks.sh +45 -0
  25. trustwise-0.1.0a1/src/trustwise/__init__.py +9 -0
  26. trustwise-0.1.0a1/src/trustwise/sdk/__init__.py +3 -0
  27. trustwise-0.1.0a1/src/trustwise/sdk/client.py +79 -0
  28. trustwise-0.1.0a1/src/trustwise/sdk/config.py +89 -0
  29. trustwise-0.1.0a1/src/trustwise/sdk/features.py +29 -0
  30. trustwise-0.1.0a1/src/trustwise/sdk/guardrails/__init__.py +3 -0
  31. trustwise-0.1.0a1/src/trustwise/sdk/guardrails/guardrail.py +195 -0
  32. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/__init__.py +46 -0
  33. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/__init__.py +24 -0
  34. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/__init__.py +0 -0
  35. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/clarity.py +48 -0
  36. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/formality.py +46 -0
  37. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/helpfulness.py +48 -0
  38. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/sensitivity.py +50 -0
  39. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/simplicity.py +46 -0
  40. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/tone.py +46 -0
  41. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1/metrics/toxicity.py +48 -0
  42. trustwise-0.1.0a1/src/trustwise/sdk/metrics/alignment/v1.py +141 -0
  43. trustwise-0.1.0a1/src/trustwise/sdk/metrics/base.py +321 -0
  44. trustwise-0.1.0a1/src/trustwise/sdk/metrics/performance/__init__.py +43 -0
  45. trustwise-0.1.0a1/src/trustwise/sdk/metrics/performance/v1/__init__.py +14 -0
  46. trustwise-0.1.0a1/src/trustwise/sdk/metrics/performance/v1/metrics/__init__.py +0 -0
  47. trustwise-0.1.0a1/src/trustwise/sdk/metrics/performance/v1/metrics/carbon.py +58 -0
  48. trustwise-0.1.0a1/src/trustwise/sdk/metrics/performance/v1/metrics/cost.py +93 -0
  49. trustwise-0.1.0a1/src/trustwise/sdk/metrics/performance/v1.py +136 -0
  50. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/__init__.py +45 -0
  51. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/__init__.py +28 -0
  52. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/metrics/__init__.py +1 -0
  53. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/metrics/answer_relevancy.py +57 -0
  54. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/metrics/context_relevancy.py +57 -0
  55. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/metrics/faithfulness.py +60 -0
  56. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/metrics/pii.py +55 -0
  57. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/metrics/prompt_injection.py +55 -0
  58. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3/metrics/summarization.py +54 -0
  59. trustwise-0.1.0a1/src/trustwise/sdk/metrics/safety/v3.py +89 -0
  60. trustwise-0.1.0a1/src/trustwise/sdk/protocols.py +24 -0
  61. trustwise-0.1.0a1/src/trustwise/sdk/sdk.py +92 -0
  62. trustwise-0.1.0a1/src/trustwise/sdk/types.py +345 -0
  63. trustwise-0.1.0a1/tests/__init__.py +0 -0
  64. trustwise-0.1.0a1/tests/conftest.py +50 -0
  65. trustwise-0.1.0a1/tests/helpers.py +107 -0
  66. trustwise-0.1.0a1/tests/sdk/test_config.py +143 -0
  67. trustwise-0.1.0a1/tests/test_alignment_metrics.py +280 -0
  68. trustwise-0.1.0a1/tests/test_guardrails.py +227 -0
  69. trustwise-0.1.0a1/tests/test_installation.py +152 -0
  70. trustwise-0.1.0a1/tests/test_performance_metrics.py +245 -0
  71. trustwise-0.1.0a1/tests/test_safety_metrics.py +407 -0
  72. trustwise-0.1.0a1/tests/test_sdk.py +161 -0
  73. trustwise-0.1.0a1/tests/test_sdk_base_model.py +59 -0
  74. trustwise-0.1.0a1/tire_maintenance.txt +109 -0
  75. trustwise-0.1.0a1/todo.md +16 -0
  76. trustwise-0.1.0a1/tox.ini +39 -0
  77. trustwise-0.1.0a1/uv.lock +824 -0
@@ -0,0 +1,48 @@
1
+ #!/bin/sh
2
+
3
+ # Colors for output
4
+ RED='\033[0;31m'
5
+ GREEN='\033[0;32m'
6
+ NC='\033[0m' # No Color
7
+
8
+ echo "Running pre-push checks..."
9
+
10
+ # Function to check if a command exists
11
+ command_exists() {
12
+ command -v "$1" >/dev/null 2>&1
13
+ }
14
+
15
+ # Check if uv is installed
16
+ if ! command_exists uv; then
17
+ echo -e "${RED}Error: uv is not installed. Please install it first:${NC}"
18
+ echo "curl -LsSf https://astral.sh/uv/install.sh | sh"
19
+ exit 1
20
+ fi
21
+
22
+ # Install dependencies if needed
23
+ echo "Installing dependencies..."
24
+ uv pip install --system -e ".[dev]"
25
+
26
+ # Run pytest with coverage
27
+ echo "Running tests..."
28
+ if ! pytest tests/ -v --cov=trustwise --cov-report=term-missing; then
29
+ echo -e "${RED}Tests failed!${NC}"
30
+ exit 1
31
+ fi
32
+
33
+ # Run ruff linting
34
+ echo "Running linting checks..."
35
+ if ! ruff check src tests; then
36
+ echo -e "${RED}Linting failed!${NC}"
37
+ exit 1
38
+ fi
39
+
40
+ # Build documentation
41
+ echo "Building documentation..."
42
+ if ! sphinx-build -b html docs/source docs/_build/html; then
43
+ echo -e "${RED}Documentation build failed!${NC}"
44
+ exit 1
45
+ fi
46
+
47
+ echo -e "${GREEN}All checks passed!${NC}"
48
+ exit 0
@@ -0,0 +1,56 @@
1
+ name: Build and Test Package
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ build-and-test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.11", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+
24
+ - name: Install uv
25
+ run: |
26
+ curl -LsSf https://astral.sh/uv/install.sh | sh
27
+ echo "$HOME/.cargo/bin" >> $GITHUB_PATH
28
+
29
+ - name: Build wheel
30
+ run: |
31
+ uv build --wheel
32
+
33
+ - name: Create isolated environment and test installation
34
+ run: |
35
+ # Create a new virtual environment
36
+ python -m venv test_env
37
+ source test_env/bin/activate
38
+
39
+ # Install the wheel
40
+ pip install dist/*.whl
41
+
42
+ # Test importing the package and key components
43
+ python -c "
44
+ import trustwise
45
+ print('Successfully imported trustwise')
46
+
47
+ # Test importing main SDK components
48
+ from trustwise.sdk import TrustwiseSDK
49
+ from trustwise.sdk.config import TrustwiseConfig
50
+ print('Successfully imported SDK components')
51
+
52
+ # Verify package metadata
53
+ assert hasattr(trustwise, '__version__')
54
+ assert isinstance(trustwise.__version__, str)
55
+ print('Successfully verified package metadata')
56
+ "
@@ -0,0 +1,102 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ # Add permissions at the workflow level
10
+ permissions:
11
+ contents: read
12
+ pages: write
13
+ id-token: write
14
+
15
+ jobs:
16
+ test:
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ matrix:
20
+ python-version: ["3.11", "3.12"]
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - name: Set up Python ${{ matrix.python-version }}
26
+ uses: actions/setup-python@v5
27
+ with:
28
+ python-version: ${{ matrix.python-version }}
29
+
30
+ - name: Install uv
31
+ run: |
32
+ curl -LsSf https://astral.sh/uv/install.sh | sh
33
+ echo "$HOME/.cargo/bin" >> $GITHUB_PATH
34
+
35
+ - name: Install dependencies
36
+ run: |
37
+ uv pip install --system -e ".[dev]"
38
+
39
+ - name: Run tests with tox
40
+ run: |
41
+ tox -e py${{ matrix.python-version == '3.11' && '311' || '312' }}
42
+
43
+ lint:
44
+ runs-on: ubuntu-latest
45
+ steps:
46
+ - uses: actions/checkout@v4
47
+
48
+ - name: Set up Python
49
+ uses: actions/setup-python@v5
50
+ with:
51
+ python-version: "3.12"
52
+
53
+ - name: Install uv
54
+ run: |
55
+ curl -LsSf https://astral.sh/uv/install.sh | sh
56
+ echo "$HOME/.cargo/bin" >> $GITHUB_PATH
57
+
58
+ - name: Install dependencies
59
+ run: |
60
+ uv pip install --system -e ".[dev]"
61
+
62
+ - name: Run linting with tox
63
+ run: |
64
+ tox -e lint
65
+
66
+ docs:
67
+ environment:
68
+ name: github-pages
69
+ url: ${{ steps.deployment.outputs.page_url }}
70
+ runs-on: ubuntu-latest
71
+ steps:
72
+ - uses: actions/checkout@v4
73
+
74
+ - name: Set up Python
75
+ uses: actions/setup-python@v5
76
+ with:
77
+ python-version: "3.12"
78
+
79
+ - name: Install uv
80
+ run: |
81
+ curl -LsSf https://astral.sh/uv/install.sh | sh
82
+ echo "$HOME/.cargo/bin" >> $GITHUB_PATH
83
+
84
+ - name: Install dependencies
85
+ run: |
86
+ uv pip install --system -e ".[dev]"
87
+
88
+ - name: Build documentation with tox
89
+ run: |
90
+ tox -e docs
91
+
92
+ - name: Setup Pages
93
+ uses: actions/configure-pages@v4
94
+
95
+ - name: Upload artifact
96
+ uses: actions/upload-pages-artifact@v3
97
+ with:
98
+ path: docs/_build/html
99
+
100
+ - name: Deploy to GitHub Pages
101
+ id: deployment
102
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,43 @@
1
+ # Simple workflow for deploying static content to GitHub Pages
2
+ name: Deploy static content to Pages
3
+
4
+ on:
5
+ # Runs on pushes targeting the default branch
6
+ push:
7
+ branches: ["main"]
8
+
9
+ # Allows you to run this workflow manually from the Actions tab
10
+ workflow_dispatch:
11
+
12
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13
+ permissions:
14
+ contents: read
15
+ pages: write
16
+ id-token: write
17
+
18
+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19
+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20
+ concurrency:
21
+ group: "pages"
22
+ cancel-in-progress: false
23
+
24
+ jobs:
25
+ # Single deploy job since we're just deploying
26
+ deploy:
27
+ environment:
28
+ name: github-pages
29
+ url: ${{ steps.deployment.outputs.page_url }}
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v4
34
+ - name: Setup Pages
35
+ uses: actions/configure-pages@v5
36
+ - name: Upload artifact
37
+ uses: actions/upload-pages-artifact@v3
38
+ with:
39
+ # Upload entire repository
40
+ path: '.'
41
+ - name: Deploy to GitHub Pages
42
+ id: deployment
43
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,174 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
@@ -0,0 +1,268 @@
1
+ Metadata-Version: 2.4
2
+ Name: trustwise
3
+ Version: 0.1.0a1
4
+ Summary: Trustwise SDK for evaluating AI-generated content
5
+ Project-URL: Homepage, https://trustwise.ai
6
+ Project-URL: Documentation, https://docs.trustwise.ai
7
+ Project-URL: Repository, https://github.com/trustwise/trustwise-sdk
8
+ Project-URL: Issues, https://github.com/trustwise/trustwise-sdk/issues
9
+ Author-email: Trustwise Team <team@trustwise.ai>
10
+ License-Expression: MIT
11
+ Keywords: ai,alignment,evaluation,metrics,safety
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: importlib-metadata>=6.0.0; python_version < '3.8'
21
+ Requires-Dist: pydantic>=2.11.0
22
+ Requires-Dist: python-dotenv>=1.0.0
23
+ Requires-Dist: requests>=2.31.0
24
+ Requires-Dist: urllib3>=2.4.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: docutils>=0.21.0; extra == 'dev'
27
+ Requires-Dist: mypy>=1.15.0; extra == 'dev'
28
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
29
+ Requires-Dist: pytest-mock>=3.10.0; extra == 'dev'
30
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
31
+ Requires-Dist: ruff>=0.11.0; extra == 'dev'
32
+ Requires-Dist: sphinx-autodoc-typehints>=2.0.0; extra == 'dev'
33
+ Requires-Dist: sphinx-rtd-theme>=3.0.2; extra == 'dev'
34
+ Requires-Dist: sphinx>=8.2.0; extra == 'dev'
35
+ Requires-Dist: tox>=4.0.0; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # 🦉 Trustwise Python SDK
39
+
40
+ A powerful, flexible SDK for evaluating AI-generated content with Trustwise's Safety and Alignment metrics. This SDK provides a clean path-based versioning approach that makes working with different API versions intuitive and explicit.
41
+
42
+ ## 🔥 Features
43
+
44
+ - **Path-based API versioning**: Access specific API versions directly using intuitive paths (e.g., `sdk.safety.v3.faithfulness`)
45
+ - **Backward compatibility**: Maintain code simplicity with default version methods (e.g., `sdk.safety.faithfulness`)
46
+ - **Comprehensive evaluation metrics**: Assess faithfulness, relevancy, clarity, helpfulness, and more
47
+ - **LLM guardrails**: Set thresholds and automatically validate responses against multiple metrics
48
+ - **Framework integrations**: Ready-to-use callback handlers for LangChain and LlamaIndex
49
+ - **Detailed analytics**: Get comprehensive insights from every evaluation, including scores, facts, and analysis
50
+
51
+ ## 📦 Installation
52
+
53
+ ```bash
54
+ pip install trustwise
55
+ ```
56
+
57
+ ## 🚀 Quick Start
58
+
59
+ Get started with Trustwise in just a few lines of code:
60
+
61
+ ```python
62
+ import os
63
+ from trustwise.sdk import TrustwiseSDK
64
+ from trustwise.sdk.config import TrustwiseConfig
65
+
66
+ # Set your API key
67
+ os.environ["TW_API_KEY"] = "your-api-key"
68
+
69
+ # Initialize the SDK
70
+ config = TrustwiseConfig()
71
+ trustwise = TrustwiseSDK(config)
72
+ ```
73
+
74
+ ### 🛡️ Safety Metrics
75
+
76
+ Evaluate content safety and faithfulness:
77
+
78
+ ```python
79
+ # Example context
80
+ context = [{
81
+ "node_text": "Paris is the capital of France.",
82
+ "node_score": 0.95,
83
+ "node_id": "doc:idx:1"
84
+ }]
85
+
86
+ # Evaluate faithfulness
87
+ result = trustwise.safety.v3.faithfulness.evaluate(
88
+ query="What is the capital of France?",
89
+ response="The capital of France is Paris.",
90
+ context=context
91
+ )
92
+ print(f"Faithfulness score: {result['score']}")
93
+
94
+ # Evaluate PII detection
95
+ pii_result = trustwise.safety.v3.pii.evaluate(
96
+ text="My email is john@example.com and my phone is 123-456-7890",
97
+ allowlist=["john@example.com"] # Allow specific PII
98
+ )
99
+ print(f"PII detection result: {pii_result}")
100
+ ```
101
+
102
+ ### 🎯 Alignment Metrics
103
+
104
+ Assess content quality and alignment:
105
+
106
+ ```python
107
+ # Evaluate clarity
108
+ clarity_result = trustwise.alignment.v1.clarity.evaluate(
109
+ query="What is the capital of France?",
110
+ response="The capital of France is Paris."
111
+ )
112
+ print(f"Clarity score: {clarity_result['score']}")
113
+
114
+ # Evaluate tone
115
+ tone_result = trustwise.alignment.v1.tone.evaluate(
116
+ response="The capital of France is Paris."
117
+ )
118
+ print(f"Tone result: {tone_result}")
119
+ ```
120
+
121
+ ### 💰 Performance Metrics
122
+
123
+ Evaluate cost and carbon emissions for your AI models:
124
+
125
+ ```python
126
+ # Evaluate cost for OpenAI model
127
+ cost_result = trustwise.performance.v1.cost(
128
+ model_name="gpt-3.5-turbo",
129
+ model_type="LLM",
130
+ model_provider="OpenAI",
131
+ number_of_queries=5,
132
+ total_prompt_tokens=950,
133
+ total_completion_tokens=50
134
+ )
135
+ print(f"Cost per run: ${cost_result['cost_estimate_per_run']}")
136
+ print(f"Total project cost: ${cost_result['total_project_cost_estimate']}")
137
+
138
+ # Evaluate carbon emissions
139
+ carbon_result = trustwise.performance.v1.carbon(
140
+ processor_name="NVIDIA A100",
141
+ provider_name="AWS",
142
+ provider_region="us-east-1",
143
+ instance_type="p4d.24xlarge",
144
+ average_latency=100
145
+ )
146
+ print(f"Carbon emissions: {carbon_result['carbon_emissions']} kg CO2e")
147
+ ```
148
+
149
+ ### 🚧 Guardrails
150
+
151
+ Create guardrails to automatically validate responses:
152
+
153
+ ```python
154
+ # Create a multi-metric guardrail
155
+ guardrail = trustwise.guardrails(
156
+ thresholds={
157
+ "faithfulness": 0.8,
158
+ "answer_relevancy": 0.7,
159
+ "clarity": 0.7
160
+ },
161
+ block_on_failure=True
162
+ )
163
+
164
+ # Evaluate with multiple metrics
165
+ evaluation = guardrail.evaluate_response(
166
+ query="What is the capital of France?",
167
+ response="The capital of France is Paris.",
168
+ context=context
169
+ )
170
+
171
+ print("Guardrail Evaluation:")
172
+ print(f"Passed all checks: {evaluation['passed']}")
173
+ print(f"Response blocked: {evaluation['blocked']}")
174
+ for metric, result in evaluation['results'].items():
175
+ print(f" - {metric}: {result['passed']} (score: {result['result'].get('score')})")
176
+ ```
177
+
178
+ ## 🔐 API Key Setup
179
+
180
+ Get your API Key by logging in through Github -> [link](https://trustwise.ai)
181
+
182
+ The SDK requires an API key to authenticate requests. You can provide the API key in several ways:
183
+
184
+ ```python
185
+ # Option 1: From environment variable (recommended)
186
+ import os
187
+ from trustwise.sdk import TrustwiseSDK
188
+ from trustwise.sdk.config import TrustwiseConfig
189
+
190
+ # Set environment variable (you can also set this in your shell or .env file)
191
+ os.environ["TW_API_KEY"] = "your-api-key"
192
+
193
+ # Initialize with configuration object
194
+ config = TrustwiseConfig() # Will automatically use TW_API_KEY from environment
195
+ trustwise = TrustwiseSDK(config)
196
+
197
+ # Option 2: Direct initialization
198
+ config = TrustwiseConfig(api_key="your-api-key")
199
+ trustwise = TrustwiseSDK(config)
200
+
201
+ # Option 3: Mixed approach (direct values take precedence)
202
+ os.environ["TW_API_KEY"] = "env-key" # Set environment variable
203
+ config = TrustwiseConfig(api_key="direct-key") # Will override TW_API_KEY
204
+ trustwise = TrustwiseSDK(config)
205
+ ```
206
+
207
+ ## 📚 API Versioning
208
+
209
+ The SDK supports both explicit version paths and default version usage:
210
+
211
+ ```python
212
+ # Using explicit version path
213
+ result = trustwise.safety.v3.faithfulness.evaluate(...)
214
+
215
+ # Using default version (backward compatibility)
216
+ result = trustwise.safety.faithfulness.evaluate(...)
217
+
218
+ # Set default version explicitly
219
+ trustwise.safety.set_version("v3")
220
+ ```
221
+
222
+ ## 📊 Available Metrics
223
+
224
+ ### Safety Metrics (v3)
225
+ - Faithfulness
226
+ - Answer Relevancy
227
+ - Context Relevancy
228
+ - Summarization
229
+ - PII Detection
230
+ - Prompt Injection Detection
231
+
232
+ ### Alignment Metrics (v1)
233
+ - Clarity
234
+ - Helpfulness
235
+ - Toxicity
236
+ - Tone
237
+ - Formality
238
+ - Simplicity
239
+ - Sensitivity
240
+
241
+ ### Performance Metrics (v1)
242
+ - Cost Estimation
243
+ - Support for multiple providers (OpenAI, Hugging Face, Azure)
244
+ - Support for both LLM and Reranker models
245
+ - Detailed cost breakdown per run and total project cost
246
+ - Carbon Emissions
247
+ - Processor-specific emissions calculation
248
+ - Provider and region-aware estimates
249
+ - Latency-based calculations
250
+
251
+ ## 📝 License
252
+
253
+ This project is licensed under the MIT License - see the LICENSE file for details.
254
+
255
+ ## 🤝 Contributing
256
+
257
+ We welcome contributions! If you find a bug, have a feature request, or want to contribute code, please create an issue or submit a pull request.
258
+
259
+ ### Git Hooks
260
+
261
+ This repository includes git hooks to ensure code quality. To install them:
262
+
263
+ ```bash
264
+ # Make sure you're in the repository root
265
+ ./scripts/install-hooks.sh
266
+ ```
267
+
268
+ The hooks will run tests, linting, and documentation checks before each push to ensure code quality.