Client Libraries
API Reference
- Scoring System
- Prompt Optimization
- Data Generation
- Model Training
- Search
Score
Scores the provided input and output based on the given scoring spec
import PiClient from 'withpi';
const client = new PiClient({
apiKey: process.env['WITHPI_API_KEY'], // This is the default and can be omitted
});
async function main() {
const scoringSystemMetrics = await client.scoringSystem.score({
llm_input: 'Tell me something different',
llm_output: 'The lazy dog was jumped over by the quick brown fox',
scoring_spec: {
description: "Write a children's story communicating a simple life lesson.",
dimensions: [
{
description: 'dimension1 description',
label: 'dimension1',
sub_dimensions: [
{ description: 'subdimension1 description', label: 'subdimension1', scoring_type: 'PI_SCORER' },
],
},
],
name: 'Sample Scoring Spec',
},
});
console.log(scoringSystemMetrics.dimension_scores);
}
main();
{
"dimension_scores": {
"dimension1": {
"subdimension_scores": {
"subdimension1": 0.5
},
"total_score": 0.5
}
},
"total_score": 0.4
}
Authorizations
Body
The input to score
"Tell me something different"
The output to score
"The lazy dog was jumped over by the quick brown fox"
The scoring spec to score
The application description
"Write a children's story communicating a simple life lesson."
The dimensions of the scoring spec
The description of the dimension
"Relevance of the response"
The label of the dimension
"Relevance"
The sub dimensions of the dimension
The description of the dimension
"Is the response relevant to the prompt?"
The label of the dimension
"Relevance to Prompt"
The type of scoring performed for this dimension
PI_SCORER
, PYTHON_CODE
, CUSTOM_MODEL_SCORER
The ID of the custom model to use for scoring. Only relevant for scoring_type of CUSTOM_MODEL_SCORER
"your-model-id"
The learned parameters for the scoring method. This represents piecewise linear interpolation between [0, 1].
[
0.14285714285714285,
0.2857142857142857,
0.42857142857142855,
0.5714285714285714,
0.7142857142857143,
0.8571428571428571
]
The PYTHON code associated the PYTHON_CODE DimensionScoringType.
"\ndef score(response_text: str, input_text: str, kwargs: dict) -> dict:\n word_count = len(response_text.split())\n if word_count > 10:\n return {\"score\": 0.2, \"explanation\": \"Response has more than 10 words\"}\n elif word_count > 5:\n return{\"score\": 0.6, \"explanation\": \"Response has more than 5 words\"}\n else:\n return {\"score\": 1, \"explanation\": \"Response has 5 or fewer words\"}\n"
The weight of the subdimension. The sum of subdimension weights will be normalized to one internally. A higher weight counts for more when aggregating this subdimension into the parent dimension.
1
{
"description": "subdimension1 description",
"label": "subdimension1",
"scoring_type": "PI_SCORER"
}
The learned parameters for the scoring method. This represents piecewise linear interpolation between [0, 1].
[
0.14285714285714285,
0.2857142857142857,
0.42857142857142855,
0.5714285714285714,
0.7142857142857143,
0.8571428571428571
]
The weight of the dimension The sum of dimension weights will be normalized to one internally. A higher weight counts for more when aggregating this dimension is aggregated into the final score.
1
[
{
"description": "dimension1 description",
"label": "dimension1",
"sub_dimensions": [
{
"description": "subdimension1 description",
"label": "subdimension1",
"scoring_type": "PI_SCORER"
}
]
}
]
The name of the scoring spec
"Sample Scoring Spec"
Response
The score components for each dimension
{
"dimension1": {
"subdimension_scores": { "subdimension1": 0.5 },
"total_score": 0.5
}
}
The total score of the scoring spec
0.4
import PiClient from 'withpi';
const client = new PiClient({
apiKey: process.env['WITHPI_API_KEY'], // This is the default and can be omitted
});
async function main() {
const scoringSystemMetrics = await client.scoringSystem.score({
llm_input: 'Tell me something different',
llm_output: 'The lazy dog was jumped over by the quick brown fox',
scoring_spec: {
description: "Write a children's story communicating a simple life lesson.",
dimensions: [
{
description: 'dimension1 description',
label: 'dimension1',
sub_dimensions: [
{ description: 'subdimension1 description', label: 'subdimension1', scoring_type: 'PI_SCORER' },
],
},
],
name: 'Sample Scoring Spec',
},
});
console.log(scoringSystemMetrics.dimension_scores);
}
main();
{
"dimension_scores": {
"dimension1": {
"subdimension_scores": {
"subdimension1": 0.5
},
"total_score": 0.5
}
},
"total_score": 0.4
}