{"id":22191931,"url":"https://github.com/klich3/firebase-gpt-chat-completion-stream","last_synced_at":"2025-07-26T22:31:43.965Z","repository":{"id":171596419,"uuid":"648141696","full_name":"klich3/firebase-gpt-chat-completion-stream","owner":"klich3","description":"Example of ChatGPT Stream implementation in Firebase with functions. For this method you have to use `fetch`.","archived":false,"fork":false,"pushed_at":"2024-03-18T12:05:47.000Z","size":94,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T11:27:08.027Z","etag":null,"topics":["chatgpt","chatgpt-api","firebase","firebase-function","firebase-functions","gpt","openai","openai-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klich3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"ko_fi":"klich3"}},"created_at":"2023-06-01T09:51:41.000Z","updated_at":"2024-03-23T05:43:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"9f8c57d2-8944-46ed-929a-81a927b8f0b7","html_url":"https://github.com/klich3/firebase-gpt-chat-completion-stream","commit_stats":null,"previous_names":["klich3/firebase-gpt-chat-completion-stream"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klich3%2Ffirebase-gpt-chat-completion-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klich3%2Ffirebase-gpt-chat-completion-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klich3%2Ffirebase-gpt-chat-completion-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klich3%2Ffirebase-gpt-chat-completion-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klich3","download_url":"https://codeload.github.com/klich3/firebase-gpt-chat-completion-stream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227724142,"owners_count":17810036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","chatgpt-api","firebase","firebase-function","firebase-functions","gpt","openai","openai-api"],"created_at":"2024-12-02T12:18:27.096Z","updated_at":"2024-12-02T12:18:27.787Z","avatar_url":"https://github.com/klich3.png","language":"JavaScript","funding_links":["https://ko-fi.com/klich3"],"categories":[],"sub_categories":[],"readme":"# Firebase Cloud Functions for GPT Chat Completion\n\n![firebase+gpt](images/firebase_and_gpt.jpg?raw=true)\n\nExample of ChatGPT ***Stream*** implementation in Firebase with functions. For this method you have to use `fetch`.\n***Issue:***: This method seems to be slower than the other Stream method because it does not stream.\n\n## SETUP\n\nIn `functions` folder create file `.env` with your OpenAI Api key.\n\nSample: \n```text\nOPEN_AI_KEY=\"sk-\u003cyour key here\u003e\"\n```\n\n## SETUP WITH CUSTOM FUNCTIONS FOLDER\n\nTo 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-stream` 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.\n\n```json\n{\n\t...\n\t\"firestore\": {\n\t\t...\n\t},\n\t...\n\t\"functions\": [\n\t\t{\n\t\t\t\"source\": \"functions/gpt-chat-completion-stream\",\n\t\t\t\"codebase\": \"gpt-chat-completion-stream\",\n\t\t\t\"predeploy\": [\"npm --prefix \\\"$RESOURCE_DIR\\\" run lint\"],\n\t\t\t\"ignore\": [\n\t\t\t\t\"node_modules\",\n\t\t\t\t\".git\",\n\t\t\t\t\"firebase-debug.log\",\n\t\t\t\t\"firebase-debug.*.log\"\n\t\t\t],\n\t\t\t\"runtime\": \"nodejs16\"\n\t\t}\n\t]\n\t...\n}\n```\n\n## Deploy\n\nRun `firebase deploy --only functions:gpt-chat-completion-stream`\n\n## Sample usage in REACT\n\n```javascript\nconst [responseChunk, setResponseChunk] = useState\u003cstring\u003e(\"\");\nlet responseStream = \"\";\n\nconst callPrompt = (e:any) =\u003e {\n\tfetch(\"https://\u003cregion\u003e-\u003cproject-name\u003e.cloudfunctions.net/gptPromptStream\", {\n\t\tmethod: \"POST\",\n\t\tbody: JSON.stringify({\n\t\t\tprompt: [{role: \"user\", content: \"Hello world\"}],\n\t\t}),\n\t}).then(async (response) =\u003e {\n\t\tif(!response \u0026\u0026 !response.body) return;\n\n\t\tconst decoder = new TextDecoder(\"utf-8\");\n\t\tconst reader = response?.body?.getReader();\n\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\t\n\t\t\tif (done) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst text = decoder.decode(value);\n\n\t\t\tresponseStream += text;\n\t\t\tsetResponseChunk(responseStream);\n\t\t}\n\t})\n\t.catch((err) =\u003e {\n\t\tconsole.error(`Error occurred while attempting Fetch request: ${err}`);\n\t});\n};\n...\n\n//JSX part:\n\n\u003c\u003e\n\t\u003cbutton onClick={callPrompt}\u003eCall prompt\u003c/button\u003e\n\n\t\u003ch1\u003eResponse\u003c/h1\u003e\n\t\u003cdiv\u003e{responseChunk}\u003c/div\u003e\n\u003c/\u003e\n```\n\n---\n\n# BEWARE \u003ch1\u003e⚠️\u003c/h1\u003e\n\nThis method may no longer be functional as the LangChain package is updated daily.\n\nIf you feel like collaborating you can create Pull Request...\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklich3%2Ffirebase-gpt-chat-completion-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklich3%2Ffirebase-gpt-chat-completion-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklich3%2Ffirebase-gpt-chat-completion-stream/lists"}