Skip to content

Firebase App Database

Eloi edited this page Jun 26, 2024 · 5 revisions

Navigating the Firebase Database

The Firebase Database is mainly used for the frontend app. It can be accessed via the web interface or api methods in react native.

Requirements

  • Access to the firebase project (can be granted by the software developers)
  • Firebase account (login with a google account is also possible)
  • For react native development: firebase configuration in .env file in the project root directory (containing api keys and similar, message a developer to get the contents)

Web Interface

Open the Amos Agent Framework Project in your web browser. Probably the two main functionalities that are needed can be found under Build/Authentication and Build/Firestore Database

1.)

Navigate to Build

2.)

Authentication and Firestore Tabs

Authentication

In this tab you can see and manage (if you have the rights) information concerning user accounts registered in the app. Different sign-in methods can be set up (e.g. google and email signin). This tab can also be used to add new users, reset passwords, see registered email-addresses which partain to account user UIDs, etc.

Authentication Window

Firestore Database

In the firestore database you can organise data into collections that contain documents. The entries in this database can be retrieved in react native to for example display a username or chat.

At this moment, we have a users collection containing all the users.

Firestore users

Here you can also create a user for yourself for testing purposes. For reference, see the already existing users.

Each user can possess a chats collection containing all the different conversations with the chatbots. Here you can create new chats or see existing ones.

Firestore user chats

Right now, a chat contains a conversation array, createdAt timestamp, model string and a title string.

React Native API

For usage of the stored data in react native, you can for example take a look at the src/frontend/hooks/ directory where different hooks for retrieving chat data are already implemented. For example:

  • useGetAllChat returns { chats: Chat[], status: string, error: Error } a list of all stored chats for the logged in user, the status of retrieval and an error object
type Chat = {
  id?: string;
  title: string;
  createdAt: Timestamp;
  model: string[];
  conversation: string[];
};
  • useActiveChatId can be used to retrieve the current (or last) selected chat by the user. The active chat can also be changed via this hook. Example usage:
// access the hook
const { activeChatId, setActiveChatId } = useActiveChatId();
// change active id
useEffect(() => {
  setActiveChatId(id)
}, [condition]);

similar hooks exist for

  • useDeleteChat delete a chat by chat id
  • useGetChat get one single chat by chat id
  • useUpdateChat overwrite the stored content of a chat with specified id
  • useLLMs retrieve active LLMs for the current active (or selected) chat or toggle LLMs on or off. At least one LLM should be on

For documentation about how to retrieve data from the firebase in React Native on a more granular level, see for example the documentation of react-native-firebase.