Template request | Bug report | Generate Data Product
Tags: #openai #ai #machinelearning #deeplearning #notebooks #automation #gsheet
Author: Florent Ravenel
Description: This notebook creates "Act as a ..." notebooks from a Google Sheets spreadsheet using OpenAI_Act_as_a_chef.ipynb as template.
References:
from papermill.iorw import (
load_notebook_node,
write_ipynb,
)
import naas
from naas_drivers import gsheet
import copy
import json
import subprocess
# Inputs
spreadsheet_url = "https://docs.google.com/spreadsheets/d/"
sheet_name = "Templates"
# Outputs
notebook_init = "OpenAI_Act_as_a_chef.ipynb"
name_init = "Act as a chef"
model = "gpt-4"
prompt_init = f"""
Act as a chef whose name is Florent.
Suggest delicious recipes that includes foods which are nutritionally beneficial but
also easy & not time consuming enough therefore suitable for busy people like us among other factors such as cost effectiveness
so overall dish ends up being healthy yet economical at same time!
In your first message, you will present yourself and what you can do.
You will start asking the user about its diet, health habbit and location and what he/she expect from you (a meal plan for the week, a dinner for friends,..) with questions in bullet point.
"""
temperature = 1
max_tokens = 2084
# Get notebook
nb_init = load_notebook_node(notebook_init)
df_input = gsheet.connect(spreadsheet_url).get(sheet_name=sheet_name)
print("Row fetched:", len(df_input))
df_input.head(1)
for row in df_input.itertuples():
# Init
nb = copy.deepcopy(nb_init)
name = row.Name
description = row.Description
tags = row.Tags
prompt = row.Prompt
# Prep outputs
notebook_output = f"OpenAI_{name.replace(' ', '_')}.ipynb"
title = f"# OpenAI - {name}"
hashtags = f"**Tags:** {tags.lower()}"
author = "**Author:** [Jeremy Ravenel](https://www.linkedin.com/in/jeremyravenel/)"
nb_description = f"**Description:** {description}"
variables = nb.cells[10].source
data = {
"name": name,
"prompt": prompt.replace("\n", ""),
"model": model,
"temperature": temperature,
"max_tokens": max_tokens,
}
# Update notebook
nb.cells[1].source = title
nb.cells[2].source = hashtags
nb.cells[3].source = author
nb.cells[4].source = nb_description
nb.cells[10].source = variables.replace(name_init, name, 1).replace(prompt_init, prompt)
nb.cells[13].outputs[0]["text"] = json.dumps(data)
# Save new notebook
write_ipynb(nb, notebook_output)