|
2 | 2 | from ai.providers import get_available_providers |
3 | 3 | from slack_sdk import WebClient |
4 | 4 | from state_store.get_redis_user_state import get_redis_user_state |
| 5 | +from state_store.set_redis_user_state import set_redis_user_state |
5 | 6 | import sys |
| 7 | +import os |
6 | 8 |
|
7 | 9 | """ |
8 | 10 | Callback for handling the 'app_home_opened' event. It checks if the event is for the 'home' tab, |
@@ -39,13 +41,27 @@ def app_home_opened_callback(event: dict, logger: Logger, client: WebClient): |
39 | 41 | print(f"⚠️ No matching option found for model '{model}', using default") |
40 | 42 | else: |
41 | 43 | print(f"ℹ️ No provider selection found for user: {user_id}") |
42 | | - # add an empty option if the user has no previously selected model. |
43 | | - options.append( |
44 | | - { |
45 | | - "text": {"type": "plain_text", "text": "Select a provider", "emoji": True}, |
46 | | - "value": "null", |
47 | | - } |
48 | | - ) |
| 44 | + # Check if GENAI_API_URL is set and genai-agent is available |
| 45 | + genai_api_url = os.environ.get("GENAI_API_URL") |
| 46 | + if genai_api_url and any(opt["value"].startswith("genai-agent") for opt in options): |
| 47 | + print(f"🔄 Using genai-agent as default model for user: {user_id}") |
| 48 | + initial_option = list(filter(lambda x: x["value"].startswith("genai-agent"), options)) |
| 49 | + if initial_option: |
| 50 | + # Save the default selection to Redis |
| 51 | + try: |
| 52 | + set_redis_user_state(user_id, "genai", "genai-agent") |
| 53 | + print(f"✅ Saved default GenAI selection to Redis for user: {user_id}") |
| 54 | + except Exception as e: |
| 55 | + print(f"❌ Error saving default GenAI selection: {e}", file=sys.stderr) |
| 56 | + logger.error(f"Error saving default GenAI selection: {e}") |
| 57 | + else: |
| 58 | + # add an empty option if the user has no previously selected model. |
| 59 | + options.append( |
| 60 | + { |
| 61 | + "text": {"type": "plain_text", "text": "Select a provider", "emoji": True}, |
| 62 | + "value": "null", |
| 63 | + } |
| 64 | + ) |
49 | 65 |
|
50 | 66 | try: |
51 | 67 | client.views_publish( |
|
0 commit comments