Skip to content

Commit

Permalink
Merge pull request #95 from jupyter-naas/92-using-saved-prompt-to-cre…
Browse files Browse the repository at this point in the history
…ate-github-issue-on-naas-chat

92 using saved prompt to create GitHub issue on naas chat
  • Loading branch information
FlorentLvr authored Feb 21, 2024
2 parents 8cbb258 + a2b686e commit 86c48bd
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 270 deletions.
25 changes: 12 additions & 13 deletions models/content-engine/__plugin__.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,21 @@
"source": [
"### Setup variables\n",
"**Inputs**\n",
"- `entity_dir`: This variable represents the entity directory.\n",
"- `entity_dir`: Entity directory.\n",
"- `input_dir`: Input directory to retrieve file from.\n",
"- `file_content`: Name of the file to be retrieved.\n",
"- `input_file`: Input file.\n",
"- `spreadsheet_url`: Google Sheets spreadsheet URL.\n",
"- `sheet_name`: Google Sheets sheet name.\n",
"- `name`: The name of the plugin.\n",
"- `system_prompt`: Plugin system prompt with the commands they can use.\n",
"- `model`: This variable holds the openai model.\n",
"- `temperature`: This variable holds the temperate value.\n",
"- `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",
"- `name`: Plugin name.\n",
"- `model`: Plugin chat model.\n",
"- `temperature`: Plugin chat temperature.\n",
"- `description`: Plugin description.\n",
"- `avatar`: Plugin avatar image.\n",
"- `model_dir`: Models directory.\n",
"\n",
"**Outputs**\n",
"- `output_dir`: This variable holds a relative path to the directory where output files will be stored. \n",
"- `entity_name`: This variable holds the entity name."
"- `output_dir`: Output directory where output files are stored. \n",
"- `entity_name`: Entity name."
]
},
{
Expand All @@ -139,7 +138,7 @@
"# Inputs\n",
"entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_dir\")\n",
"input_dir = os.path.join(entity_dir, \"content-engine\", date.today().isoformat())\n",
"file_content = \"content\"\n",
"input_file = \"content\"\n",
"spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"abi_spreadsheet\") or \"\"\n",
"sheet_name = \"CONTENT\"\n",
"name = \"📲 Content Assistant\"\n",
Expand Down Expand Up @@ -217,7 +216,7 @@
"interactions = 0\n",
"\n",
"# Load data from pickle\n",
"data = pload(input_dir, file_content) \n",
"data = pload(input_dir, input_file) \n",
"if data is None:\n",
" data = gsheet.connect(spreadsheet_url).get(sheet_name=sheet_name)\n",
"if isinstance(data, pd.DataFrame):\n",
Expand Down
29 changes: 14 additions & 15 deletions models/growth-engine/__plugin__.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,22 @@
},
"source": [
"### Setup variables\n",
"**Mandatory**\n",
"- `entity_dir`: This variable represents the entity directory.\n",
"**Inputs**\n",
"- `entity_dir`: Entity directory.\n",
"- `input_dir`: Input directory to retrieve file from.\n",
"- `file_growth`: Name of the file to be retrieved.\n",
"- `input_file`: Input file.\n",
"- `spreadsheet_url`: Google Sheets spreadsheet URL.\n",
"- `sheet_name`: Google Sheets sheet name.\n",
"- `name`: The name of the plugin.\n",
"- `model`: This variable holds the openai model.\n",
"- `temperature`: This variable holds the temperate value.\n",
"- `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",
"- `name`: Plugin name.\n",
"- `model`: Plugin chat model.\n",
"- `temperature`: Plugin chat temperature.\n",
"- `description`: Plugin description.\n",
"- `avatar`: Plugin avatar image.\n",
"- `model_dir`: Models directory.\n",
"\n",
"**Optional**\n",
"- `output_dir`: This variable holds a relative path to the directory where output files will be stored. \n",
"- `output_path`: This variable holds the full path of the plugin.\n",
"- `entity_name`: This variable holds the entity name."
"**Outputs**\n",
"- `output_dir`: Output directory where output files are stored. \n",
"- `entity_name`: Entity name."
]
},
{
Expand All @@ -139,7 +138,7 @@
"# Inputs\n",
"entity_dir = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"entity_dir\")\n",
"input_dir = os.path.join(entity_dir, \"growth-engine\", date.today().isoformat())\n",
"file_growth = \"people\"\n",
"input_file = \"people\"\n",
"spreadsheet_url = pload(os.path.join(naas_data_product.OUTPUTS_PATH, \"entities\", \"0\"), \"abi_spreadsheet\")\n",
"sheet_name = \"PEOPLE\"\n",
"name = \"🚀 Growth Assistant\"\n",
Expand Down Expand Up @@ -270,7 +269,7 @@
"new_leads = 0\n",
"\n",
"# Load data from pickle\n",
"data = pload(input_dir, file_growth) \n",
"data = pload(input_dir, input_file) \n",
"if data is None:\n",
" data = gsheet.connect(spreadsheet_url).get(sheet_name=sheet_name)\n",
"if isinstance(data, pd.DataFrame):\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
},
"source": [
"### Setup variables\n",
"- `query`: naas.ai, Data & AI platform\n",
"- `keywords`: naas.ai, Data & AI platform\n",
"- `api_key`: Your News API key.\n",
"- `body`: This variable stores the body to be send by the webhook."
]
Expand All @@ -140,7 +140,7 @@
},
"outputs": [],
"source": [
"query = \"Microsoft\"\n",
"keywords = \"Microsoft\"\n",
"api_key = None\n",
"body = {}"
]
Expand Down Expand Up @@ -182,7 +182,7 @@
"source": [
"# Parameters\n",
"if len(body) > 0:\n",
" query = body.get(\"query\")\n",
" keywords = body.get(\"keywords\")\n",
" api_key = body.get(\"api_key\")"
]
},
Expand Down Expand Up @@ -218,28 +218,28 @@
},
"outputs": [],
"source": [
"def fetch_top_headlines(api_key, query):\n",
"def fetch_top_headlines(api_key, keywords):\n",
" # Init\n",
" status = \"ok\"\n",
" \n",
" # Manage api key\n",
" if api_key is None or str(api_key) == \"\":\n",
" if naas.secret.get(\"NEWS_API_API_KEY\") is None:\n",
" message = f\"❌ Unable to Connect to News API. Please update your API Key or your query: '{query}'\"\n",
" message = f\"❌ Unable to Connect to News API. Please update your API Key or your keywords: '{keywords}'\"\n",
" return status, message\n",
" else:\n",
" api_key = naas.secret.get(\"NEWS_API_API_KEY\")\n",
" \n",
" # Requests\n",
" try:\n",
" url = f\"https://newsapi.org/v2/top-headlines?q={query}\"\n",
" url = f\"https://newsapi.org/v2/top-headlines?q={keywords}\"\n",
" headers = {\"Authorization\": f\"Bearer {api_key}\"}\n",
" res = requests.get(url, headers=headers)\n",
" if len(res.json()) == 0 or len(res.json().get('articles')) == 0:\n",
" message = f\"✅ No articles found.\"\n",
" else:\n",
" message = f\"\"\"\n",
" Please provide the query result '✅ We have found {len(res.json().get('articles'))} articles on {query} from the News API.' and give a concise summary of the first 3 articles, sorted by date. If there is more than 3 articles, ask if the user wants to know more about the other articles. Start with the 'publishedAt' date in ISO format, followed by the 'title' and 'url' in markdown format. Then, provide a brief description in English. Display the associated image using markdown as 'followImage'. Conclude with the author's name and the source name below the image. Each article should be presented as a bullet point in a list without creating sub-bullet points for key elements of each article.\n",
" Please provide the keywords result '✅ We have found {len(res.json().get('articles'))} articles on {keywords} from the News API.' and give a concise summary of the first 3 articles, sorted by date. If there is more than 3 articles, ask if the user wants to know more about the other articles. Start with the 'publishedAt' date in ISO format, followed by the 'title' and 'url' in markdown format. Then, provide a brief description in English. Display the associated image using markdown as 'followImage'. Conclude with the author's name and the source name below the image. Each article should be presented as a bullet point in a list without creating sub-bullet points for key elements of each article.\n",
" Articles: \n",
" {res.json().get('articles')}\n",
" \"\"\"\n",
Expand All @@ -248,7 +248,7 @@
" message = f\"❌ Unable to Connect to News API. Error message: '{e}'\"\n",
" return status, message\n",
" \n",
"status, message = fetch_top_headlines(api_key, query)\n",
"status, message = fetch_top_headlines(api_key, keywords)\n",
"print(\"Status:\", status)\n",
"print(\"Message:\", message)"
]
Expand Down
Loading

0 comments on commit 86c48bd

Please sign in to comment.