Spaces:
Running
Running
phyloforfun
commited on
Commit
•
a78800a
1
Parent(s):
9b82b76
add code
Browse files
vouchervision/LLM_chatGPT_3_5.py
CHANGED
@@ -47,6 +47,7 @@ def OCR_to_dict(is_azure, logger, MODEL, prompt, llm, prompt_version):
|
|
47 |
{"role": "system", "content": "You are a helpful assistant acting as a transcription expert and your job is to transcribe herbarium specimen labels based on OCR data and reformat it to meet Darwin Core Archive Standards into a Python dictionary based on certain rules."},
|
48 |
{"role": "user", "content": prompt},
|
49 |
],
|
|
|
50 |
max_tokens=4096,
|
51 |
)
|
52 |
# print the model's response
|
|
|
47 |
{"role": "system", "content": "You are a helpful assistant acting as a transcription expert and your job is to transcribe herbarium specimen labels based on OCR data and reformat it to meet Darwin Core Archive Standards into a Python dictionary based on certain rules."},
|
48 |
{"role": "user", "content": prompt},
|
49 |
],
|
50 |
+
response_format={type: "json_object"},#################################### TODO ###############################################################################
|
51 |
max_tokens=4096,
|
52 |
)
|
53 |
# print the model's response
|
vouchervision/prompt_catalog.py
CHANGED
@@ -710,7 +710,8 @@ class PromptCatalog:
|
|
710 |
|
711 |
# Generate the prompt using the loaded rules and structure
|
712 |
if is_palm:
|
713 |
-
prompt = f"""
|
|
|
714 |
You need to return coorect JSON for the following dictionary. Most likely, a quotation mark inside of a field value has not been escaped properly with a backslash.
|
715 |
Given the input, please generate a JSON response. Please note that the response should not contain any special characters, including quotation marks (single ' or double \"), within the JSON values.
|
716 |
Escape all JSON control characters that appear in input including ampersand (&) and other control characters.
|
@@ -720,9 +721,10 @@ class PromptCatalog:
|
|
720 |
The output JSON structure: {self.structure}
|
721 |
The output JSON structure: {self.structure}
|
722 |
The output JSON structure: {self.structure}
|
723 |
-
|
724 |
else:
|
725 |
-
prompt = f"""
|
|
|
726 |
You need to return coorect JSON for the following dictionary. Most likely, a quotation mark inside of a field value has not been escaped properly with a backslash.
|
727 |
Given the input, please generate a JSON response. Please note that the response should not contain any special characters, including quotation marks (single ' or double \"), within the JSON values.
|
728 |
Escape all JSON control characters that appear in input including ampersand (&) and other control characters.
|
@@ -730,7 +732,7 @@ class PromptCatalog:
|
|
730 |
Ensure the output JSON string is valid JSON format. It should not have trailing commas or unquoted keys.
|
731 |
The incorrectly formatted JSON dictionary: {incorrect_json}
|
732 |
The output JSON structure: {self.structure}
|
733 |
-
|
734 |
return prompt
|
735 |
|
736 |
#############################################################################################
|
|
|
710 |
|
711 |
# Generate the prompt using the loaded rules and structure
|
712 |
if is_palm:
|
713 |
+
prompt = f"""The incorrectly formatted JSON dictionary below is not valid. It contains an error that prevents it from loading with the Python command json.loads().
|
714 |
+
The incorrectly formatted JSON dictionary below is the literal string returned by a previous function and the error may be caused by markdown formatting.
|
715 |
You need to return coorect JSON for the following dictionary. Most likely, a quotation mark inside of a field value has not been escaped properly with a backslash.
|
716 |
Given the input, please generate a JSON response. Please note that the response should not contain any special characters, including quotation marks (single ' or double \"), within the JSON values.
|
717 |
Escape all JSON control characters that appear in input including ampersand (&) and other control characters.
|
|
|
721 |
The output JSON structure: {self.structure}
|
722 |
The output JSON structure: {self.structure}
|
723 |
The output JSON structure: {self.structure}
|
724 |
+
Please reformat the incorrectly formatted JSON dictionary given the output JSON structure: """
|
725 |
else:
|
726 |
+
prompt = f"""The incorrectly formatted JSON dictionary below is not valid. It contains an error that prevents it from loading with the Python command json.loads().
|
727 |
+
The incorrectly formatted JSON dictionary below is the literal string returned by a previous function and the error may be caused by markdown formatting.
|
728 |
You need to return coorect JSON for the following dictionary. Most likely, a quotation mark inside of a field value has not been escaped properly with a backslash.
|
729 |
Given the input, please generate a JSON response. Please note that the response should not contain any special characters, including quotation marks (single ' or double \"), within the JSON values.
|
730 |
Escape all JSON control characters that appear in input including ampersand (&) and other control characters.
|
|
|
732 |
Ensure the output JSON string is valid JSON format. It should not have trailing commas or unquoted keys.
|
733 |
The incorrectly formatted JSON dictionary: {incorrect_json}
|
734 |
The output JSON structure: {self.structure}
|
735 |
+
Please reformat the incorrectly formatted JSON dictionary given the output JSON structure: """
|
736 |
return prompt
|
737 |
|
738 |
#############################################################################################
|