Skip to content

Commit

Permalink
feat: push abi plugins to workspace plugin's
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentLvr committed Apr 5, 2024
1 parent e797e2e commit a20b621
Show file tree
Hide file tree
Showing 8 changed files with 590 additions and 529 deletions.
112 changes: 25 additions & 87 deletions models/content-engine/__plugin__.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@
"input_file = \"posts\"\n",
"spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"abi_spreadsheet\") or \"\"\n",
"sheet_name = \"POSTS\"\n",
"name = \"📲 Content Assistant\"\n",
"name = \"Content Assistant\"\n",
"model = \"gpt-4-1106-preview\"\n",
"temperature = 0.5\n",
"description = \"Streamline the generation and distribution of content that aligns with the user's or business's brand voice and audience engagement goals.\"\n",
"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",
"\n",
"# Outputs\n",
"output_dir = os.path.join(entity_dir, \"plugins\")\n",
Expand Down Expand Up @@ -217,6 +218,7 @@
"interactions = 0\n",
"\n",
"# Load data from pickle\n",
"df = pd.DataFrame()\n",
"data = pload(input_dir, input_file) \n",
"if data is None:\n",
" data = gsheet.connect(spreadsheet_url).get(sheet_name=sheet_name)\n",
Expand All @@ -239,7 +241,7 @@
" kpi = f\"{views}\"\n",
" kpi_label = \"impressions\"\n",
"\n",
"limit = 0.45\n",
"limit = 0.3\n",
"prompt_tokens, max_tokens = naas_chat_plugin.check_tokens(\n",
" prompt=prompt_data,\n",
" model=model,\n",
Expand Down Expand Up @@ -277,29 +279,6 @@
"\"\"\""
]
},
{
"cell_type": "markdown",
"id": "3c97c27b-06d4-474c-a347-08a6df8856de",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create commands"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c78707b5-9496-44d5-a0b3-26fa4e88004e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"commands = create_command(model_dir)"
]
},
{
"cell_type": "markdown",
"id": "81ce4521-731f-42cb-8ace-0e7611c750b3",
Expand All @@ -319,8 +298,7 @@
"tags": []
},
"source": [
"### Create Naas Chat plugin\n",
"This function will generate the plugin in JSON format and also verify if your prompt adheres to the recommended limit, which is set at 20% of the maximum tokens allowed by the model. Then, it will save your plugin in your local environment."
"### Create Naas Chat plugin & Push to Workspace"
]
},
{
Expand All @@ -333,75 +311,35 @@
},
"outputs": [],
"source": [
"output_path = os.path.join(output_dir, f\"{name.lower().replace(' ', '_')}.json\")\n",
"# Create commands\n",
"print(\"--> Creating commands\")\n",
"commands = create_command(model_dir)\n",
"print()\n",
"\n",
"# Create plugin\n",
"plugin_file_path = naas_chat_plugin.create_plugin(\n",
"# Create Naas Chat plugin\n",
"print(\"--> Creating Naas Chat plugin\")\n",
"plugin_file_path, plugin_url, plugin = create_plugin(\n",
" name=name,\n",
" prompt=system_prompt,\n",
" model=model,\n",
" temperature=temperature,\n",
" output_path=output_path,\n",
" output_dir=output_dir,\n",
" description=description,\n",
" avatar=avatar,\n",
" commands=commands\n",
")"
]
},
{
"cell_type": "markdown",
"id": "34b625a0-f39b-4c7e-82f5-cc58a11ec902",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create asset\n",
"This asset can be utilized by using the command `/use` in your Naas Chat or by simply clicking on the link provided in the last cell output."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39437f23-bcf8-40df-9538-32b3cac1c8fb",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"plugin_url = naas.asset.add(plugin_file_path, params={\"inline\": True})\n",
"print(plugin_url)"
]
},
{
"cell_type": "markdown",
"id": "1dde0d3d-de48-4307-bd6a-63081b1e436c",
"metadata": {},
"source": [
"### Create new chat\n",
"NB: You don't need to click on 'Create New Chat' everytime you update your system prompt, you can use the command `/refresh`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "221fab1a-663b-4aa7-871d-f8ff7b1e2a18",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
" commands=commands,\n",
" entity_name=entity_name,\n",
")\n",
"print()\n",
"\n",
"# Push plugin to Personal workspace\n",
"print(\"--> Push plugin to Personal workspace\")\n",
"push_plugin_to_workspace(api_key, plugin)\n",
"print()\n",
"\n",
"# Create new chat\n",
"print(\"--> Create new chat\")\n",
"Markdown(f\"[Create New Chat](https://naas.ai/chat/use?plugin_url={plugin_url})\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8a2f65a-c24b-4d33-b24d-7ce2dacb834e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
134 changes: 36 additions & 98 deletions models/finance-engine/__plugin__.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,13 @@
"# Inputs\n",
"entity_id = \"0\"\n",
"entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", entity_id), \"entity_dir\")\n",
"name = \"💰 Finance Assistant\"\n",
"system_prompt = f\"\"\"\n",
"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",
"Start by presenting yourself.\n",
"\"\"\"\n",
"name = \"Finance Assistant\"\n",
"model = \"gpt-3.5-turbo-16k\"\n",
"temperature = 0\n",
"description = \"Manage financial transactions accurately and maintain comprehensive records for informed financial planning and analysis.\"\n",
"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",
"\n",
"# Outputs\n",
"output_dir = os.path.join(entity_dir, \"plugins\")\n",
Expand All @@ -164,51 +158,28 @@
},
{
"cell_type": "markdown",
"id": "3c97c27b-06d4-474c-a347-08a6df8856de",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create commands"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c78707b5-9496-44d5-a0b3-26fa4e88004e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"commands = create_command(model_dir)"
]
},
{
"cell_type": "markdown",
"id": "d8873a32-ba94-48ff-84de-0a025cc64d15",
"id": "8046aa2e-3d49-4a53-9e48-f8d970757006",
"metadata": {},
"source": [
"### Add commands to system prompt"
"### Create system prompt"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "814cbc57-f274-494d-a939-55dc73a7997c",
"id": "5a9393dc-722b-4592-9973-60c967eb4771",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"if len(commands) > 0:\n",
" command_prompt = \"Tell the user the commands they could use: [COMMANDS]\"\n",
"\n",
" # Generate the list of commands with description in prompt.\n",
" command_prompt = command_prompt.replace(\"[COMMANDS]\", \" \".join([f\"-**{x.get('name')}**: {x.get('description').replace('notebook', 'command')}\" for x in commands]))\n",
" print(\"Command prompt:\", command_prompt)\n",
" system_prompt = system_prompt + command_prompt"
"system_prompt = f\"\"\"\n",
"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",
"Start by presenting yourself.\n",
"\"\"\""
]
},
{
Expand All @@ -224,92 +195,59 @@
},
{
"cell_type": "markdown",
"id": "2d959298-e04a-459f-85d9-1b12bb5754c9",
"id": "db5ba009-3728-4f20-b749-4ae4a6e71eac",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create Naas Chat plugin\n",
"This function will generate the plugin in JSON format and also verify if your prompt adheres to the recommended limit, which is set at 20% of the maximum tokens allowed by the model. Then, it will save your plugin in your local environment."
"### Create Naas Chat plugin & Push to Workspace"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac0af791-9f6d-4da8-82d0-1defed0bc59f",
"id": "1f46769c-8ea8-4ccd-8724-ef3c5c47f4e7",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"output_path = os.path.join(output_dir, f\"{name.lower().replace(' ', '_')}.json\")\n",
"# Create commands\n",
"print(\"--> Creating commands\")\n",
"commands = create_command(model_dir)\n",
"print()\n",
"\n",
"# Create plugin\n",
"plugin_file_path = naas_chat_plugin.create_plugin(\n",
"# Create Naas Chat plugin\n",
"print(\"--> Creating Naas Chat plugin\")\n",
"plugin_file_path, plugin_url, plugin = create_plugin(\n",
" name=name,\n",
" prompt=system_prompt,\n",
" model=model,\n",
" temperature=temperature,\n",
" output_path=output_path,\n",
" output_dir=output_dir,\n",
" description=description,\n",
" avatar=avatar,\n",
" commands=commands\n",
")"
]
},
{
"cell_type": "markdown",
"id": "34b625a0-f39b-4c7e-82f5-cc58a11ec902",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Create asset\n",
"This asset can be utilized by using the command `/use` in your Naas Chat or by simply clicking on the link provided in the last cell output."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39437f23-bcf8-40df-9538-32b3cac1c8fb",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"plugin_url = naas.asset.add(plugin_file_path, params={\"inline\": True})\n",
"print(plugin_url)"
]
},
{
"cell_type": "markdown",
"id": "1dde0d3d-de48-4307-bd6a-63081b1e436c",
"metadata": {},
"source": [
"### Create new chat\n",
"NB: You don't need to click on 'Create New Chat' everytime you update your system prompt, you can use the command `/refresh`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "221fab1a-663b-4aa7-871d-f8ff7b1e2a18",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
" commands=commands,\n",
" entity_name=entity_name,\n",
")\n",
"print()\n",
"\n",
"# Push plugin to Personal workspace\n",
"print(\"--> Push plugin to Personal workspace\")\n",
"push_plugin_to_workspace(api_key, plugin)\n",
"print()\n",
"\n",
"# Create new chat\n",
"print(\"--> Create new chat\")\n",
"Markdown(f\"[Create New Chat](https://naas.ai/chat/use?plugin_url={plugin_url})\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8a2f65a-c24b-4d33-b24d-7ce2dacb834e",
"id": "8dd9405f-eeb5-49c8-823b-52a069b092d9",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit a20b621

Please sign in to comment.