59 lines
5.0 KiB
C++
59 lines
5.0 KiB
C++
// Route: POST /ai/retrieval/call (generic table-driven call: 422, dry runs, 503 without a credential)
|
|
#include <cstdlib>
|
|
|
|
#include "support/Assert.hpp"
|
|
|
|
using namespace molo::example::test;
|
|
|
|
int main() {
|
|
setenv("MOLO_ENV_FILES", "off", 1);
|
|
for (const char* v : {"VOYAGE_API_KEY", "JINA_API_KEY", "PINECONE_API_KEY", "QDRANT_API_KEY", "QDRANT_URL", "WEAVIATE_API_KEY",
|
|
"WEAVIATE_URL", "MXBAI_API_KEY", "TAVILY_API_KEY", "EXA_API_KEY", "BRAVE_API_KEY"})
|
|
unsetenv(v);
|
|
Fixture f;
|
|
auto post = [&](const std::string& body) { return f.client->post("/ai/retrieval/call", body, "application/json"); };
|
|
|
|
// 422: input rules run before anything else
|
|
check(post("{\"provider\":\"qdrant\"}").status == 422, "call name is required");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"nope\"}").status == 422, "unknown call");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collection\"}").status == 422, "missing path parameter");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collection\",\"path\":{\"collection_name\":\"../x\"}}").status == 422, "path traversal id");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collection\",\"path\":{\"collection_name\":\"a b\"}}").status == 422, "id with a space");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"query\":{\"bogus\":1}}").status == 422, "query parameter not in the table");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"body\":{\"a\":1}}").status == 422, "GET takes no body");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"upsert_points\",\"path\":{\"collection_name\":\"c\"},\"body\":{\"nope\":1}}").status == 422, "body field not in the table");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"path\":[1]}").status == 422, "path must be an object");
|
|
check(post("{\"provider\":\"qdrant\",\"call\":\"get_collections\",\"query\":{\"x\":[1]}}").status == 422, "query values are scalars");
|
|
check(post("{\"provider\":\"pinecone\",\"call\":\"describe_index_stats\",\"body\":{}}").status == 422, "data plane call needs index_host");
|
|
check(post("{\"provider\":\"pinecone\",\"call\":\"describe_index_stats\",\"index_host\":\"https://x.io\",\"body\":{}}").status == 422, "index_host must be a bare host");
|
|
|
|
// dry runs: writes, destructive and paid calls show the exact request
|
|
auto upsert = post("{\"provider\":\"qdrant\",\"call\":\"upsert_points\",\"path\":{\"collection_name\":\"docs\"},\"query\":{\"wait\":true},\"body\":{\"points\":[]}}");
|
|
check(upsert.status == 200 && contains(upsert.body, "\"dry_run\":true") && contains(upsert.body, "/collections/docs/points?wait=true"),
|
|
"upsert is a dry run with the rendered target");
|
|
auto del = post("{\"provider\":\"qdrant\",\"call\":\"delete_collection\",\"path\":{\"collection_name\":\"docs\"}}");
|
|
check(del.status == 200 && contains(del.body, "\"dry_run\":true") && contains(del.body, "\"flags\":\"d\""), "delete collection is a dry run");
|
|
auto delidx = post("{\"provider\":\"pinecone\",\"call\":\"delete_index\",\"path\":{\"index_name\":\"docs\"}}");
|
|
check(delidx.status == 200 && contains(delidx.body, "\"dry_run\":true"), "delete index is a dry run");
|
|
auto delvec = post("{\"provider\":\"pinecone\",\"call\":\"delete_vectors\",\"index_host\":\"docs-abc.svc.pinecone.io\",\"body\":{\"deleteAll\":true}}");
|
|
check(delvec.status == 200 && contains(delvec.body, "\"dry_run\":true") && contains(delvec.body, "deleteAll"), "delete vectors is a dry run");
|
|
auto paid = post("{\"provider\":\"voyage\",\"call\":\"embed\",\"body\":{\"input\":[\"a\"],\"model\":\"voyage-3.5\"}}");
|
|
check(paid.status == 200 && contains(paid.body, "\"dry_run\":true") && contains(paid.body, "/v1/embeddings"), "paid call is a dry run");
|
|
|
|
// 503: free reads and confirmed calls need the credential
|
|
for (const char* body : {"{\"provider\":\"qdrant\",\"call\":\"get_collections\"}",
|
|
"{\"provider\":\"weaviate\",\"call\":\"schema_dump\"}",
|
|
"{\"provider\":\"pinecone\",\"call\":\"list_indexes\"}",
|
|
"{\"provider\":\"mixedbread\",\"call\":\"list_stores\"}",
|
|
"{\"provider\":\"jina\",\"call\":\"list_models\"}",
|
|
"{\"provider\":\"tavily\",\"call\":\"get_usage\"}",
|
|
"{\"provider\":\"pinecone\",\"call\":\"describe_index_stats\",\"index_host\":\"docs-abc.svc.pinecone.io\",\"body\":{}}",
|
|
"{\"provider\":\"qdrant\",\"call\":\"delete_collection\",\"path\":{\"collection_name\":\"docs\"},\"confirm\":true}",
|
|
"{\"provider\":\"pinecone\",\"call\":\"delete_index\",\"path\":{\"index_name\":\"docs\"},\"confirm\":true}",
|
|
"{\"provider\":\"voyage\",\"call\":\"rerank\",\"body\":{\"query\":\"q\",\"documents\":[\"a\"],\"model\":\"rerank-2.5\"},\"confirm\":true}"}) {
|
|
auto res = post(body);
|
|
check(res.status == 503 && contains(res.body, "retrieval_not_configured"), std::string("503 without a credential: ") + body);
|
|
}
|
|
return finish("ai/retrieval/call");
|
|
}
|