Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from Gradio_UI import GradioUI
|
|
| 10 |
|
| 11 |
import json
|
| 12 |
@tool
|
| 13 |
-
def text_to_json(text: str, json_schema: dict) ->
|
| 14 |
"""
|
| 15 |
Uses an LLM to transform the information of plain text into structured data using a JSON schema.
|
| 16 |
|
|
@@ -19,7 +19,7 @@ def text_to_json(text: str, json_schema: dict) -> dict:
|
|
| 19 |
json_schema (dict): The JSON schema that defines the structure of the valid JSON.
|
| 20 |
|
| 21 |
Returns:
|
| 22 |
-
|
| 23 |
|
| 24 |
Example:
|
| 25 |
>>> text = "John Doe, 30 years old, lives in New York and works as a software engineer."
|
|
@@ -47,9 +47,8 @@ def text_to_json(text: str, json_schema: dict) -> dict:
|
|
| 47 |
{"role": "system", "content": "You are an assistant that converts text into JSON. Convert the provided text into a JSON object based on the provided schema. JSON_SCHEMA:\n```json " + json.dumps(json_schema) + "```"},
|
| 48 |
{"role": "user", "content": text},
|
| 49 |
]
|
| 50 |
-
data= model(messages, response_format={"type": "json_object", "schema": json_schema}).content
|
| 51 |
-
|
| 52 |
-
return json.loads(data)
|
| 53 |
|
| 54 |
|
| 55 |
@tool
|
|
|
|
| 10 |
|
| 11 |
import json
|
| 12 |
@tool
|
| 13 |
+
def text_to_json(text: str, json_schema: dict) -> str:
|
| 14 |
"""
|
| 15 |
Uses an LLM to transform the information of plain text into structured data using a JSON schema.
|
| 16 |
|
|
|
|
| 19 |
json_schema (dict): The JSON schema that defines the structure of the valid JSON.
|
| 20 |
|
| 21 |
Returns:
|
| 22 |
+
str: A valid JSON string.
|
| 23 |
|
| 24 |
Example:
|
| 25 |
>>> text = "John Doe, 30 years old, lives in New York and works as a software engineer."
|
|
|
|
| 47 |
{"role": "system", "content": "You are an assistant that converts text into JSON. Convert the provided text into a JSON object based on the provided schema. JSON_SCHEMA:\n```json " + json.dumps(json_schema) + "```"},
|
| 48 |
{"role": "user", "content": text},
|
| 49 |
]
|
| 50 |
+
data = model(messages, response_format={"type": "json_object", "schema": json_schema}).content
|
| 51 |
+
return data
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
@tool
|