firebase-gpt-chat-completion-stream

Example of ChatGPT Stream implementation in Firebase with functions. For this method you have to use `fetch`.

https://github.com/klich3/firebase-gpt-chat-completion-stream

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.5%) to scientific vocabulary

Keywords

chatgpt chatgpt-api firebase firebase-function firebase-functions gpt openai openai-api
Last synced: 6 months ago · JSON representation ·

Repository

Example of ChatGPT Stream implementation in Firebase with functions. For this method you have to use `fetch`.

Basic Info
  • Host: GitHub
  • Owner: klich3
  • License: mit
  • Language: JavaScript
  • Default Branch: main
  • Homepage:
  • Size: 91.8 KB
Statistics
  • Stars: 14
  • Watchers: 2
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Topics
chatgpt chatgpt-api firebase firebase-function firebase-functions gpt openai openai-api
Created over 2 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Funding License Citation

README.md

Firebase Cloud Functions for GPT Chat Completion

firebase+gpt

Example of ChatGPT Stream implementation in Firebase with functions. For this method you have to use fetch. 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-<your key here>"

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-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.

json { ... "firestore": { ... }, ... "functions": [ { "source": "functions/gpt-chat-completion-stream", "codebase": "gpt-chat-completion-stream", "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-stream

Sample usage in REACT

```javascript const [responseChunk, setResponseChunk] = useState(""); let responseStream = "";

const callPrompt = (e:any) => { fetch("https://-.cloudfunctions.net/gptPromptStream", { method: "POST", body: JSON.stringify({ prompt: [{role: "user", content: "Hello world"}], }), }).then(async (response) => { if(!response && !response.body) return;

    const decoder = new TextDecoder("utf-8");
    const reader = response?.body?.getReader();

    while (true) {
        const { done, value } = await reader.read();

        if (done) {
            break;
        }

        const text = decoder.decode(value);

        responseStream += text;
        setResponseChunk(responseStream);
    }
})
.catch((err) => {
    console.error(`Error occurred while attempting Fetch request: ${err}`);
});

}; ...

//JSX part:

<>

<h1>Response</h1>
<div>{responseChunk}</div>

</> ```


BEWARE

⚠️

This method may no longer be functional as the LangChain package is updated daily.

If you feel like collaborating you can create Pull Request...

Owner

  • Name: Anton Sychev
  • Login: klich3
  • Kind: user
  • Location: Barcelona
  • Company: @Sychev

FullStack developer passionate about decentralized web tech, AI, Web 2.0, FrontEnd/BackEnd, databases, and system optimization. Focused on R&D.

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: gpt-chat-completion-stream
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Anton
    family-names: Sychev
    email: anton@sychev.xyz
repository-code: "https://github.com/klich3/firebase-gpt-chat-completion.git"
abstract: GPT Chat Completion Stream Cloud Functions for Firebase
keywords:
  - gpt
  - stream
  - chatGPT
  - firebase
  - functions
license: MIT
version: 0.1.0

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: about 1 month
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: about 1 month
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • alaminkouser (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels