Thursday, May 11, 2023

Writing letter using openAI python

This code generated by chat.openai.com and this code is for databricks notebook. I modified according to my need.


 %python

import openai
openai.api_key = os.environ["OPENAI_API_KEY"]

#prompt = "Write a news article about a new breakthrough in cancer research."
#prompt = "Write a letter about cancer research. to a doctor "
#prompt = "Write a letter to supervisor about leave"
prompt =dbutils.widgets.get("SearchBox")

response = openai.Completion.create(
    engine="text-davinci-002",
    prompt=prompt,
    max_tokens=1024,
    n=1,
    stop=None,
    temperature=0.5,
)

article = response.choices[0].text
#print(article)

df = spark.createDataFrame([(article,)], ["article"]  )
# Display the DataFrame as a table
display(df)

No comments: