How to use two Language Tasks with PaLM API extension instances in a same collection document

The Language Tasks with PaLM API extension is really really awesome, it is very good to be able to perform custom language tasks this easily and quickly directly on Firestore. However there is a problem when trying to make two of this tasks for the same document in a collection.

You see, as for the code of the extension (https://github.com/GoogleCloudPlatform/firebase-extensions/blob/next/firestore-palm-gen-text/functions/src/index.ts), the extension will only trigger if the prompt is valid, the response field does not exist yet and, most importantly, if the status of the task is not ‘PROCESSING’, ‘COMPLETED’ or ‘ERRORED’. This status is a field that the task creates in the document.

before task
after task

This status field is the same for whatever instance you create. So, if I create two tasks, say, one to summarize a text, and the other to create tags from the summarized text, the summarize task will create this status and the second one will never start, because this status will be ‘PROCESSING’, ‘COMPLETED’ or’ERRORED’.

What the best practice would be for this kind of use case?

The first solution I though for this is to create functions to delete the status after the first task so that the second task can execute. I would need to add some verification logic to make this properly, but I can see this becoming more convoluted the more tasks I want to make.

Then I though about creating separate collections. I would have a “texts”, “summaries” and “tags” collections. This way there would be no status conflict anymore, however, I would need to create some functions to move the information around: When I recieve a valid text, I would need a function to move this text to a “summary” document, so the task could start. Then I would need to move the summary text to a “tags” document so the tag task can happen. Also, I would need to keep track of all the documents references aswell, so I can link the text document to it’s summary and tags document.

I know this extension is kind of new, but are there some best practices for this cases? How are you guys doing it?

Leave a Comment