Skip to content

Commit

Permalink
update prompts and data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dgauldie committed Sep 12, 2024
1 parent 2663206 commit b4427bd
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 45 deletions.
2 changes: 2 additions & 0 deletions api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ async def configure_model_from_document(input_model: ConfigureModelDocument):
@app.post("/model_card")
async def model_card(input_model: ModelCardModel):
try:
amr = input_model.amr
research_paper = input_model.research_paper
response = await model_card_chain(
amr=amr,
research_paper=research_paper
) # Use await here
response = {"response": response}
Expand Down
3 changes: 2 additions & 1 deletion gollm/openai/prompts/config_from_document.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CONFIGURE_FROM_DOCUMENT_PROMPT = """
You are a helpful agent designed to find multiple model configurations for a given AMR model of various conditions described in a research paper.
You are a helpful agent designed to find multiple model configurations for a given AMR model of various conditions described in a research paper and the initials and parameters that make up those conditions.
For context, initials represent the initial state of the system through the initial distribution of tokens across the places, known as the initial marking. Each place corresponds to a variable or state in the system, such as a species concentration in a reaction, and the number of tokens reflects the initial conditions of the ODEs. Parameters define the system's rules and rates of evolution, including transition rates (analogous to reaction rates in ODEs) that determine how quickly tokens move between places. These parameters also include stoichiometric relationships, represented by the weights of arcs connecting places and transitions, dictating how many tokens are consumed or produced when a transition occurs.
Use the following AMR model JSON file as a reference:
Expand Down
4 changes: 2 additions & 2 deletions gollm/openai/prompts/model_card.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
INSTRUCTIONS = """
You are a helpful agent designed to populate metadata of a given AMR model.
You may have access to a document that describes the given AMR model and a JSON representation of the AMR model. Structural information should come from the AMR model.
You may have access to a document that describes the given AMR model and a JSON representation of the AMR model we want populated. Structural information should come from the AMR model.
You may only have access to the model. Do your best to populate the JSON object specified in the response format with as much information as possible.
If you cannot answer the entire query, provide as much information as possible. If there is no answer, use the string "null" as a placeholder.
If you cannot answer the entire query, provide as much information as possible. If there is no answer, populate fields with a null values. Do not leave any fields empty and do not make up information.
Use the following document as a reference:
Expand Down
80 changes: 58 additions & 22 deletions gollm/openai/schemas/model_card.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"modelSummary": {
"type": "string",
"description": "A brief description of the system or process."
"summary": {
"type": "object",
"properties": {
"modelSummary": {
"type": "string",
"description": "A brief description of the system or process."
}
},
"required": [
"modelSummary"
],
"additionalProperties": false
},
"modelDetails": {
"details": {
"type": "object",
"properties": {
"modelDescription": {
Expand Down Expand Up @@ -48,30 +57,57 @@
"additionalProperties": false
},
"biasRisksLimitations": {
"type": "string",
"description": "Describe sources of bias and risk based on the research paper"
"type": "object",
"properties": {
"modelBiasRisksLimitations": {
"type": "string",
"description": "Describe sources of bias and risk based on the research paper"
}
},
"required": [
"modelBiasRisksLimitations"
],
"additionalProperties": false
},
"testingDataFactorsMetrics": {
"type": "string",
"description": "Describe how the model was validated, e.g., through simulation, comparison with real-world data, etc."
"testing": {
"type": "object",
"properties": {
"testingDataFactorsMetrics": {
"type": "string",
"description": "Describe how the model was validated, e.g., through simulation, comparison with real-world data, etc."
}
},
"required": [
"testingDataFactorsMetrics"
],
"additionalProperties": false
},
"modelSpecs": {
"type": "string",
"description": "Details about the model's complexity, such as the number of places, transitions, parameter count, and arcs."
"specs": {
"type": "object",
"properties": {
"modelSpecs": {
"type": "string",
"description": "Details about the model's complexity, such as the number of places, transitions, parameter count, and arcs."
}
},
"required": [
"modelSpecs"
],
"additionalProperties": false
},
"glossary": {
"type": "array",
"items": {
"type": "string"
}
},
"modelCardAuthors": {
"authors": {
"type": "array",
"items": {
"type": "string"
}
},
"howToGetStartedWithTheModel": {
"gettingStarted": {
"type": "object",
"properties": {
"examples": {
Expand All @@ -86,7 +122,7 @@
],
"additionalProperties": false
},
"citation": {
"citations": {
"type": "object",
"properties": {
"references": {
Expand Down Expand Up @@ -165,16 +201,16 @@
}
},
"required": [
"modelSummary",
"modelDetails",
"summary",
"details",
"uses",
"biasRisksLimitations",
"testingDataFactorsMetrics",
"modelSpecs",
"testing",
"specs",
"glossary",
"modelCardAuthors",
"howToGetStartedWithTheModel",
"citation",
"authors",
"gettingStarted",
"citations",
"moreInformation",
"structuralInformation"
],
Expand Down
41 changes: 21 additions & 20 deletions gollm/openai/tool_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))


def escape_curly_braces(text: str):
"""
Escapes curly braces in a string.
Expand Down Expand Up @@ -82,26 +83,26 @@ def model_config_from_document(research_paper: str, amr: str) -> dict:
return model_config_adapter(output_json)


def amr_enrichment_chain(amr: str, research_paper:str) -> dict:
def amr_enrichment_chain(amr: str, research_paper: str) -> dict:
amr_param_states = parse_param_initials(amr)
prompt = ENRICH_PROMPT.format(
param_initial_dict=amr_param_states,
paper_text=escape_curly_braces(research_paper)
)
param_initial_dict=amr_param_states,
paper_text=escape_curly_braces(research_paper)
)
client = OpenAI()
output = client.chat.completions.create(
model="gpt-4o-2024-05-13",
max_tokens=4000,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
seed=123,
temperature=0,
response_format={"type": "json_object"},
messages=[
{"role": "user", "content": prompt},
],
)
model="gpt-4o-2024-05-13",
max_tokens=4000,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
seed=123,
temperature=0,
response_format={"type": "json_object"},
messages=[
{"role": "user", "content": prompt},
],
)
return postprocess_oai_json(output.choices[0].message.content)


Expand All @@ -125,7 +126,7 @@ def model_card_chain(amr: str = None, research_paper: str = None) -> dict:
client = OpenAI()
output = client.chat.completions.create(
model="gpt-4o-2024-08-06",
temperature=0,
temperature=0,
frequency_penalty=0,
max_tokens=4000,
presence_penalty=0,
Expand Down Expand Up @@ -162,7 +163,7 @@ def condense_chain(query: str, chunks: List[str], max_tokens: int = 16385) -> st
top_p=1,
frequency_penalty=0,
presence_penalty=0,
temperature=0,
temperature=0,
seed=123,
max_tokens=1024,
messages=[
Expand All @@ -180,7 +181,7 @@ def generate_response(instruction: str, response_format: ResponseFormat | None =
top_p=1,
frequency_penalty=0,
presence_penalty=0,
temperature=0,
temperature=0,
seed=123,
max_tokens=2048,
response_format=response_format,
Expand Down Expand Up @@ -261,7 +262,7 @@ def compare_models(amrs: List[str]) -> str:
frequency_penalty=0,
presence_penalty=0,
seed=123,
temperature=0,
temperature=0,
max_tokens=2048,
messages=[
{"role": "user", "content": prompt},
Expand Down

0 comments on commit b4427bd

Please sign in to comment.