Created
May 8, 2024 15:58
-
-
Save Muazzeem/7f5054311eea81cf28fb0cc93dea6944 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_json_from_text(text): | |
# Removing newline characters and backticks | |
clean_text = text.replace('\n', '').replace('`', '') | |
# Extracting JSON part | |
json_start_index = clean_text.find('{') | |
json_string = clean_text[json_start_index:] | |
# Parsing JSON | |
data = json.loads(json_string) | |
return data | |
## Uses | |
text = responses.candidates[0].content.parts[0].text | |
model_res = parse_json_from_text(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment