https://github.com/klich3/firebase-gpt-chat-completion
Function for use of GPT Api for chat completion in Firebase
https://github.com/klich3/firebase-gpt-chat-completion
firestore firestore-function nodejs16 react reactfire
Last synced: 2 months ago
JSON representation
Function for use of GPT Api for chat completion in Firebase
- Host: GitHub
- URL: https://github.com/klich3/firebase-gpt-chat-completion
- Owner: klich3
- License: mit
- Created: 2023-05-25T11:07:37.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-18T11:26:45.000Z (almost 2 years ago)
- Last Synced: 2025-01-30T01:17:17.226Z (4 months ago)
- Topics: firestore, firestore-function, nodejs16, react, reactfire
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
README
# Firebase Cloud Functions for GPT Chat Completion

Example of ChatGPT implementation in Firebase with functions. They are via internal calls with call and response.
***Issue:***: This method seems to be slower than the other Stream method because it does not stream.## SETUP
In `functions` folder create file `.env` with your OpenAI Api key.
Sample:
```text
OPEN_AI_KEY="sk-"
```## SETUP WITH CUSTOM FUNCTIONS FOLDER
To use functions in a custom folder different from the default, suppose the destination folder is `functions` inside we create a new folder named `gpt-chat-completion` and copy files from this project that are inside the `functions` folder. Then edit the `firebase.json` file from the root folder of your project.
```json
{
...
"firestore": {
...
},
...
"functions": [
{
"source": "functions/gpt-chat-completion",
"codebase": "gpt-chat-completion",
"predeploy": ["npm --prefix \"$RESOURCE_DIR\" run lint"],
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"runtime": "nodejs16"
}
]
...
}
```## Deploy
Run `firebase deploy --only functions:gpt-chat-completion`
## Sample usage in REACT
```javascript
import { httpsCallable } from "firebase/functions";
import {
useFunctions,
} from "reactfire";
...const functions = useFunctions();
const gptPrompt = httpsCallable(functions, "gptPrompt");gptPrompt({prompt: [{role: "user", content: "Hello world"}]})
```