From b5562074f8688fca9cfe1e0cd0a55b0b5beb9f40 Mon Sep 17 00:00:00 2001 From: Raghav Date: Sat, 27 Jan 2024 20:54:45 +0000 Subject: [PATCH] added story to database w/ document id --- functions/main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/functions/main.py b/functions/main.py index 8d766fc..fae827b 100644 --- a/functions/main.py +++ b/functions/main.py @@ -54,12 +54,30 @@ def generate_story(req: https_fn.Request) -> https_fn.Response: ], ) + response_story = completion.choices[0].message.content + pattern = r"Title: (.+?)" + + # Use re.search to find the match in the input string + match = re.search(pattern, input_string) + + if match: + title = match.group(1) + print("Title:", title) + else: + title = "" + print("Title not found.") + + response_character = generate_characters_json(response_story) print(response_story) print(response_character) + + response_object = {"story": response_story, "characters": response_character, "narrator_voice": "", "storyId":title} + + db_doc = doc_ref.add(response_object) - response_object = {"story": response_story, "characters": response_character} + response_object["document_id"] = db_doc.id return https_fn.Response.json(response_object)