Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/GitHub/GitHub_Create_plugin_with_commands.ipynb
2973 views
Kernel: Python 3

GitHub.png

GitHub - Create plugin with commands

Give Feedback | Bug report

Tags: #github #naaschatplugin #naas #naas_driver

Last update: 2023-09-28 (Created: 2023-09-28)

Description: This notebook creates a Naas Chat plugin using commands from GitHub templates.

Input

Import libraries

import os import naas from naas_drivers import naas_chat_plugin from IPython.display import Markdown

Setup variables

Mandatory

  • name: The name of the plugin.

  • system_prompt: The system prompt for the plugin.

  • input_dir: The path where the webhooks should be stored. By default, you can access all templates in your Naas Lab in "/home/ftp/templates/"

Optional

  • body: This variable stores the body to be send by the webhook.

  • model: The name of the model to be used for tokenization. Default is "gpt-3.5-turbo-16k".

  • temperature: The temperature parameter for the model. Default is 0.

  • output_path: The path where the JSON file should be saved. If not provided, it will be created from the plugin name.

# Mandatory name = "GitHub Agent" system_prompt = f"You are a GitHub assistant. Start presenting yourself and tell the user the commands they could use: [COMMANDS]" input_dir = "/home/ftp/__templates__" # Optional body = {} model = "gpt-3.5-turbo-16k" temperature = 0 output_path = None

Model

Push Webhook to production

Webhook URL to be included in command of your Naas Chat plugin.

webhook_url1 = naas.webhook.add(f"{input_dir}/GitHub/GitHub_Connect_from_Naas_Chat.ipynb", params={"inline": True}) webhook_url2 = naas.webhook.add(f"{input_dir}/GitHub/GitHub_Create_Issue_from_Naas_Chat.ipynb", params={"inline": True})

Create command

Modify payload with parameters

commands = [ { "name": "GitHub_Connect_from_Naas_Chat", "action": { "request_type": "POST", "url": webhook_url1, "payload": { "secret_value": { "type": "str", "description": "GitHub token to be add as secret", "default": "" }, "github_url": { "type": "str", "description": "GitHub organization html URL", "default": "" }, } } }, { "name": "GitHub_Create_Issue_from_Naas_Chat", "action": { "request_type": "POST", "url": webhook_url2, "payload": { "repo_url": { "type": "str", "description": "GitHub repository URL. By default, https://github.com/jupyter-naas/awesome-notebooks", "default": "https://github.com/jupyter-naas/awesome-notebooks" }, "title": { "type": "str", "description": "Issue title to create template such as Tool + Action verb like GitHub - Create Issue", "default": "" }, "description": { "type": "str", "description": "Issue description", "default": "" }, "assignee": { "type": "str", "description": "Optional: Profile to be assigned to task", "default": "" }, "label": { "type": "str", "description": "Optional: good first issue, enhancement, fix", "default": "" }, } } } ]

Output

Create Naas Chat plugin

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.

plugin_file_path = naas_chat_plugin.create_plugin( name=name, prompt=system_prompt.replace("[COMMANDS]", ", ".join([x.get("name") for x in commands])), model=model, temperature=temperature, output_path=output_path, commands=commands )

Create asset

This asset can be utilized by using the command /use in your Naas Chat or by simply clicking on the link provided in the cell below.

plugin_url = naas.asset.add(plugin_file_path, params={"inline": True})

Create new chat

You don't need to click on 'Create New Chat' everytime you update your system prompt, you can use the command /refresh.

Markdown(f"[Create New Chat](https://naas.ai/chat/use?plugin_url={plugin_url})")