Skip to content

Commit

Permalink
add predict proxy virtual service (#1628)
Browse files Browse the repository at this point in the history
* add predict proxy virtual service

* Add e2e for predict proxy endpoint

* simpler check
  • Loading branch information
lferran authored Nov 30, 2023
1 parent 84cebd9 commit 3c0130a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
4 changes: 4 additions & 0 deletions charts/nucliadb_search/templates/search.vs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ spec:
regex: '^/api/v\d+/kb/[^/]+/summarize$'
method:
regex: "POST|OPTIONS"
- uri:
regex: '^/api/v\d+/kb/[^/]+/predict/.*'
method:
regex: "GET|POST|OPTIONS"
- uri:
regex: '^/api/v\d+/kb/[^/]+/resource/[^/]+/(chat|find|search|ask)$'
method:
Expand Down
82 changes: 77 additions & 5 deletions e2e/test_e2e.py
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")

Expand Down Expand Up @@ -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")

1 comment on commit 3c0130a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 3c0130a Previous: 84cebd9 Ratio
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.

Please sign in to comment.