Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructured code. #1066

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions kairon/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 0 additions & 66 deletions tests/unit_test/llm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading