-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add predict proxy virtual service (#1628)
* add predict proxy virtual service * Add e2e for predict proxy endpoint * simpler check
- Loading branch information
Showing
2 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import pytest | ||
import requests | ||
import base64 | ||
import io | ||
import json | ||
import os | ||
import random | ||
import time | ||
import io | ||
import json | ||
import base64 | ||
|
||
import pytest | ||
import requests | ||
|
||
BASE_URL = os.environ.get("NUCLIADB_URL", "http://localhost:8080") | ||
|
||
|
@@ -149,3 +150,74 @@ def test_search(kbid: str, resource_id: str): | |
|
||
assert "Not enough data to answer this" not in chat_response | ||
assert len(search_results["resources"]) == 1 | ||
|
||
|
||
def test_predict_proxy(kbid: str): | ||
_test_predict_proxy_chat(kbid) | ||
_test_predict_proxy_tokens(kbid) | ||
_test_predict_proxy_rephrase(kbid) | ||
|
||
|
||
def _test_predict_proxy_chat(kbid: str): | ||
resp = requests.post( | ||
os.path.join(BASE_URL, f"api/v1/kb/{kbid}/predict/chat"), | ||
headers={ | ||
"content-type": "application/json", | ||
"X-NUCLIADB-ROLES": "READER", | ||
"x-ndb-client": "web", | ||
}, | ||
json={ | ||
"question": "Who is the best one?", | ||
"query_context": [ | ||
"Many football players have existed. Cristiano Ronaldo and Messi among them, but Messi is by far the greatest." | ||
], | ||
"user_id": "[email protected]", | ||
}, | ||
) | ||
resp.raise_for_status() | ||
data = io.BytesIO(resp.content) | ||
answer = data.read().decode("utf-8") | ||
assert "Messi" in answer | ||
|
||
|
||
def _test_predict_proxy_tokens(kbid: str): | ||
resp = requests.get( | ||
os.path.join(BASE_URL, f"api/v1/kb/{kbid}/predict/tokens"), | ||
headers={ | ||
"content-type": "application/json", | ||
"X-NUCLIADB-ROLES": "READER", | ||
"x-ndb-client": "web", | ||
}, | ||
params={ | ||
"text": "Barcelona", | ||
}, | ||
) | ||
resp.raise_for_status() | ||
data = resp.json() | ||
assert data["tokens"][0]["text"] == "Barcelona" | ||
|
||
|
||
def _test_predict_proxy_rephrase(kbid: str): | ||
resp = requests.post( | ||
os.path.join(BASE_URL, f"api/v1/kb/{kbid}/predict/rephrase"), | ||
headers={ | ||
"content-type": "application/json", | ||
"X-NUCLIADB-ROLES": "READER", | ||
"x-ndb-client": "web", | ||
}, | ||
json={ | ||
"question": "Who is the best one?", | ||
"context": [ | ||
{ | ||
"author": "NUCLIA", | ||
"text": "Many football players have existed. Cristiano Ronaldo and Messi among them.", | ||
}, | ||
{"author": "USER", "text": "Tell me some football players"}, | ||
], | ||
"user_id": "[email protected]", | ||
}, | ||
) | ||
resp.raise_for_status() | ||
rephrased_query = resp.json() | ||
# Status code 0 means success... | ||
assert rephrased_query.endswith("0") |
3c0130a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
nucliadb/search/tests/unit/search/test_fetch.py::test_highligh_error
12943.701279146402
iter/sec (stddev: 7.755443114231847e-7
)12982.011001408568
iter/sec (stddev: 3.088010895258411e-7
)1.00
This comment was automatically generated by workflow using github-action-benchmark.