from wiktionaryparser import WiktionaryParser def get_word_definitions(word): parser = WiktionaryParser() word_data = parser.fetch(word) result = '' if word_data: word_data = word_data[0] # Get definitions if 'definitions' in word_data.keys() and len(word_data['definitions'])>0: result += f"Definitions of '{word}':\n" for definition in word_data['definitions']: if 'text' in definition.keys(): result += "- " + "\n ".join(definition['text']) + "\n" # Get example sentences if 'examples' in word_data.keys(): result += f"\nExample sentences with '{word}':\n" for example in word_data['examples']: if 'text' in example.keys(): result += "- " + example['text'] + "\n" if len (result) < 12: return False else: openai return result # Example usage word = 'overstep the mark' word_definitions = get_word_definitions(word) print(word_definitions)