irudnyts / openai

An R package-wrapper around OpenAI API
https://irudnyts.github.io/openai/
Other
164 stars 28 forks source link

Enable OpenAI functions in chat completion #47

Open nhardtskim opened 12 months ago

nhardtskim commented 12 months ago

Enabled OpenAI function calling, and added the example from the cookbook (https://platform.openai.com/docs/guides/gpt/function-calling).

I haven't added any parsing of the output yet, because I am not sure that is desirable or straightforward.

nhardtskim commented 12 months ago

I guess if there is a message.function_call.arguments, one could automatically invoke jsonlite::fromJSON() since jsonlite is a dependency anyway, but up to you.

statzhero commented 11 months ago

This looks good to me, although I'm not sure why the original code formatting is screwed up. I look forward to the merge.

Possibly add the test

  if (!is.null(functions)) {
    assertthat::assert_that(
      is.list(functions)
    )
  }
mpr1255 commented 9 months ago

@irudnyts can you merge? This would be really really great.

irudnyts commented 9 months ago

@irudnyts can you merge? This would be really really great.

@mpr1255 I am really sorry for the delay. I quickly reviewed several PRs. The problem is that there is a certain idea behind this package (i.e., mimic arguments from the official Python package) + certain code style. Rather than modifying someone else's code, for me, it is faster to quickly write my own.

Good news is there are plenty of new endpoints have been introduced and many functions must be depricated. So, I'll do my best to get back on the track and maintain it properly.

If you need those functionality now, you can always use remotes::install_github() and specify @nhardtskim's commit from their fork.

nhardtskim commented 9 months ago

I do appreciate consistency with openai's python package as an objective, and tried to be close. However, @irudnyts, be careful that, because version 1.0.0 of openai's python package had some breaking changes, and it's a bit of a headache.