update for errors in current version app
Browse files
app.py
CHANGED
|
@@ -16,12 +16,13 @@ def model1_translate_to_graph(request_text):
|
|
| 16 |
The output is expected to be in JSON format with "nodes" and "edges".
|
| 17 |
"""
|
| 18 |
prompt = (
|
| 19 |
-
"Translate the following customer request into a structured graph in JSON format.
|
| 20 |
-
"The JSON should have two keys: 'nodes' (a list of node names)
|
|
|
|
| 21 |
f"Customer Request: \"{request_text}\"\n"
|
| 22 |
"Structured Graph JSON:"
|
| 23 |
)
|
| 24 |
-
output = model1_generator(prompt,
|
| 25 |
return output
|
| 26 |
|
| 27 |
def model2_generate_response(graph_description):
|
|
@@ -33,7 +34,7 @@ def model2_generate_response(graph_description):
|
|
| 33 |
f"Structured Graph: {graph_description}\n"
|
| 34 |
"Response:"
|
| 35 |
)
|
| 36 |
-
output = model2_generator(prompt,
|
| 37 |
return output
|
| 38 |
|
| 39 |
def model3_response_to_graph(response_text):
|
|
@@ -41,11 +42,13 @@ def model3_response_to_graph(response_text):
|
|
| 41 |
Model 3: Convert the textual response into a structured graph description (JSON format) of the response.
|
| 42 |
"""
|
| 43 |
prompt = (
|
| 44 |
-
"Translate the following response into a structured graph in JSON format.
|
|
|
|
|
|
|
| 45 |
f"Response: \"{response_text}\"\n"
|
| 46 |
"Structured Response Graph JSON:"
|
| 47 |
)
|
| 48 |
-
output = model3_generator(prompt,
|
| 49 |
return output
|
| 50 |
|
| 51 |
def try_parse_json(text):
|
|
@@ -54,7 +57,7 @@ def try_parse_json(text):
|
|
| 54 |
If parsing fails, return None.
|
| 55 |
"""
|
| 56 |
try:
|
| 57 |
-
#
|
| 58 |
start = text.find('{')
|
| 59 |
end = text.rfind('}') + 1
|
| 60 |
json_str = text[start:end]
|
|
|
|
| 16 |
The output is expected to be in JSON format with "nodes" and "edges".
|
| 17 |
"""
|
| 18 |
prompt = (
|
| 19 |
+
"Translate the following customer request into a structured graph in valid JSON format. "
|
| 20 |
+
"Output only the JSON and nothing else. The JSON should have two keys: 'nodes' (a list of node names) "
|
| 21 |
+
"and 'edges' (a list of pairs, where each pair is a list of two node names representing a directed edge).\n"
|
| 22 |
f"Customer Request: \"{request_text}\"\n"
|
| 23 |
"Structured Graph JSON:"
|
| 24 |
)
|
| 25 |
+
output = model1_generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)[0]['generated_text']
|
| 26 |
return output
|
| 27 |
|
| 28 |
def model2_generate_response(graph_description):
|
|
|
|
| 34 |
f"Structured Graph: {graph_description}\n"
|
| 35 |
"Response:"
|
| 36 |
)
|
| 37 |
+
output = model2_generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)[0]['generated_text']
|
| 38 |
return output
|
| 39 |
|
| 40 |
def model3_response_to_graph(response_text):
|
|
|
|
| 42 |
Model 3: Convert the textual response into a structured graph description (JSON format) of the response.
|
| 43 |
"""
|
| 44 |
prompt = (
|
| 45 |
+
"Translate the following response into a structured graph in valid JSON format. "
|
| 46 |
+
"Output only the JSON. The JSON should have two keys: 'nodes' (a list of concept names) "
|
| 47 |
+
"and 'edges' (a list of relationships as pairs of node names).\n"
|
| 48 |
f"Response: \"{response_text}\"\n"
|
| 49 |
"Structured Response Graph JSON:"
|
| 50 |
)
|
| 51 |
+
output = model3_generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)[0]['generated_text']
|
| 52 |
return output
|
| 53 |
|
| 54 |
def try_parse_json(text):
|
|
|
|
| 57 |
If parsing fails, return None.
|
| 58 |
"""
|
| 59 |
try:
|
| 60 |
+
# Extract from the first '{' to the last '}'
|
| 61 |
start = text.find('{')
|
| 62 |
end = text.rfind('}') + 1
|
| 63 |
json_str = text[start:end]
|