-
-
Notifications
You must be signed in to change notification settings - Fork 954
feat: Added example for openAI function call #475
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
feat: Added example for openAI function call #475
Conversation
|
| }); | ||
|
|
||
| //Function call example for OpenAI | ||
| const createCompletion = async () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
|
||
| //Function call example for OpenAI | ||
| const createCompletion = async () => { | ||
| const chatCompletion = await io.openai.createChatCompletion("chat-completion", { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
|
Thanks @ericallam
Please check and share your feedback. |
|
HI @ericallam Did you get a chance to look into this? I have made the changes. |
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 🥺🥺