1.0.1 • Published 7 months ago

@receptron/graphai_firebase_functions v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

GraphAI firebase function stream runner

Install

yarn add @receptron/graphai_firebase_functions

Usage

import { openAIAgent } from "@graphai/openai_agent";
import { CallableRequest, CallableResponse, HttpsError } from "firebase-functions/v2/https";
import type { AgentFunctionContext, AgentFunctionInfoDictionary } from "graphai";

import { StreamChunkCallback, runAgentOnCall } from "@receptron/graphai_firebase_functions";

const agentDictionary: AgentFunctionInfoDictionary = {
  openAIAgent,
};

export const agentRunner = async (request: CallableRequest, response?: CallableResponse) => {
  const uid = request.auth?.uid;

  if (!uid) {
    throw new HttpsError("unauthenticated", "Authentication required");
  }

  const streamCallback: StreamChunkCallback = (context: AgentFunctionContext, token: string) => {
    response?.sendChunk({
      delta: token,
      type: "agent",
      nodeId: context.debugInfo.nodeId,
      agentId: context.debugInfo.agentId,
    });
  };

  return await runAgentOnCall(request, agentDictionary, { streamCallback });
};
1.0.1

7 months ago

1.0.0

7 months ago