Skip to content

Conversation

@RamK777-stack
Copy link
Contributor

Added function call example in openAI.

/claim #469
/closes #469

Note:

I can't able to test the changes because I don't have an active openAI key. I consumed all of my free quota 🥺🥺

image

@changeset-bot
Copy link

changeset-bot bot commented Sep 14, 2023

⚠️ No Changeset found

Latest commit: 238a170

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

});

//Function call example for OpenAI
const createCompletion = async () => {
Copy link
Member

Choose a reason for hiding this comment

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

This won't work, because the key param is the same on each call. Not sure why it's necessary to do two calls to createChatCompetion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the first call, openAI returns JSON which contains the function name and arguments

Example:
{'index': 0,
'message': {'role': 'assistant',
'content': None,
'function_call': {'name': 'get_n_day_weather_forecast',
'arguments': '{\n "location": "Glasgow, Scotland",\n "format": "celsius",\n "num_days": 5\n}'}},
'finish_reason': 'function_call'}

Using this we need to call our functions. and pass the result to GPT again for summarization. so we need 2 calls.

Reference: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb


//Function call example for OpenAI
const createCompletion = async () => {
const chatCompletion = await io.openai.createChatCompletion("chat-completion", {
Copy link
Member

Choose a reason for hiding this comment

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

We should use the new way of doing this io.openai.chats.completions.create

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't understand this part @ericallam,

Do I need to use await io.openai.chats.completions.create instead of await io.openai.createChatCompletion ?

@RamK777-stack
Copy link
Contributor Author

Thanks @ericallam

  1. I have added more comments.
  2. Removed Google API request and mocked responses.
  3. Fixed ts errors.

Please check and share your feedback.

@RamK777-stack
Copy link
Contributor Author

HI @ericallam Did you get a chance to look into this? I have made the changes.

@ericallam ericallam changed the base branch from main to merges/pr-475 October 6, 2023 13:27
@ericallam ericallam merged commit 58a2eb2 into triggerdotdev:merges/pr-475 Oct 6, 2023
@RamK777-stack RamK777-stack deleted the fn-call-example-openAI branch October 13, 2023 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TRI-1273] Create a function call example for OpenAI

2 participants