From 57fd5d22b63f2fd7ffe10cbe3b2db9b51286370d Mon Sep 17 00:00:00 2001 From: FlorentLvr Date: Thu, 25 Apr 2024 17:29:44 +0200 Subject: [PATCH] feat: send plugin to multiples workspaces --- __pipeline__.ipynb | 17 ++-- models/content-engine/__plugin__.ipynb | 11 ++- models/finance-engine/__plugin__.ipynb | 16 ++-- models/growth-engine/__plugin__.ipynb | 11 ++- models/opendata-engine/__plugin__.ipynb | 16 ++-- models/operations-engine/__plugin__.ipynb | 16 ++-- models/sales-engine/__plugin__.ipynb | 20 ++-- utils/naas_chat_plugin.ipynb | 112 +++++++++++++--------- 8 files changed, 131 insertions(+), 88 deletions(-) diff --git a/__pipeline__.ipynb b/__pipeline__.ipynb index 3476bb3..bd4f767 100644 --- a/__pipeline__.ipynb +++ b/__pipeline__.ipynb @@ -192,13 +192,14 @@ " print(\"- Entity:\", entity_name)\n", " print(\"- Emails:\", emails)\n", " print(\"- LinkedIn URL:\", linkedin_url)\n", - " print(\"- LinkedIn li_at:\", li_at)\n", - " print(\"- LinkedIn JSESSIONID:\", JSESSIONID)\n", " entity_code = unidecode(row.ENTITY.lower().replace(\" \", \"_\").replace(\".\", \"\"))\n", " entity_dir = os.path.join(datalake_dir, entity_code)\n", " os.makedirs(entity_dir, exist_ok=True) # Create dirs\n", " os.makedirs(os.path.join(entity_dir, \"plugins\"), exist_ok=True) # Create dirs\n", " print(\"- Directory:\", entity_dir)\n", + " if \"WORKSPACE_IDS\" in df_gsheet.columns and row.WORKSPACE_IDS != \"NA\":\n", + " workspace_ids = row.WORKSPACE_IDS.split(\",\")\n", + " print(\"- Workspace IDs:\", workspace_ids)\n", " print()\n", " \n", " # Save entity data\n", @@ -214,7 +215,9 @@ " naas.dependency.add(os.path.join(output_dir, \"linkedin_url.pickle\"))\n", " pdump(output_dir, entity_dir, \"entity_dir\")\n", " naas.dependency.add(os.path.join(output_dir, \"entity_dir.pickle\"))\n", - " \n", + " pdump(output_dir, workspace_ids, \"workspace_ids\")\n", + " naas.dependency.add(os.path.join(output_dir, \"workspace_ids.pickle\"))\n", + "\n", " # Save secrets\n", " for x in [\"LINKEDIN_LI_AT\", \"LINKEDIN_JSESSIONID\"]:\n", " value = df_gsheet.loc[index, x]\n", @@ -226,7 +229,9 @@ " if li_at == \"NA\":\n", " li_at = naas.secret.get(\"li_at\")\n", " if JSESSIONID == \"NA\":\n", - " JSESSIONID = naas.secret.get(\"JSESSIONID\")\n", + " JSESSIONID = naas.secret.get(\"JSESSIONID\").replace('\"', '')\n", + " print(\"- LinkedIn li_at:\", li_at)\n", + " print(\"- LinkedIn JSESSIONID:\", JSESSIONID)\n", " \n", " # Set timezone: Timezone will be defined from the first profile region's and country's\n", " if index == 0:\n", @@ -287,8 +292,6 @@ " \"entity_name\": entity_name,\n", " \"emails\": emails,\n", " \"linkedin_url\": linkedin_url,\n", - " \"li_at\": li_at,\n", - " \"JSESSIONID\": JSESSIONID,\n", " \"entity_dir\": entity_dir\n", " }\n", " )\n", @@ -357,7 +360,7 @@ "outputs": [], "source": [ "# Schedule pipeline\n", - "cron = \"0 12 * * *\"\n", + "cron = \"0 8 * * *\"\n", "print(\"⏰ Scheduler:\", cron)\n", "naas.scheduler.add(cron=cron)\n", "# naas.scheduler.delete()" diff --git a/models/content-engine/__plugin__.ipynb b/models/content-engine/__plugin__.ipynb index 475e852..f73da54 100644 --- a/models/content-engine/__plugin__.ipynb +++ b/models/content-engine/__plugin__.ipynb @@ -117,6 +117,9 @@ "- `description`: Plugin description.\n", "- `avatar`: Plugin avatar image.\n", "- `model_dir`: Models directory.\n", + "- `api_key`: Naas API Key.\n", + "- `workspace_ids`: Workspace IDs to push the plugin in.\n", + "- `personal_workspace`: Plugin sent to personal workspace.\n", "\n", "**Outputs**\n", "- `output_dir`: Output directory where output files are stored. \n", @@ -149,6 +152,8 @@ "avatar = \"https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/content_creation.png\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"content-engine\")\n", "api_key = naas.secret.get('NAAS_API_TOKEN')\n", + "workspace_ids = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"workspace_ids\") or \"\"\n", + "personal_workspace = True\n", "\n", "# Outputs\n", "output_dir = os.path.join(entity_dir, \"plugins\")\n", @@ -281,14 +286,12 @@ }, "outputs": [], "source": [ - "system_prompt = f\"\"\"\n", - "Act as a Content Assistant who has access to valuable data and insights about the content strategy. \n", + "system_prompt = f\"\"\"Act as a Content Assistant who has access to valuable data and insights about the content strategy. \n", "Your role is to manage and optimize the content, ensuring it reaches the target audience effectively. \n", "The last 2 weeks '{TW}' & '{LW}' the '{entity_name}' published {len(df)} contents and generated and {kpi} {kpi_label}. \n", "Here is the list with the post published: {prompt_data}.\n", "The first message should be about presenting yourself and analyze '{entity_name}' contents published based on best post/topics by {kpi_label}, by date and time with a maximum of 3 bullet points.\n", "Then, you will display the image inside the markdown of the chat about the evolution of content {kpi_label} over the last 2 weeks: ![Content KPI]({image_url}).\n", - "You must ALWAYS show the image in the first message.\n", "Be casual, but professional. Wait for the first answer from the user, and then start with the first high-level analysis. \n", "\"\"\"" ] @@ -347,7 +350,7 @@ "\n", "# Push plugin to Personal workspace\n", "print(\"--> Push plugin to Personal workspace\")\n", - "push_plugin_to_workspace(api_key, plugin)\n", + "push_plugin_to_workspace(api_key, plugin, workspace_ids, personal_workspace)\n", "print()\n", "\n", "# Create new chat\n", diff --git a/models/finance-engine/__plugin__.ipynb b/models/finance-engine/__plugin__.ipynb index 4ba8def..bfa40d6 100644 --- a/models/finance-engine/__plugin__.ipynb +++ b/models/finance-engine/__plugin__.ipynb @@ -111,6 +111,9 @@ "- `description`: This variable holds a string that describes the plugin.\n", "- `avatar`: This variable holds a URL to an image to be displayed in your plugin as avatar.\n", "- `model_dir`: This variable holds a relative path to the directory where input notebooks with commands will be stored.\n", + "- `api_key`: Naas API Key.\n", + "- `workspace_ids`: Workspace IDs to push the plugin in.\n", + "- `personal_workspace`: Plugin sent to personal workspace.\n", "\n", "**Outputs**\n", "- `output_dir`: This variable holds a relative path to the directory where output files will be stored. \n", @@ -130,8 +133,8 @@ "outputs": [], "source": [ "# Inputs\n", - "entity_id = \"0\"\n", - "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_dir\")\n", + "entity_index = \"0\"\n", + "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_dir\")\n", "name = \"Finance Assistant\"\n", "model = \"gpt-3.5-turbo-16k\"\n", "temperature = 0\n", @@ -139,10 +142,12 @@ "avatar = \"https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/finance_management.png\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"finance-engine\")\n", "api_key = naas.secret.get('NAAS_API_TOKEN')\n", + "workspace_ids = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"workspace_ids\") or \"\"\n", + "personal_workspace = True\n", "\n", "# Outputs\n", "output_dir = os.path.join(entity_dir, \"plugins\")\n", - "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_name\") or \"\"" + "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_name\") or \"\"" ] }, { @@ -173,8 +178,7 @@ }, "outputs": [], "source": [ - "system_prompt = f\"\"\"\n", - "Act as a Financial Assistant with access to comprehensive financial data sources. \n", + "system_prompt = f\"\"\"Act as a Financial Assistant with access to comprehensive financial data sources. \n", "Your primary objective is to analyze and optimize financial transactions, ensuring you identify key insights and trends to guide financial strategies. \n", "Leverage the data to decipher patterns, customer behavior, and payment methods to strategize on revenue growth and financial operations.\n", "Your ultimate goal is to maximize revenue, minimize risks, and contribute to the overall financial success of the organization.\n", @@ -236,7 +240,7 @@ "\n", "# Push plugin to Personal workspace\n", "print(\"--> Push plugin to Personal workspace\")\n", - "push_plugin_to_workspace(api_key, plugin)\n", + "push_plugin_to_workspace(api_key, plugin, workspace_ids, personal_workspace)\n", "print()\n", "\n", "# Create new chat\n", diff --git a/models/growth-engine/__plugin__.ipynb b/models/growth-engine/__plugin__.ipynb index e011bd7..bb95586 100644 --- a/models/growth-engine/__plugin__.ipynb +++ b/models/growth-engine/__plugin__.ipynb @@ -118,6 +118,9 @@ "- `description`: Plugin description.\n", "- `avatar`: Plugin avatar image.\n", "- `model_dir`: Models directory.\n", + "- `api_key`: Naas API Key.\n", + "- `workspace_ids`: Workspace IDs to push the plugin in.\n", + "- `personal_workspace`: Plugin sent to personal workspace.\n", "\n", "**Outputs**\n", "- `output_dir`: Output directory where output files are stored. \n", @@ -150,6 +153,8 @@ "avatar = \"https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/growth_marketing.png\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"growth-engine\")\n", "api_key = naas.secret.get('NAAS_API_TOKEN')\n", + "workspace_ids = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"workspace_ids\") or \"\"\n", + "personal_workspace = True\n", "\n", "# Outputs\n", "output_dir = os.path.join(entity_dir, \"plugins\")\n", @@ -321,15 +326,13 @@ }, "outputs": [], "source": [ - "system_prompt = f\"\"\"\n", - "Act as a Growth assistant who has access to a list of interactions from content that enable the user to get marketing qualified contacts.\n", + "system_prompt = f\"\"\"Act as a Growth assistant who has access to a list of interactions from content that enable the user to get marketing qualified contacts.\n", "Your role is to manage and optimize the list of people who interacted on the content, ensuring to extract only the most qualified contacts to feed the sales representative.\n", "The last 2 weeks '{TW}' & '{LW}' the '{entity_name}' generated {total_leads} new leads ({new_leads} on {TW}) by the following posts published: {post_data}. \n", "Here is the list of leads with the highest interaction score: {df.to_string()}.\n", "Please remember the user that you don't have access to all the list due to the limit of the context window.\n", "The first message should be about presenting yourself and analyze briefly '{entity_name}' new interactions with a maximum of 3 bullet points.\n", "Then, you will display the image inside the markdown of the chat about the contacts reached over the weeks: ![Contacts Reached]({image_url}).\n", - "You must ALWAYS show the image in the first message.\n", "Be casual, but professional. Wait for the first answer from the user, and then start with the first high-level analysis. \n", "\"\"\"" ] @@ -388,7 +391,7 @@ "\n", "# Push plugin to Personal workspace\n", "print(\"--> Push plugin to Personal workspace\")\n", - "push_plugin_to_workspace(api_key, plugin)\n", + "push_plugin_to_workspace(api_key, plugin, workspace_ids, personal_workspace)\n", "print()\n", "\n", "# Create new chat\n", diff --git a/models/opendata-engine/__plugin__.ipynb b/models/opendata-engine/__plugin__.ipynb index b49a155..af41851 100644 --- a/models/opendata-engine/__plugin__.ipynb +++ b/models/opendata-engine/__plugin__.ipynb @@ -111,6 +111,9 @@ "- `description`: This variable holds a string that describes the plugin.\n", "- `avatar`: This variable holds a URL to an image to be displayed in your plugin as avatar.\n", "- `model_dir`: This variable holds a relative path to the directory where input notebooks with commands will be stored.\n", + "- `api_key`: Naas API Key.\n", + "- `workspace_ids`: Workspace IDs to push the plugin in.\n", + "- `personal_workspace`: Plugin sent to personal workspace.\n", "\n", "**Outputs**\n", "- `output_dir`: This variable holds a relative path to the directory where output files will be stored. \n", @@ -130,8 +133,8 @@ "outputs": [], "source": [ "# Inputs\n", - "entity_id = \"0\"\n", - "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_dir\")\n", + "entity_index = \"0\"\n", + "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_dir\")\n", "name = \"Open Data Assistant\"\n", "model = \"gpt-4-1106-preview\"\n", "temperature = 0\n", @@ -139,10 +142,12 @@ "avatar = \"https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/open_data_intelligence.png\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"opendata-engine\")\n", "api_key = naas.secret.get('NAAS_API_TOKEN')\n", + "workspace_ids = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"workspace_ids\") or \"\"\n", + "personal_workspace = True\n", "\n", "# Outputs\n", "output_dir = os.path.join(entity_dir, \"plugins\")\n", - "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_name\") or \"\"" + "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_name\") or \"\"" ] }, { @@ -176,8 +181,7 @@ }, "outputs": [], "source": [ - "system_prompt = f\"\"\"\n", - "Act as a Open Data Assitant who has access to a list of indicators from financial, extra-financial data and alternative data.\n", + "system_prompt = f\"\"\"Act as a Open Data Assitant who has access to a list of indicators from financial, extra-financial data and alternative data.\n", "Your role is to help people follow the portfolio of indicators that makes sense for them.\n", "Start by presenting yourself.\n", "\"\"\"" @@ -237,7 +241,7 @@ "\n", "# Push plugin to Personal workspace\n", "print(\"--> Push plugin to Personal workspace\")\n", - "push_plugin_to_workspace(api_key, plugin)\n", + "push_plugin_to_workspace(api_key, plugin, workspace_ids, personal_workspace)\n", "print()\n", "\n", "# Create new chat\n", diff --git a/models/operations-engine/__plugin__.ipynb b/models/operations-engine/__plugin__.ipynb index fe5e4d0..21b21e3 100644 --- a/models/operations-engine/__plugin__.ipynb +++ b/models/operations-engine/__plugin__.ipynb @@ -111,6 +111,9 @@ "- `description`: This variable holds a string that describes the plugin.\n", "- `avatar`: This variable holds a URL to an image to be displayed in your plugin as avatar.\n", "- `model_dir`: This variable holds a relative path to the directory where input notebooks with commands will be stored.\n", + "- `api_key`: Naas API Key.\n", + "- `workspace_ids`: Workspace IDs to push the plugin in.\n", + "- `personal_workspace`: Plugin sent to personal workspace.\n", "\n", "**Outputs**\n", "- `output_dir`: This variable holds a relative path to the directory where output files will be stored. \n", @@ -130,8 +133,8 @@ "outputs": [], "source": [ "# Inputs\n", - "entity_id = \"0\"\n", - "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_dir\")\n", + "entity_index = \"0\"\n", + "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_dir\")\n", "name = \"Operations Assistant\"\n", "model = \"gpt-3.5-turbo-16k\"\n", "temperature = 0\n", @@ -139,10 +142,12 @@ "avatar = \"https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/operations_efficiency.png\"\n", "model_dir = os.path.join(naas_data_product.ROOT_PATH, \"models\", \"operations-engine\")\n", "api_key = naas.secret.get('NAAS_API_TOKEN')\n", + "workspace_ids = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"workspace_ids\") or \"\"\n", + "personal_workspace = True\n", "\n", "# Outputs\n", "output_dir = os.path.join(entity_dir, \"plugins\")\n", - "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_name\") or \"\"" + "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_name\") or \"\"" ] }, { @@ -176,8 +181,7 @@ }, "outputs": [], "source": [ - "system_prompt = f\"\"\"\n", - "Act as an Operations Efficiency Assistant with access to comprehensive data sources, including detailed GitHub contributor activity. \n", + "system_prompt = f\"\"\"Act as an Operations Efficiency Assistant with access to comprehensive data sources, including detailed GitHub contributor activity. \n", "Your primary role is to analyze and optimize the list of contributors, ensuring you identify the most active and influential individuals to guide collaborative strategies. \n", "Leverage the data to decipher patterns, contributions, and engagement levels to strategize on operations and collaborations.\n", "Your ultimate goal is to foster a high-performing and cohesive community, playing a pivotal role in the overall success of the project's development and growth.\n", @@ -239,7 +243,7 @@ "\n", "# Push plugin to Personal workspace\n", "print(\"--> Push plugin to Personal workspace\")\n", - "push_plugin_to_workspace(api_key, plugin)\n", + "push_plugin_to_workspace(api_key, plugin, workspace_ids, personal_workspace)\n", "print()\n", "\n", "# Create new chat\n", diff --git a/models/sales-engine/__plugin__.ipynb b/models/sales-engine/__plugin__.ipynb index e1c5d9f..a0b0119 100644 --- a/models/sales-engine/__plugin__.ipynb +++ b/models/sales-engine/__plugin__.ipynb @@ -117,6 +117,9 @@ "- `description`: Plugin description.\n", "- `avatar`: Plugin avatar image.\n", "- `model_dir`: Models directory.\n", + "- `api_key`: Naas API Key.\n", + "- `workspace_ids`: Workspace IDs to push the plugin in.\n", + "- `personal_workspace`: Plugin sent to personal workspace.\n", "\n", "**Outputs**\n", "- `output_dir`: Output directory where output files are stored. \n", @@ -136,11 +139,11 @@ "outputs": [], "source": [ "# Inputs\n", - "entity_id = \"0\"\n", - "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_dir\")\n", + "entity_index = \"0\"\n", + "entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_dir\")\n", "input_dir = os.path.join(entity_dir, \"sales-engine\", date.today().isoformat())\n", "input_file = \"deals\"\n", - "spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"abi_spreadsheet\")\n", + "spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"abi_spreadsheet\")\n", "sheet_name = \"DEALS\"\n", "name = \"Sales Assistant\"\n", "model = \"gpt-4-1106-preview\"\n", @@ -151,10 +154,12 @@ "input_image = \"deals_trend.png\"\n", "input_html = \"deals_trend.html\"\n", "api_key = naas.secret.get('NAAS_API_TOKEN')\n", + "workspace_ids = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"workspace_ids\") or \"\"\n", + "personal_workspace = True\n", "\n", "# Outputs\n", "output_dir = os.path.join(entity_dir, \"plugins\")\n", - "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_name\")" + "entity_name = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_index), \"entity_name\")" ] }, { @@ -277,13 +282,12 @@ }, "outputs": [], "source": [ - "system_prompt = f\"\"\"\n", - "Act as a Sales Assistant who has access to a list of deals generated thanks to your contents published on social media platform. \n", + "system_prompt = f\"\"\"Act as a Sales Assistant who has access to a list of deals generated thanks to your contents published on social media platform. \n", "Your role is to manage and nurture theses deals, ensuring that they progress through the sales pipeline effectively.\n", "Begin your conversation by introducing yourself and displaying the image: ![Deals Evolution]({image_url}) inside the markdown of the chat that illustrates the evolution of deals over the past two weeks, thanks to the content published by '{entity_name}'. \n", "Next, provide an update on this week's results: \n", "The last 2 weeks '{TW}' & '{LW}', the content from '{entity_name}' has generated {new_deals} new promising deals.\n", - "Proceed with a brief analysis of the new deals made this week '{TW}' starting with the deal name and giving details of the people and organization involved in each deal: {sales_data}.\n", + "Proceed with a brief analysis of the new deals (5 max) made this week '{TW}' starting with the deal name and giving details of the people and organization involved in each deal: {sales_data}.\n", "For the convenience of your sales team, please hyperlink the people fullname and organization name to their respective LinkedIn URL.\n", "While maintaining a casual yet professional tone, ensure to stick to the requested information and avoid adding unnecessary details.\n", "After receiving the user's first response, you can then commence with the first high-level analysis.\n", @@ -344,7 +348,7 @@ "\n", "# Push plugin to Personal workspace\n", "print(\"--> Push plugin to Personal workspace\")\n", - "push_plugin_to_workspace(api_key, plugin)\n", + "push_plugin_to_workspace(api_key, plugin, workspace_ids, personal_workspace)\n", "print()\n", "\n", "# Create new chat\n", diff --git a/utils/naas_chat_plugin.ipynb b/utils/naas_chat_plugin.ipynb index 96f4741..4385669 100644 --- a/utils/naas_chat_plugin.ipynb +++ b/utils/naas_chat_plugin.ipynb @@ -146,7 +146,7 @@ "\n", " # Generate commands (to be develop)\n", " commands.append(command)\n", - " print(json.dumps(commands, indent=4))\n", + "# print(json.dumps(commands, indent=4))\n", " return commands\n", "\n", "# commands = create_command(\"/home/ftp/abi/models\")\n", @@ -226,7 +226,7 @@ " \"id\": f\"{name.lower().replace(' ', '-')}-{entity_id}\",\n", " \"slug\": f\"{name.lower().replace(' ', '-')}/{entity_id}\",\n", " \"url\": plugin_url,\n", - " \"name\": name,\n", + " \"name\": f\"{name} - {entity_name}\",\n", " \"model\": model,\n", " \"temperature\": temperature,\n", " \"max_tokens\": max_tokens,\n", @@ -262,54 +262,72 @@ }, "outputs": [], "source": [ - "def push_plugin_to_workspace(api_key, plugin):\n", - " # Get personal workspace\n", - " workspace_id = None\n", + "def push_plugin_to_workspace(\n", + " api_key,\n", + " plugin,\n", + " workspace_ids=[],\n", + " personal_workspace=True\n", + "):\n", + " # Get workspaces\n", " workspaces = list_workspaces(api_key)\n", - " for workspace in workspaces.get(\"workspaces\"):\n", - " if workspace.get(\"is_personal\"):\n", - " workspace_id = workspace.get(\"id\")\n", - " break\n", - " print(\"Workspaces:\", len(workspaces.get(\"workspaces\")))\n", - " print(\"Personal workspace ID:\", workspace_id)\n", " \n", - " # List existing plugins\n", - " plugins = list_workspace_plugins(\n", - " api_key,\n", - " workspace_id,\n", - " )\n", - " plugin_exist = False\n", - " print(\"Plugins:\", len(plugins.get('workspace_plugins')))\n", - " for i, p in enumerate(plugins.get('workspace_plugins')):\n", - " plugin_id = p.get(\"id\")\n", - " p_json = json.loads(p.get(\"payload\"))\n", - " p_name = p_json.get(\"name\")\n", - " p_slug = p_json.get(\"slug\")\n", - " p_url = p_json.get(\"url\")\n", - " if plugin_url == p_url:\n", - " plugin_exist = True\n", - " print(\"Plugin ID:\", plugin_id)\n", - " print(\"- Slug:\", p_slug)\n", - " print(\"- Name:\", p_name)\n", - " print(\"- URL:\", p_url)\n", - " break\n", + " # Get existing workspace ids\n", + " current_workspace_ids = [workspace.get(\"id\") for workspace in workspaces.get(\"workspaces\")]\n", + "\n", + " if personal_workspace:\n", + " personal_workspace_id = None\n", + " # Get personal workspace\n", + " for workspace in workspaces.get(\"workspaces\"):\n", + " if workspace.get(\"is_personal\"):\n", + " personal_workspace_id = workspace.get(\"id\")\n", + " break\n", + " if personal_workspace_id not in workspace_ids:\n", + " workspace_ids.append(personal_workspace_id)\n", " \n", - " # Create or update plugin\n", - " if not plugin_exist:\n", - " result = create_workspace_plugin(\n", - " api_key,\n", - " workspace_id,\n", - " plugin,\n", - " )\n", - " print(\"✅ Plugin successfully created\")\n", - " else:\n", - " result = update_workspace_plugin(\n", - " api_key,\n", - " workspace_id,\n", - " plugin_id,\n", - " plugin,\n", - " )\n", - " print(\"✅ Plugin successfully updated\")\n", + " for index, workspace_id in enumerate(workspace_ids):\n", + " if workspace_id in current_workspace_ids:\n", + " workspace_id = workspace_id.strip()\n", + " print(f\"{index} - Workspace ID:\", workspace_id)\n", + " # List existing plugins\n", + " plugins = list_workspace_plugins(\n", + " api_key,\n", + " workspace_id,\n", + " )\n", + " plugin_exist = False\n", + " print(\"Plugins:\", len(plugins.get('workspace_plugins')))\n", + " for i, p in enumerate(plugins.get('workspace_plugins')):\n", + " plugin_id = p.get(\"id\")\n", + " p_json = json.loads(p.get(\"payload\"))\n", + " p_name = p_json.get(\"name\")\n", + " p_slug = p_json.get(\"slug\")\n", + " p_url = p_json.get(\"url\")\n", + " if plugin_url == p_url:\n", + " plugin_exist = True\n", + " print(\"Plugin ID:\", plugin_id)\n", + " print(\"- Slug:\", p_slug)\n", + " print(\"- Name:\", p_name)\n", + " print(\"- URL:\", p_url)\n", + " break\n", + "\n", + " # Create or update plugin\n", + " if not plugin_exist:\n", + " result = create_workspace_plugin(\n", + " api_key,\n", + " workspace_id,\n", + " plugin,\n", + " )\n", + " print(\"✅ Plugin successfully created\")\n", + " else:\n", + " result = update_workspace_plugin(\n", + " api_key,\n", + " workspace_id,\n", + " plugin_id,\n", + " plugin,\n", + " )\n", + " print(\"✅ Plugin successfully updated\")\n", + " print()\n", + " else:\n", + " print(\"❌ Workspace ID does not exist for user.\")\n", " return result" ] },