# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ### Run Setup Environment notebook first before running below cells

# +
# # %run ./setup-env.ipynb

# +
# load libraries
import os
import openai

# Define variables
openai.api_key = os.getenv('OPENAI_API_KEY')
# -

# ### Generate product name

response = openai.Completion.create(
  engine="davinci",
  prompt="""
    This is a product name generator.
    
    Product description: A home milkshake maker
    Seed words: fast, healthy, compact
    Product names: HomeShaker, Fit Shaker, QuickShake, Shake Maker
    Product description: A pair of shoes that can fit any foot size.
    Seed words: adaptable, fit
    Product names:""",
  temperature=0.5,
  max_tokens=60,
  top_p=1.0,
  frequency_penalty=0.0,
  presence_penalty=0.0,
  stop=["\n"]
)


response


# ### Q&A with banking context

# +
def call_openapi(question):
    response = openai.Completion.create(
      engine="davinci",
      prompt="""
        This is a banking expert.

        Q: What is interest rate?
        A: The interest rate is the amount a lender charges for the use of assets expressed as a percentage of the principal.

        Q: What is PD?
        A: Probability of default.

        Q: {question}?
        A:""".format(question=question),
      temperature=0.3,
      max_tokens=60,
      top_p=1.0,
      frequency_penalty=0.0,
      presence_penalty=0.0,
      stop=["\n"]
    )
    
    return response

def extract_ans(response):
    return print(response.choices[0].text)



# -

response = call_openapi('What is LGD?')
extract_ans(response)

response = call_openapi('What is the difference between conventional financing vs syariah financing?')
extract_ans(response)

response = call_openapi('How do banks assess credit risk?')
extract_ans(response)

# ### Text classification

tweet = ''


def call_openapi(tweet):
    response = openai.Completion.create(
      engine="davinci",
      prompt="""This is a tweet sentiment classifier
      
                Tweet: "I loved the new Batman movie!"
                Sentiment: Positive
                ###
                Tweet: "I hate it when my phone battery dies"
                Sentiment: Negative
                ###
                Tweet: "My day has been 👍"
                Sentiment: Positive
                ###
                Tweet: "This is the link to the article"
                Sentiment: Neutral
                ###
                Tweet: {tweet}
                Sentiment:""".format(tweet=tweet),
       temperature=0.3,
      max_tokens=60,
      top_p=1.0,
      frequency_penalty=0.0,
      presence_penalty=0.0,
      stop=["###"]
    )
    
    return response


call_openapi('trump wins again. yay!')

StarcoderdataJupyterScriptsDedupFiltered