Execute context-relevance evaluator
curl --request POST \
--url https://api.traceloop.com/v2/evaluators/context-relevance/execute \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"input": {
"completion": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"context": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"query": "What are the business hours?"
},
"config": {
"model": "gpt-4o"
}
}
'import requests
url = "https://api.traceloop.com/v2/evaluators/context-relevance/execute"
payload = {
"input": {
"completion": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"context": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"query": "What are the business hours?"
},
"config": { "model": "gpt-4o" }
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
input: {
completion: 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
context: 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
query: 'What are the business hours?'
},
config: {model: 'gpt-4o'}
})
};
fetch('https://api.traceloop.com/v2/evaluators/context-relevance/execute', 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://api.traceloop.com/v2/evaluators/context-relevance/execute",
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([
'input' => [
'completion' => 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
'context' => 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
'query' => 'What are the business hours?'
],
'config' => [
'model' => 'gpt-4o'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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://api.traceloop.com/v2/evaluators/context-relevance/execute"
payload := strings.NewReader("{\n \"input\": {\n \"completion\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"context\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"query\": \"What are the business hours?\"\n },\n \"config\": {\n \"model\": \"gpt-4o\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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://api.traceloop.com/v2/evaluators/context-relevance/execute")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"input\": {\n \"completion\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"context\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"query\": \"What are the business hours?\"\n },\n \"config\": {\n \"model\": \"gpt-4o\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.traceloop.com/v2/evaluators/context-relevance/execute")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"input\": {\n \"completion\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"context\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"query\": \"What are the business hours?\"\n },\n \"config\": {\n \"model\": \"gpt-4o\"\n }\n}"
response = http.request(request)
puts response.read_body{
"relevance_score": 0.88
}{
"error": "error message"
}{
"error": "error message"
}Evaluators
Execute context-relevance evaluator
Evaluate whether retrieved context contains sufficient information to answer the query
Request Body:
input.query(string, required): The query/question to evaluate context relevance forinput.completion(string, required): The completion to evaluate for context relevanceinput.context(string, required): The context to evaluate for relevance to the queryconfig.model(string, optional): Model to use for evaluation (default: gpt-4o)
POST
/
v2
/
evaluators
/
context-relevance
/
execute
Execute context-relevance evaluator
curl --request POST \
--url https://api.traceloop.com/v2/evaluators/context-relevance/execute \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"input": {
"completion": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"context": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"query": "What are the business hours?"
},
"config": {
"model": "gpt-4o"
}
}
'import requests
url = "https://api.traceloop.com/v2/evaluators/context-relevance/execute"
payload = {
"input": {
"completion": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"context": "Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.",
"query": "What are the business hours?"
},
"config": { "model": "gpt-4o" }
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
input: {
completion: 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
context: 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
query: 'What are the business hours?'
},
config: {model: 'gpt-4o'}
})
};
fetch('https://api.traceloop.com/v2/evaluators/context-relevance/execute', 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://api.traceloop.com/v2/evaluators/context-relevance/execute",
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([
'input' => [
'completion' => 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
'context' => 'Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.',
'query' => 'What are the business hours?'
],
'config' => [
'model' => 'gpt-4o'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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://api.traceloop.com/v2/evaluators/context-relevance/execute"
payload := strings.NewReader("{\n \"input\": {\n \"completion\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"context\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"query\": \"What are the business hours?\"\n },\n \"config\": {\n \"model\": \"gpt-4o\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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://api.traceloop.com/v2/evaluators/context-relevance/execute")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"input\": {\n \"completion\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"context\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"query\": \"What are the business hours?\"\n },\n \"config\": {\n \"model\": \"gpt-4o\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.traceloop.com/v2/evaluators/context-relevance/execute")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"input\": {\n \"completion\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"context\": \"Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays.\",\n \"query\": \"What are the business hours?\"\n },\n \"config\": {\n \"model\": \"gpt-4o\"\n }\n}"
response = http.request(request)
puts response.read_body{
"relevance_score": 0.88
}{
"error": "error message"
}{
"error": "error message"
}Was this page helpful?
⌘I

