ruby-openai icon indicating copy to clipboard operation
ruby-openai copied to clipboard

Functions Calling capability from ChatGPT model gpt-3.5-turbo-0613 not working

Open kris2150 opened this issue 2 years ago • 5 comments

Describe the bug This function throws a 500 error

**ArgumentError (unknown keyword: :functions):

app/controllers/openai_controller.rb:120:in `generate_insight'**

Am i doing something wrong

To Reproduce Steps to reproduce the behavior: # ChatGPT Prompt begin @aiResponseSleep = ChatGPTclient.completions( model: "gpt-3.5-turbo-0613", messages: [ { role: "user", content:"Your role is to be a Data Analyst with expert knowledge on sleep" }, { role: "user", content:" Your goal is to - Provide a natural language comparison between these two data sets attached below make it short and interesting. - Provide a comparison of the summariest from Today's day and past 3 Day - Use days instead of full dates and bold these days - Provide insights based on notes and based on your trained knowlege. - Use an encouraging tone to make sure I keep up these habits - Use HTML formatting and mark up to bold dates, number of days, REM, Deep, Light, Total - Avoid displaying the data tables " }, { role: "user", content: "Today's Data: #{ formatted_latest_sleep_record.to_json }" }, { role: "user", content: "Past 3 Days Sleep Recorded Data: #{ formatted_3days_data.to_json }" } ] ) rescue OpenaiChatgpt::Error => e puts e.message end

kris2150 avatar Jun 17 '23 07:06 kris2150

My guess: you passed in functions as a peer of parameters rather than nested under parameters

johnwahba avatar Jun 18 '23 17:06 johnwahba

My guess:

you passed in functions as a peer of parameters rather than nested under parameters

How would you update this code in order for this to work?

kris2150 avatar Jun 18 '23 21:06 kris2150

I added a function calling example to the README: https://github.com/alexrudall/ruby-openai/pull/281

seanmccann avatar Jun 19 '23 05:06 seanmccann

I merged that example so it's in the main README now @kris2150. Can you try that example and let us know if it's working for you?

alexrudall avatar Jun 20 '23 17:06 alexrudall

@alexrudall

# ChatGPT Functions

begin @aiResponse = ChatGPTclient.chat( parameters: { model: "gpt-3.5-turbo-16k", temperature: 1, frequency_penalty: 0, messages: [ { role: "user", content:" - Come up with 15 different goals derived from the data attached below with 5 goals benefits generated by You associated to each goal?" }, { role: "user", content:"#{@selected_text}" }, ], functions: [ { name: "get_goals_from_questionnaires", description: "15 different goals derived from the data attached below with 5 goals", parameters: { type: :object, properties: { goal_name: { type: :string, description: "Goal Name, e.g Maintain 7 hrs sleep schedule consistently", }, goal_benefits: { type: :string, description: "Goal Benefits, e.g be more energized through the day, experience better mental clairity", }, }, required: ["goal_name", "goal_benefits"], }, }, ], } ) rescue OpenaiChatgpt::Error => e puts e.message end

message = @aiResponse.dig("choices", 0, "message")

kris2150 avatar Jul 03 '23 14:07 kris2150