Skip to content

Commit

Permalink
chore: fixing readme and error handler for json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gotochkin committed Sep 26, 2024
1 parent 00c5e11 commit 7cb37c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
21 changes: 19 additions & 2 deletions infrastructure/cymbal-store-embeddings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,38 @@ 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=./ \
--no-allow-unauthenticated \
--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
Expand Down
21 changes: 13 additions & 8 deletions infrastructure/cymbal-store-embeddings/cymbal_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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"]))
Expand Down

0 comments on commit 7cb37c2

Please sign in to comment.