Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
pr fixes, exception separation and retry for free tier
Browse files Browse the repository at this point in the history
  • Loading branch information
miararoy committed Oct 1, 2023
1 parent f5b2cc1 commit 0f0931c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 8 additions & 1 deletion resin_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ def is_healthy(url: str):
def validate_connection():
try:
KnowledgeBase._connect_pinecone()
except Exception:
msg = (
"Failed to connect to Pinecone index, please make sure"
+ " you have set the right env vars"
)
click.echo(click.style(msg, fg="red"), err=True)
sys.exit(1)
openai.Model.list()
except Exception:
msg = (
"Failed to connect to Pinecone index and OpenAI API, please make sure"
"Failed to connect to OpenAI, please make sure"
+ " you have set the right env vars"
)
click.echo(click.style(msg, fg="red"), err=True)
Expand Down
20 changes: 13 additions & 7 deletions tests/e2e/test_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from fastapi.testclient import TestClient
from tenacity import retry, stop_after_attempt, wait_fixed

from resin.knoweldge_base import KnowledgeBase
from resin.knoweldge_base.tokenizer import OpenAITokenizer, Tokenizer
Expand Down Expand Up @@ -64,13 +65,18 @@ def test_e2e():

# test response is as expected on /query
response_as_json = query_response.json()
assert (
response_as_json[0]["query"] == query_payload.dict()["queries"][0]["text"]
)
assert (
response_as_json[0]["snippets"][0]["text"]
== upsert_payload.dict()["documents"][0]["text"]
)

@retry(stop=stop_after_attempt(60), wait=wait_fixed(1))
def test_response_is_expected(response_as_json):
(
response_as_json[0]["query"]
== query_payload.dict()["queries"][0]["text"]
and response_as_json[0]["snippets"][0]["text"]
== upsert_payload.dict()["documents"][0]["text"]
)

assert test_response_is_expected(response_as_json)

# TODO: uncomment when fix is pushed
# assert response_as_json[0]["snippets"][0]["source"] == \
# upsert_payload.dict()["documents"][0]["source"]
Expand Down

0 comments on commit 0f0931c

Please sign in to comment.