No project description provided
Project description
Scorecard AI Python Library
Installation
Add this dependency to your project's build file:
pip install scorecard-ai
# or
poetry add scorecard-ai
Usage
We also export an HTTP client so that you can hit our APIs directly.
import scorecard
from scorecard.client import Scorecard
client = Scorecard(
api_key="YOUR_API_KEY" # Defaults to SCORECARD_API_KEY
)
testset = client.testset.create(
testset_id=1234,
user_query="Your prompt...",
model_params: {
"param": "value"
}
)
print(testset)
Async Client
Use our async cien to make non-blocking requests to the API.
import scorecard
import asyncio
from scorecard.client import AsyncScorecard
client = AsyncScorecard(
api_key="YOUR_API_KEY" # Defaults to SCORECARD_API_KEY
)
async def main() -> None:
testset = await client.testset.create(
testset_id=1234,
user_query="Your prompt...",
model_params: {
"param": "value"
}
)
print(testset)
asyncio.run(main())
Running Tests
The run_tests
method will load your test cases,
invoke your models with saved prompts, and record success and failure. This is
available on both the sync and async client.
from scorecard.client import Scorecard
client = Scorecard(
api_key="YOUR_API_KEY"
)
client.run_tests(
# Your Testset ID
input_testset_id=123,
# Your Scoring Config ID
scoring_config_id=456,
# The model invocation that you would like to test
model_invocation=lambda prompt: call_model(prompt),
)
Timeouts
By default, the client is configured to have a timeout of 60 seconds. You can customize this value at client instantiation.
from scorecard.client import Scorecard
scorecard_client = Scorecard(
api_key="YOUR_API_KEY",
timeout=15,
)
Handling Exceptions
All exceptions thrown by the SDK will subclass scorecard.ApiError.
from scorecard.core import ApiError
from scorecard import UnprocessableEntityError
try:
client.testset.get("testset-id")
except UnprocessableEntityError as e:
# handle unprocessable entity error
except APIError as e:
# handle any api related error
Error codes are as followed:
Status Code | Error Type |
---|---|
422 | UnprocessableEntityError |
Telemetry
If you wish to use the Scorecard telemetry setup, you may choose to add the telemetry
package extra:
pip install scorecard-ai[telemetry,instrument-openai]
# or
poetry add scorecard-ai --extras "telemetry instrument-openai"
Scorecard's SDK can auto-instrument certain AI tools for you by including them in the extras enumeration:
instrument-bedrock
instrument-dspy
instrument-langchain
instrument-llama-index
instrument-mistralai
instrument-openai
Beta status
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your pyproject.toml file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file scorecard_ai-1.1.0.tar.gz
.
File metadata
- Download URL: scorecard_ai-1.1.0.tar.gz
- Upload date:
- Size: 41.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.19 Linux/5.15.0-1071-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42602e9ac48a89a3d45835bc77249a72e98a8332a1e5c992225ddb0eea638244 |
|
MD5 | ddc37c5afc29564e2e14fe19ca361b3f |
|
BLAKE2b-256 | bb42a2962263ab66782f3a56a9be668b880091dc4df0bcbed4e6c5425f94cbd6 |
File details
Details for the file scorecard_ai-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: scorecard_ai-1.1.0-py3-none-any.whl
- Upload date:
- Size: 78.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.19 Linux/5.15.0-1071-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4948a1b83f0189d9226f222c47bf5f1a0551e1a2fcf617648168ea442560dfa3 |
|
MD5 | 2b0eafea087ff995554596d2940aa98d |
|
BLAKE2b-256 | 49e2bd59d2f4c9652a412dcb6b5187fb9a22a684fa0a89029702679a4da266f8 |