Skip to content

Add functions example to README #281

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 20, 2023

Conversation

seanmccann
Copy link
Contributor

Add the standard weather example for function calling to the README

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?

"content": "What is the weather like in San Francisco?",
},
],
functions: [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes —

"What is the weather like in San Francisco?" returns:

{"role"=>"assistant", "content"=>nil, "function_call"=>{"name"=>"get_current_weather", "arguments"=>"{\n  \"location\": \"San Francisco, CA\"\n}"}}

"What is the weather like in San Francisco in celsius?" returns:

{"role"=>"assistant", "content"=>nil, "function_call"=>{"name"=>"get_current_weather", "arguments"=>"{\n  \"location\": \"San Francisco, CA\",\n  \"unit\": \"celsius\"\n}"}}

"What is 1+1" returns:

{"role"=>"assistant", "content"=>"1 + 1 is equal to 2."}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, when I run this I just get:

       {"message"=>"Unrecognized request argument supplied: functions", "type"=>"invalid_request_error", "param"=>nil, "code"=>nil}```

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i get it. You need to use the latest model (for example):

gpt-4-0613

@seanmccann seanmccann force-pushed the sean/functions-example branch from 69fc57d to b01ca38 Compare June 19, 2023 18:48
@alexrudall
Copy link
Owner

Thanks @seanmccann! Works for me 👍

@alexrudall alexrudall merged commit 1dc9dfd into alexrudall:main Jun 20, 2023
@kris2150
Copy link

kris2150 commented Jul 3, 2023

Doesn't work for me. The error I am getting is

<NoMethodError: undefined method `chat' for #<OpenaiChatgpt::Client:0x0000000120abcbd0 @api_key="XXXXXXXXXX", @adapter=:net_http, @request_timeout=1200, @stubs=nil>>

I have also tried model: "gpt-3.5-turbo-0613",

Here is my function.

# # 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")

render json:{ aiResponse:  message }

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

Successfully merging this pull request may close these issues.

4 participants