DEV Community

Cover image for How to let ChatGPT call functions in your app

How to let ChatGPT call functions in your app

Simon Johansson on August 14, 2024

You can now give OpenAI access to your app’s APIs when answering prompts. This means, with just a few lines of code, you can let your users interac...
Collapse
 
crazycga profile image
James

Impressive. I hadn't thought of doing something like this...

Collapse
 
simonjohansson profile image
Simon Johansson

Cool! I found it really nice that it was so quick and easy to get going with the OpenAI SDK, try it out in your own app.

Collapse
 
jd_2bdf19f7f15397f profile image
Juan Davi

I needed to use:
Encore secret set OpenAIAPIKey --type dev,local,pr

Collapse
 
simonjohansson profile image
Simon Johansson

Thanks Juan, I updated the example 👍

Collapse
 
jd_2bdf19f7f15397f profile image
Juan Davi

but when runing I get:
encore run

❌ Building Encore application graph... Failed: setup deps
Caused by:
0: setup dependencies
1: npm install failed
2: No such file or directory (os error 2)
Stack backtrace:
0: anyhow::backtrace::capture::Backtrace::capture
1: ::setup_deps
2: scoped_tls::ScopedKey::set
3: tsparser_encore::main
4: std::sys_common::backtrace::__rust_begin_short_backtrace
5: _main
⠚ Analyzing service topology...
setup deps

Caused by:
0: setup dependencies
1: npm install failed
2: No such file or directory (os error 2)

Stack backtrace:
0: anyhow::backtrace::capture::Backtrace::capture
1: ::setup_deps
2: scoped_tls::ScopedKey::set
3: tsparser_encore::main
4: std::sys_common::backtrace::__rust_begin_short_backtrace
5: _main

Collapse
 
simonjohansson profile image
Simon Johansson

I think maybe you don’t have npm installed (or not on the PATH)? What happens in you run npm help in your terminal?

Thread Thread
 
jd_2bdf19f7f15397f profile image
Juan Davi

You are right, after trying to install npm, I get Error: You are using macOS 11

Thread Thread
 
jd_2bdf19f7f15397f profile image
Juan Davi

I will try with windows.

Collapse
 
mahesh_g profile image
Mahesh kumar

Great content. Keep going

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Thanks for the support Manesh!

Collapse
 
simonjohansson profile image
Simon Johansson

Thanks for the feedback, will do!

Collapse
 
shekharrr profile image
Shekhar Rajput

Good one. Bookmarking for later.

Collapse
 
kin7777 profile image
kince marando

Amazing advice, and well articulated
Kindly thanks

Collapse
 
jatin_patel_30d5db89d55b8 profile image
Jatin Patel

Amazing tutorial would surely integrate this one of my projects

Collapse
 
simonjohansson profile image
Simon Johansson

Thanks Jatin, glad to hear!

Collapse
 
martinbaun profile image
Martin Baun

Do you use this to test ChatGPT plugins?

Collapse
 
simonjohansson profile image
Simon Johansson

Hey Martin, thanks for your question. Do you mean testing your own integration before publishing a ChatGPT plugin? I have not published a ChatGPT plugin myself so I am unsure about the process OpenAI recommends for that. But OpenAI is pushing "function calling" as their recommended way of integrating ChatGPT into external system so to me it would make sense to utilize it when building plugins as well.

Collapse
 
kostaspap profile image
Κώστας Παπ

great!

Collapse
 
simonjohansson profile image
Simon Johansson

Thanks 🙌