Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/technologiestiftung/openai-function-calls-poc
https://github.com/technologiestiftung/openai-function-calls-poc
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/technologiestiftung/openai-function-calls-poc
- Owner: technologiestiftung
- License: mit
- Created: 2023-11-03T16:44:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-03T16:51:57.000Z (about 1 year ago)
- Last Synced: 2023-11-04T17:42:02.370Z (about 1 year ago)
- Language: TypeScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenAI function calls
What are function calls for in a nutshell?
Function calls can extract structured arguments from natural language.
for example for the function get_weather(city) the following user question would generate the following function call:> What is the weather in Berlin tomorrow?
OpenAIs API would return structured data like:
```json
{
"choices": [
{
"finish_reason": "function_call",
"index": 0,
"message": {
"content": null,
"function_call": {
"arguments": "{\n \"city\": \"Berlin\"\n}",
"name": "get_weather"
},
"role": "assistant"
}
}
],
// ...
}
}```
This response could then be plugged into an actual function we implemented to call a weather API.
---
## Implementation in Node.js
To use the example in this repo you need to have
- Node.js 20 installed
- Have an OpenAI API key exported in your environment as `OPENAPI_API_KEY````bash
# install dependencies
npm ci
# run the script
npx tsx index.ts --topic wisdom
```---
Related articles:
- https://platform.openai.com/docs/api-reference/chat/create?lang=curl
- https://platform.openai.com/docs/guides/gpt/function-calling
- https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models
- https://cookbook.openai.com/examples/how_to_call_functions_for_knowledge_retrieval