# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/06_gpt.ipynb.

# %% auto 0
__all__ = ['generate_quote']

# %% ../nbs/06_gpt.ipynb 1
import os
from .config import fetch_env_var

# %% ../nbs/06_gpt.ipynb 2
def generate_quote(journal_entry: str) -> str:
    import openai
    # Set openai.api_key to the OPENAI environment variable
    openai.api_key = fetch_env_var("OPENAI_API_KEY")

    # Define system and user messages
    messages = [
        {"role": "system", "content": "You are a helpful assistant that provides an inspiring, motivational, and encouraging quote relevant to a given journal entry."},
        {"role": "user", "content": f"Please provide a motivational, inspiring, or encouraging quote relevant to this journal entry: '{journal_entry}'"},
        {"role": "user", "content": f"After you have provided the quote, please provide specific excerpts from the journal entry that relate to the quote. Do not explain how the excerpts are relevant."}
    ]

    # Make the API call
    response = openai.ChatCompletion.create(
        model="gpt-4-1106-preview",  # use the correct model name for GPT-4
        messages=messages
    )

    # Extract the generated message
    return response["choices"][0]["message"]["content"]
