curl --request POST \
--url https://dev.api.galtea.ai/v2/metrics/code/dry-run \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "def measure(actual_output):\n return 1.0 if actual_output else 0.0\n",
"inferenceResultIds": [
"inferenceResult_123"
]
}
'import requests
url = "https://dev.api.galtea.ai/v2/metrics/code/dry-run"
payload = {
"code": "def measure(actual_output):
return 1.0 if actual_output else 0.0
",
"inferenceResultIds": ["inferenceResult_123"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
code: 'def measure(actual_output):\n return 1.0 if actual_output else 0.0\n',
inferenceResultIds: ['inferenceResult_123']
})
};
fetch('https://dev.api.galtea.ai/v2/metrics/code/dry-run', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://dev.api.galtea.ai/v2/metrics/code/dry-run",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'def measure(actual_output):
return 1.0 if actual_output else 0.0
',
'inferenceResultIds' => [
'inferenceResult_123'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://dev.api.galtea.ai/v2/metrics/code/dry-run"
payload := strings.NewReader("{\n \"code\": \"def measure(actual_output):\\n return 1.0 if actual_output else 0.0\\n\",\n \"inferenceResultIds\": [\n \"inferenceResult_123\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://dev.api.galtea.ai/v2/metrics/code/dry-run")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"def measure(actual_output):\\n return 1.0 if actual_output else 0.0\\n\",\n \"inferenceResultIds\": [\n \"inferenceResult_123\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://dev.api.galtea.ai/v2/metrics/code/dry-run")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"def measure(actual_output):\\n return 1.0 if actual_output else 0.0\\n\",\n \"inferenceResultIds\": [\n \"inferenceResult_123\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"outcome": "ran",
"error": "<string>",
"arguments": [
"actual_output",
"expected_output"
],
"runnerVersion": "<string>",
"traces": [
{
"inferenceResultId": "inferenceResult_123",
"outcome": "scored",
"score": 123,
"reason": "<string>",
"error": "<string>"
}
]
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}Test a code metric on traces
Runs a code metric that is not saved on 1 to 20 stored traces, in the code metric sandbox. The code is checked first: code that does not load answers its error and no trace result. Code that loads answers one result per trace. Each trace gets the values a real run of the metric would give measure, and a trace a real run would skip comes back skipped. Persists nothing and consumes no credits. Answers 400 where the deployment does not enable code metrics. The dry run stops starting traces after 60 seconds.
curl --request POST \
--url https://dev.api.galtea.ai/v2/metrics/code/dry-run \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "def measure(actual_output):\n return 1.0 if actual_output else 0.0\n",
"inferenceResultIds": [
"inferenceResult_123"
]
}
'import requests
url = "https://dev.api.galtea.ai/v2/metrics/code/dry-run"
payload = {
"code": "def measure(actual_output):
return 1.0 if actual_output else 0.0
",
"inferenceResultIds": ["inferenceResult_123"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
code: 'def measure(actual_output):\n return 1.0 if actual_output else 0.0\n',
inferenceResultIds: ['inferenceResult_123']
})
};
fetch('https://dev.api.galtea.ai/v2/metrics/code/dry-run', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://dev.api.galtea.ai/v2/metrics/code/dry-run",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => 'def measure(actual_output):
return 1.0 if actual_output else 0.0
',
'inferenceResultIds' => [
'inferenceResult_123'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://dev.api.galtea.ai/v2/metrics/code/dry-run"
payload := strings.NewReader("{\n \"code\": \"def measure(actual_output):\\n return 1.0 if actual_output else 0.0\\n\",\n \"inferenceResultIds\": [\n \"inferenceResult_123\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://dev.api.galtea.ai/v2/metrics/code/dry-run")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"def measure(actual_output):\\n return 1.0 if actual_output else 0.0\\n\",\n \"inferenceResultIds\": [\n \"inferenceResult_123\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://dev.api.galtea.ai/v2/metrics/code/dry-run")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"def measure(actual_output):\\n return 1.0 if actual_output else 0.0\\n\",\n \"inferenceResultIds\": [\n \"inferenceResult_123\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"outcome": "ran",
"error": "<string>",
"arguments": [
"actual_output",
"expected_output"
],
"runnerVersion": "<string>",
"traces": [
{
"inferenceResultId": "inferenceResult_123",
"outcome": "scored",
"score": 123,
"reason": "<string>",
"error": "<string>"
}
]
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}{
"error": "NotFound",
"message": "Product not found"
}Authorizations
API key authorization. Pass your API key in the Authorization header as a Bearer token. Both new (gsk_*) and legacy (gsk-) API keys are accepted, e.g. Authorization: Bearer gsk_... or Authorization: Bearer gsk-....
Body
The Python file to test. It defines a function named measure.
1 - 80000"def measure(actual_output):\n return 1.0 if actual_output else 0.0\n"
The traces to score, 1 to 20. Results come back in this order.
1 - 20 elements1["inferenceResult_123"]
Response
The code was checked: its error when it does not load, else one result per trace
failed: the code does not load, and error says why; no trace was scored.
ran, failed Why the code does not load, with its line.
The trace values measure takes.
["actual_output", "expected_output"]
One result per asked trace, in the asked order, when the code loads. Empty when it does not.
Show child attributes
Show child attributes