From 378469892a680635af8370498bdc83248a30b347 Mon Sep 17 00:00:00 2001 From: Julian Whiting Date: Tue, 6 Feb 2024 08:18:20 -0500 Subject: [PATCH] return template model card as json obj if model card generation fails --- core/openai/prompts/model_card.py | 6 +++--- core/openai/tool_utils.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/openai/prompts/model_card.py b/core/openai/prompts/model_card.py index 9c82443..376f828 100644 --- a/core/openai/prompts/model_card.py +++ b/core/openai/prompts/model_card.py @@ -21,6 +21,7 @@ "TechnicalSpecifications": { "model_specs": "Details about the model's complexity, such as the number of places, transitions, parameter count, and arcs." }, + "Glossary": { "terms": [] }, "ModelCardAuthors": [], @@ -30,13 +31,12 @@ "Citation": { "references": [] }, - "Glossary": { - "terms": [] - }, "MoreInformation": { "links": [] + } } """ + INSTRUCTIONS = """ You are a helpful agent designed to populate a model card containing metadata about a given research paper and its associated model.\n Use the following research paper as a reference: ---PAPER START---{research_paper}---PAPER END--. Ensure that the output follows the below model card format.\n diff --git a/core/openai/tool_utils.py b/core/openai/tool_utils.py index 1bf6084..c16532a 100644 --- a/core/openai/tool_utils.py +++ b/core/openai/tool_utils.py @@ -1,4 +1,5 @@ from datetime import datetime +import json from openai import OpenAI, AsyncOpenAI from typing import List from core.entities import Tool @@ -59,7 +60,7 @@ def model_card_chain(research_paper: str): ) model_card = extract_json("{" + output.choices[0].message.content) if model_card is None: - return MODEL_CARD_TEMPLATE + return json.loads(MODEL_CARD_TEMPLATE) return model_card @@ -84,7 +85,7 @@ async def amodel_card_chain(research_paper: str): ) model_card = extract_json("{" + response.choices[0].message.content) if model_card is None: - return MODEL_CARD_TEMPLATE + return json.loads(MODEL_CARD_TEMPLATE) return model_card