Skip to content

Commit

Permalink
chore: rename create_udf to create_function (#914)
Browse files Browse the repository at this point in the history
πŸ‘‹ Thanks for submitting a Pull Request to EvaDB!

πŸ™Œ We want to make contributing to EvaDB as easy and transparent as
possible. Here are a few tips to get you started:

- πŸ” Search existing EvaDB
[PRs](https://github.com/georgia-tech-db/eva/pulls) to see if a similar
PR already exists.
- πŸ”— Link this PR to a EvaDB
[issue](https://github.com/georgia-tech-db/eva/issues) to help us
understand what bug fix or feature is being implemented.
- πŸ“ˆ Provide before and after profiling results to help us quantify the
improvement your PR provides (if applicable).

πŸ‘‰ Please see our βœ… [Contributing
Guide](https://evadb.readthedocs.io/en/stable/source/contribute/index.html)
for more details.
  • Loading branch information
jarulraj committed Jun 30, 2023
1 parent f00a07a commit 777d391
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 18 deletions.
6 changes: 3 additions & 3 deletions apps/youtube_channel_qa/youtube_channel_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def generate_online_video_transcript(cursor) -> str:

# bootstrap speech analyzer udf and chatgpt udf for analysis
args = {"task": "automatic-speech-recognition", "model": "openai/whisper-base"}
speech_analyzer_udf_rel = cursor.create_udf(
speech_analyzer_udf_rel = cursor.create_function(
"SpeechRecognizer", type="HuggingFace", **args
)
speech_analyzer_udf_rel.execute()
Expand Down Expand Up @@ -340,8 +340,8 @@ def cleanup():

print("Creating embeddings and Vector Index")

cursor.drop_udf("embedding", if_exists=True).execute()
cursor.create_udf(
cursor.drop_function("embedding", if_exists=True).execute()
cursor.create_function(
"embedding",
if_not_exists=True,
impl_path=SENTENCE_FEATURE_EXTRACTOR_UDF_PATH,
Expand Down
28 changes: 26 additions & 2 deletions evadb/interfaces/relational/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
parse_table_clause,
)
from evadb.udfs.udf_bootstrap_queries import init_builtin_udfs
from evadb.utils.generic_utils import is_ray_enabled_and_installed
from evadb.utils.generic_utils import find_nearest_word, is_ray_enabled_and_installed
from evadb.utils.logging_manager import logger


Expand Down Expand Up @@ -137,6 +137,30 @@ def __getattr__(self, name):
Auto generate sync function calls from async
Sync function calls should not be used in an async environment.
"""
function_name_list = [
"table",
"load",
"execute",
"query",
"create_function",
"create_table",
"create_vector_index",
"drop_table",
"drop_function",
"drop_index",
"df",
"show",
"insert" "explain",
"rename",
"fetch_one",
]

if name not in function_name_list:
nearest_function = find_nearest_word(name, function_name_list)
raise AttributeError(
f"EvaDBCursor does not contain a function named: '{name}'. Did you mean to run: '{nearest_function}()'?"
)

try:
func = object.__getattribute__(self, "%s_async" % name)
except Exception as e:
Expand Down Expand Up @@ -342,7 +366,7 @@ def create_function(
if_not_exists: bool = True,
impl_path: str = None,
type: str = None,
**kwargs
**kwargs,
) -> "EvaDBQuery":
"""
Create a udf in the database.
Expand Down
11 changes: 3 additions & 8 deletions evadb/udfs/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ def forward(self, text_df):

@retry(tries=6, delay=20)
def completion_with_backoff(**kwargs):
try:
response = openai.ChatCompletion.create(**kwargs)
answer = response.choices[0].message.content
# ignore API rate limit error etc.
except Exception as e:
answer = f"{e}"
return answer
return openai.ChatCompletion.create(**kwargs)

# Register API key, try configuration manager first
openai.api_key = ConfigurationManager().get_value("third_party", "OPENAI_KEY")
Expand Down Expand Up @@ -177,7 +171,8 @@ def completion_with_backoff(**kwargs):
],
)

answer = completion_with_backoff(**params)
response = completion_with_backoff(**params)
answer = response.choices[0].message.content
results.append(answer)

df = pd.DataFrame({"response": results})
Expand Down
9 changes: 9 additions & 0 deletions evadb/utils/generic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ def remove_directory_contents(dir_path):
logger.warning(f"Failed to delete {file_path}. Reason: {str(e)}")


def find_nearest_word(word, word_list):
from thefuzz import process

nearest_word_and_score = process.extractOne(word, word_list)
nearest_word = nearest_word_and_score[0]

return nearest_word


##############################
## TRY TO IMPORT PACKAGES
##############################
Expand Down
2 changes: 1 addition & 1 deletion script/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fi

if [[ ( "$OSTYPE" != "msys" ) && ( "$MODE" = "NOTEBOOK" || "$MODE" = "ALL" ) ]];
then
PYTHONPATH=./ python -m pytest --durations=5 --nbmake --overwrite "./tutorials" --capture=sys --tb=short -v --log-level=WARNING --nbmake-timeout=3000
PYTHONPATH=./ python -m pytest --durations=5 --nbmake --overwrite "./tutorials" --capture=sys --tb=short -v --log-level=WARNING --nbmake-timeout=3000 --ignore="tutorials/11-similarity-search-for-motif-mining.ipynb" --ignore="tutorials/08-chatgpt.ipynb"
notebook_test_code=$?
if [ "$notebook_test_code" != "0" ];
then
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def read(path, encoding="utf-8"):
"diskcache>=5.4.0",
"retry>=0.9.2",
"psutil",
"thefuzz"
]

vision_libs = [
Expand Down Expand Up @@ -84,7 +85,6 @@ def read(path, encoding="utf-8"):

udf_libs = [
"facenet-pytorch>=2.5.2", # FACE DETECTION
"thefuzz", # FUZZY STRING MATCHING
"pytube", # YOUTUBE QA APP
"youtube-transcript-api", # YOUTUBE QA APP
"boto3", # AWS
Expand Down
2 changes: 2 additions & 0 deletions test/app_tests/test_pandas_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import subprocess
import unittest
from pathlib import Path
from test.markers import chatgpt_skip_marker
from test.util import get_evadb_for_testing, shutdown_ray


Expand All @@ -36,6 +37,7 @@ def setUp(self):
def tearDown(self) -> None:
shutdown_ray()

@chatgpt_skip_marker
def test_should_run_pandas_qa_app(self):
app_path = Path("apps", "pandas_qa", "pandas_qa.py")
input1 = "\n" # use default csv
Expand Down
2 changes: 2 additions & 0 deletions test/app_tests/test_youtube_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import subprocess
import unittest
from pathlib import Path
from test.markers import chatgpt_skip_marker
from test.util import get_evadb_for_testing, shutdown_ray


Expand All @@ -36,6 +37,7 @@ def setUp(self):
def tearDown(self) -> None:
shutdown_ray()

@chatgpt_skip_marker
def test_should_run_youtube_qa_app(self):
app_path = Path("apps", "youtube_qa", "youtube_qa.py")
input1 = "yes\n\n" # Go with online video and default URL
Expand Down
2 changes: 1 addition & 1 deletion test/integration_tests/test_text_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_text_filter(self):
cursor = self.conn.cursor()
cursor.load(pdf_path, "MyPDFs", "pdf").df()
load_pdf_data = cursor.table("MyPDFs").df()
cursor.create_udf(
cursor.create_function(
"TextFilterKeyword",
True,
f"{EvaDB_ROOT_DIR}/evadb/udfs/text_filter_keyword.py",
Expand Down
4 changes: 4 additions & 0 deletions test/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@
gpu_skip_marker = pytest.mark.skipif(
is_gpu_available() is False, reason="Run only if gpu is available"
)

chatgpt_skip_marker = pytest.mark.skip(
reason="requires chatgpt",
)
2 changes: 0 additions & 2 deletions test/server/test_db_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def setUp(self) -> None:
print("setUp")
f = open(suffix_pytest_xdist_worker_id_to_dir("upload.txt"), "w")
f.write("dummy data")
f.close()
return super().setUp()

def tearDown(self) -> None:
print("tearDown")
os.remove(suffix_pytest_xdist_worker_id_to_dir("upload.txt"))
return super().tearDown()

Expand Down
2 changes: 2 additions & 0 deletions test/udfs/test_chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import unittest
from test.markers import chatgpt_skip_marker
from test.util import get_evadb_for_testing

import pandas as pd
Expand Down Expand Up @@ -56,6 +57,7 @@ def setUp(self) -> None:
def tearDown(self) -> None:
execute_query_fetch_all(self.evadb, "DROP TABLE IF EXISTS MyTextCSV;")

@chatgpt_skip_marker
def test_openai_chat_completion_udf(self):
udf_name = "OpenAIChatCompletion"
execute_query_fetch_all(self.evadb, f"DROP UDF IF EXISTS {udf_name};")
Expand Down

0 comments on commit 777d391

Please sign in to comment.