From 570d9375cf12416fbcce518f772493e57cf78f10 Mon Sep 17 00:00:00 2001 From: Nupur Khare Date: Wed, 25 Oct 2023 17:23:27 +0530 Subject: [PATCH] Restructured code. --- kairon/api/models.py | 17 ---------- tests/unit_test/llm_test.py | 66 ------------------------------------- 2 files changed, 83 deletions(-) diff --git a/kairon/api/models.py b/kairon/api/models.py index db34906e3..56ce81241 100644 --- a/kairon/api/models.py +++ b/kairon/api/models.py @@ -364,23 +364,6 @@ def validate_request_method(cls, v, values, **kwargs): return v.upper() -class QueryConfig(BaseModel): - type: DbQueryValueType - value: DbActionOperationType - - @root_validator - def check(cls, values): - from kairon.shared.utils import Utility - - if Utility.check_empty_string(values.get('type')): - raise ValueError("type cannot be empty") - - if Utility.check_empty_string(values.get('value')): - raise ValueError("value cannot be empty") - - return values - - class PayloadConfig(BaseModel): type: DbQueryValueType value: Any diff --git a/tests/unit_test/llm_test.py b/tests/unit_test/llm_test.py index 6ffae2dad..f9f5b717d 100644 --- a/tests/unit_test/llm_test.py +++ b/tests/unit_test/llm_test.py @@ -369,72 +369,6 @@ async def test_gpt3_faq_embedding_train_int(self, aioresponses): 'payload': expected_payload }]} - # @pytest.mark.asyncio - # async def test_gpt3_faq_embedding_train_payload_json_no_metadata(self, aioresponses): - # bot = "test_embed_faq_json_no_metadata" - # user = "test" - # value = "nupurkhare" - # CognitionSchema( - # metadata=[], - # bot=bot, user=user).save() - # test_content = CognitionData( - # data={"name": "Nupur", "age": 25, "city": "Bengaluru"}, - # content_type="json", - # bot=bot, user=user).save() - # secret = BotSecrets(secret_type=BotSecretType.gpt_key.value, value=value, bot=bot, user=user).save() - # - # embedding = list(np.random.random(GPT3FAQEmbedding.__embedding__)) - # request_header = {"Authorization": "Bearer nupurkhare"} - # - # aioresponses.add( - # url="https://api.openai.com/v1/embeddings", - # method="POST", - # status=200, - # payload={'data': [{'embedding': embedding}]} - # ) - # - # with mock.patch.dict(Utility.environment, {'llm': {"faq": "GPT3_FAQ_EMBED", 'api_key': secret}}): - # gpt3 = GPT3FAQEmbedding(test_content.bot, LLMSettings(provider="openai").to_mongo().to_dict()) - # - # aioresponses.add( - # url=urljoin(Utility.environment['vector']['db'], f"/collections"), - # method="GET", - # payload={"time": 0, "status": "ok", "result": {"collections": []}}) - # - # - # aioresponses.add( - # method="DELETE", - # url=urljoin(Utility.environment['vector']['db'], f"/collections/{gpt3.bot}{gpt3.suffix}"), - # ) - # - # aioresponses.add( - # url=urljoin(Utility.environment['vector']['db'], f"/collections/{gpt3.bot}{gpt3.suffix}"), - # method="PUT", - # status=200 - # ) - # - # aioresponses.add( - # url=urljoin(Utility.environment['vector']['db'], f"/collections/{gpt3.bot}{gpt3.suffix}/points"), - # method="PUT", - # payload={"result": {"operation_id": 0, "status": "acknowledged"}, "status": "ok", "time": 0.003612634} - # ) - # - # response = await gpt3.train() - # assert response['faq'] == 1 - # - # assert list(aioresponses.requests.values())[1][0].kwargs['json'] == {'name': gpt3.bot + gpt3.suffix, - # 'vectors': gpt3.vector_config} - # assert list(aioresponses.requests.values())[2][0].kwargs['json'] == {"model": "text-embedding-ada-002", - # "input": json.dumps(test_content.data)} - # assert list(aioresponses.requests.values())[2][0].kwargs['headers'] == request_header - # expected_payload = test_content.data - # expected_payload['collection_name'] = f"{gpt3.bot}{gpt3.suffix}" - # assert list(aioresponses.requests.values())[3][0].kwargs['json'] == { - # 'points': [{'id': test_content.vector_id, - # 'vector': embedding, - # 'payload': expected_payload - # }]} - def test_gpt3_faq_embedding_train_failure(self): with pytest.raises(AppException, match=f"Bot secret '{BotSecretType.gpt_key.value}' not configured!"): GPT3FAQEmbedding('test_failure', LLMSettings(provider="openai").to_mongo().to_dict())