From 18883c42275aba4807dc6312d075bf287b596511 Mon Sep 17 00:00:00 2001 From: Gleb Otochkin Date: Thu, 26 Sep 2024 09:55:20 -0400 Subject: [PATCH] chore: fixing readme and error handler for json parsing (#255) --- .../cymbal-store-embeddings/README.md | 21 +++++++++++++++++-- .../cymbal-store-embeddings/cymbal_store.py | 21 ++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/infrastructure/cymbal-store-embeddings/README.md b/infrastructure/cymbal-store-embeddings/README.md index 0d6acf4..a5a1eb0 100644 --- a/infrastructure/cymbal-store-embeddings/README.md +++ b/infrastructure/cymbal-store-embeddings/README.md @@ -90,6 +90,9 @@ gunicorn --bind :8080 --reload --workers 1 --threads 8 --timeout 0 cymbal_store: ``` ### Deploy the applicaion to Cloud Run +Create a service account cymbal-store-identity and grant role VertexAI User to the account - optional now since we are not using Vertex AI as of now. +Build and deploy application to the Cloud Run service. + ``` gcloud alpha run deploy cymbal-store \ --source=./ \ @@ -97,14 +100,28 @@ gcloud alpha run deploy cymbal-store \ --service-account cymbal-store-identity \ --region us-central1 \ --network=default \ + --set-env-vars=DB_USER=cymbaldb_owner,DB_PASS=StrongPassword,DB_NAME=cymbaldb,INSTANCE_HOST=127.0.0.1,DB_PORT=5432 \ --quiet ``` - -* Requests to Try +### Use the application +#### Choose the model +- Click "Model" on the bottom of the application and new dialog window will be opened +- Provide your Google AI API token +- Switch focus to models and click checkbox for Gemeini 1.5 flash model +- Click "Confirm" + +#### Ask questions +- Ask questions in the chat +- Please report all the issues with the application +- Requests to Try - Choose model using button in the chat and providing your Google AI token and choosing the Gemini model (Open AI is not supported yet) - Confirm the choice of the model - Ask in the chat - "What kind of fruit trees grow well here?" +# TO DO +- Add support for other models and providers +- Add error handlers when AI provider returns an error + # License Apache License Version 2.0; Copyright 2024 Google LLC diff --git a/infrastructure/cymbal-store-embeddings/cymbal_store.py b/infrastructure/cymbal-store-embeddings/cymbal_store.py index fc5ad75..8c05a0b 100644 --- a/infrastructure/cymbal-store-embeddings/cymbal_store.py +++ b/infrastructure/cymbal-store-embeddings/cymbal_store.py @@ -335,6 +335,7 @@ def on_input_enter(e: me.InputEnterEvent): yield from send_prompt(e) + with me.box(style=_STYLE_APP_CONTAINER): with me.content_button( type="icon", @@ -419,6 +420,7 @@ def send_prompt(e: me.ClickEvent): state.conversations.append(Conversation(model=model, messages=[])) input = state.input state.input = "" + yield for conversation in state.conversations: model = conversation.model @@ -429,14 +431,17 @@ def send_prompt(e: me.ClickEvent): yield if model == Models.GEMINI_1_5_FLASH.value: - intent_str = gemini_model.classify_intent(input) - print(intent_str) - logging.info(f"PRODUCTS LIST: {intent_str}") - try: - json_intent = json.loads(intent_str) - except json.JSONDecodeError as e: - print(f"Error decoding JSON: {e}") - json_intent = json.loads(intent_str) + while True: + intent_str = gemini_model.classify_intent(input) + print(intent_str) + logging.info(f"PRODUCTS LIST: {intent_str}") + try: + json_intent = json.loads(intent_str) + except json.JSONDecodeError as e: + print(f"Error decoding JSON: {e}") + continue + break + if json_intent["shouldRecommendProduct"] is True: search_embedding = gemini_model.generate_embedding(json_intent["summary"]) products_list = get_products(db, str(search_embedding["embedding"]))