Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include messages argument as part of output object? #38

Open
sda030 opened this issue Mar 15, 2023 · 1 comment
Open

Include messages argument as part of output object? #38

sda030 opened this issue Mar 15, 2023 · 1 comment

Comments

@sda030
Copy link

sda030 commented Mar 15, 2023

Hi, great package.
For the sake of reproducibility and for ease of continuing a chat, could the create_chat_completion() returned result object include the inputted settings (in particular the messages argument)?

@irudnyts
Copy link
Owner

Hi @sda030, thanks for this. In principle, I can do it. However, I tried to be as consistent with the official Python package as possible. If I will return other objects, then it won't be inline.

I suggest keeping messages in a stand-alone variable:

library(openai)

messages <- list(
    list(
        "role" = "system",
        "content" = "You are a helpful assistant."
    ),
    list(
        "role" = "user",
        "content" = "Who won the world series in 2020?"
    ),
    list(
        "role" = "assistant",
        "content" = "The Los Angeles Dodgers won the World Series in 2020."
    ),
    list(
        "role" = "user",
        "content" = "Where was it played?"
    )
)


response <- create_chat_completion(
    model = "gpt-3.5-turbo",
    messages = messages
)

Or even keeping it in one list:

library(openai)

chat <- list()

chat[["input_messages"]] <- list(
    list(
        "role" = "system",
        "content" = "You are a helpful assistant."
    ),
    list(
        "role" = "user",
        "content" = "Who won the world series in 2020?"
    ),
    list(
        "role" = "assistant",
        "content" = "The Los Angeles Dodgers won the World Series in 2020."
    ),
    list(
        "role" = "user",
        "content" = "Where was it played?"
    )
)

chat[["reply"]] <- create_chat_completion(
    model = "gpt-3.5-turbo",
    messages = chat[["input_messages"]]
)

Please let me know if this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants