update to allow model version to be changed
Browse files
app.py
CHANGED
|
@@ -100,7 +100,7 @@ class FarmActivities(BaseModel):
|
|
| 100 |
# TBD
|
| 101 |
|
| 102 |
# This is to make stuff happen
|
| 103 |
-
def generate_json(specification):
|
| 104 |
"""
|
| 105 |
Function to prompt OpenAI API to generate structured JSON output.
|
| 106 |
"""
|
|
@@ -108,7 +108,7 @@ def generate_json(specification):
|
|
| 108 |
try:
|
| 109 |
# Call OpenAI API to generate structured output based on prompt
|
| 110 |
response = client.beta.chat.completions.parse(
|
| 111 |
-
model=
|
| 112 |
messages=[
|
| 113 |
{"role": "system", "content": "Extract the farm information."},
|
| 114 |
{"role": "user", "content": specification}
|
|
@@ -132,15 +132,16 @@ def generate_json(specification):
|
|
| 132 |
return {"error": "Failed to generate valid JSON. " + str(e)}
|
| 133 |
|
| 134 |
|
| 135 |
-
def process_specifications(data):
|
| 136 |
# This method just drives the process
|
| 137 |
-
resulting_schema = generate_json(data)
|
| 138 |
return resulting_schema
|
| 139 |
|
| 140 |
|
| 141 |
demo = gr.Interface(
|
| 142 |
fn=process_specifications,
|
| 143 |
inputs=[gr.Textbox(label="Enter your data")],
|
|
|
|
| 144 |
outputs=[gr.Textbox(label="JSON Data Output")],
|
| 145 |
title="JSON Schema Data Translation Unstructured to Structured Data",
|
| 146 |
description="Input your data, receive the JSON Schema!",
|
|
|
|
| 100 |
# TBD
|
| 101 |
|
| 102 |
# This is to make stuff happen
|
| 103 |
+
def generate_json(specification, model_version):
|
| 104 |
"""
|
| 105 |
Function to prompt OpenAI API to generate structured JSON output.
|
| 106 |
"""
|
|
|
|
| 108 |
try:
|
| 109 |
# Call OpenAI API to generate structured output based on prompt
|
| 110 |
response = client.beta.chat.completions.parse(
|
| 111 |
+
model=model_version, # Use GPT model that supports structured output
|
| 112 |
messages=[
|
| 113 |
{"role": "system", "content": "Extract the farm information."},
|
| 114 |
{"role": "user", "content": specification}
|
|
|
|
| 132 |
return {"error": "Failed to generate valid JSON. " + str(e)}
|
| 133 |
|
| 134 |
|
| 135 |
+
def process_specifications(data, model_version):
|
| 136 |
# This method just drives the process
|
| 137 |
+
resulting_schema = generate_json(data, model_version)
|
| 138 |
return resulting_schema
|
| 139 |
|
| 140 |
|
| 141 |
demo = gr.Interface(
|
| 142 |
fn=process_specifications,
|
| 143 |
inputs=[gr.Textbox(label="Enter your data")],
|
| 144 |
+
gr.Radio(["gpt-4o-2024-08-06", "gpt-4o-mini-2024-07-18"], label="Model Versions", info="Mini is a smaller version for faster responses")
|
| 145 |
outputs=[gr.Textbox(label="JSON Data Output")],
|
| 146 |
title="JSON Schema Data Translation Unstructured to Structured Data",
|
| 147 |
description="Input your data, receive the JSON Schema!",
|