diff --git a/skills/dicto/README.md b/skills/dicto/README.md new file mode 100644 index 00000000..6e25e8b8 --- /dev/null +++ b/skills/dicto/README.md @@ -0,0 +1,46 @@ +# šŸ“š Dicto - Dictionary Lookup Skill + +Dicto is a skill for looking up English word definitions using the free [DictionaryAPI](https://dictionaryapi.dev). It returns detailed definitions, parts of speech, example usages, and a fallback Google link for further lookup. + +## šŸ” Features + +- Look up definitions of English words +- Part of speech identification (e.g., noun, verb) +- Example usages when available +- Fallback to Google definition search if no definitions are found + +--- + +## šŸš€ How It Works + +When a user inputs a word (e.g., `run`), Dicto performs a search for said word and provides the user with relevant information relating to searched word + +User: run +Dicto: šŸ” Looking up "run" +šŸ“– Definition: To move swiftly on foot. +Verb: To run. +Noun: An act or instance of running. (Example: I went for a quick run this morning.) +Noun: A trip or errand. (Example: I'm making a run to the store. +View More on Dictionary: https://www.google.com/search?q=define+run + +If the word is not found or an error occurs, Dicto informs the user and provides a Google search link as an alternative. + +User: htftya +Dicto: Sorry, we couldn't find a definition for "htftya" in `en`. +View More on Dictionary: https://www.google.com/search?q=htftya + + +--- + +## šŸ“ File Structure + +dicto/ +ā”œā”€ā”€ base.py +ā”œā”€ā”€ word_lookup.py +ā”œā”€ā”€ __init__.py +ā”œā”€ā”€ schema.json +ā”œā”€ā”€ test_skill.py +ā”œā”€ā”€ dicto.png +└── README.md + + diff --git a/skills/dicto/__init__.py b/skills/dicto/__init__.py new file mode 100644 index 00000000..01ccd0af --- /dev/null +++ b/skills/dicto/__init__.py @@ -0,0 +1,6 @@ +from .word_lookup import LookupWord + +def get_skills(): + return { + "word_lookup": LookupWord, + } diff --git a/skills/dicto/base.py b/skills/dicto/base.py new file mode 100644 index 00000000..7fae3a0d --- /dev/null +++ b/skills/dicto/base.py @@ -0,0 +1,35 @@ +import requests + +class DictionarySkillBase: + SUPPORTED_LANGUAGES = { + "en": "English", + "es": "Spanish", + "fr": "French", + "de": "German", + "it": "Italian", + "ja": "Japanese", + "ru": "Russian", + "ko": "Korean", + "pt-BR": "Portuguese (Brazil)", + "hi": "Hindi", + "tr": "Turkish" + } + + def __init__(self, config=None): + self.api_url = "https://api.dictionaryapi.dev/api/v2/entries/" + self.default_lang = (config or {}).get("language", "en") + if self.default_lang not in self.SUPPORTED_LANGUAGES: + print(f"āš ļø Unsupported default language: {self.default_lang}. Falling back to English.") + self.default_lang = "en" + + def fetch_word_data(self, word: str, lang: str = None): + lang_code = lang or self.default_lang + if lang_code not in self.SUPPORTED_LANGUAGES: + return None + try: + response = requests.get(f"{self.api_url}{lang_code}/{word}", timeout=5) + if response.status_code == 200: + return response.json() + except requests.RequestException as e: + print(f"Request error: {e}") + return None diff --git a/skills/dicto/dicto.png b/skills/dicto/dicto.png new file mode 100644 index 00000000..e9ddd11e Binary files /dev/null and b/skills/dicto/dicto.png differ diff --git a/skills/dicto/models.py b/skills/dicto/models.py new file mode 100644 index 00000000..91c2c7a4 --- /dev/null +++ b/skills/dicto/models.py @@ -0,0 +1,9 @@ +from pydantic import BaseModel +from typing import Optional + +class DictoInput(BaseModel): + word: str + lang: Optional[str] = "en" + +class DictoOutput(BaseModel): + result: str diff --git a/skills/dicto/schema.json b/skills/dicto/schema.json new file mode 100644 index 00000000..f2d7c39d --- /dev/null +++ b/skills/dicto/schema.json @@ -0,0 +1,47 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "Dictionary Lookup Skill", + "description": "Looks up a word's definition, part of speech, and example usage from a free dictionary.", + "x-icon": "https://raw.githubusercontent.com/Negred0/intentkit/main/skills/dicto/dicto.png", + "x-tags": [ + "Language", + "Utility" + ], + "x-api-key": "none", + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "Enable or disable the Dictionary Lookup Skill", + "default": true + }, + "states": { + "type": "object", + "properties": { + "word_lookup": { + "type": "string", + "title": "Word Lookup Access", + "enum": [ + "disabled", + "public", + "private" + ], + "x-enum-title": [ + "Disabled", + "Agent Owner + All Users", + "Agent Owner Only" + ], + "description": "Controls who can use the dictionary lookup functionality", + "default": "public" + } + }, + "description": "Controls access level for the dictionary lookup functionality" + } + }, + "required": [ + "enabled", + "states" + ], + "additionalProperties": true +} diff --git a/skills/dicto/word_lookup.py b/skills/dicto/word_lookup.py new file mode 100644 index 00000000..a58a22f7 --- /dev/null +++ b/skills/dicto/word_lookup.py @@ -0,0 +1,24 @@ +from abstracts.skill import IntentKitSkill +from .models import DictoInput, DictoOutput +import requests + +class DictoSkill(IntentKitSkill): + name: str = "dicto" + description: str = "Looks up dictionary definitions for a given word." + args_schema = DictoInput + + def _run(self, word: str, lang: str = "en") -> DictoOutput: + word = word.strip().lower() + if not word: + return DictoOutput(result="Please provide a word to define.") + + try: + response = requests.get(f"https://api.dictionaryapi.dev/api/v2/entries/{lang}/{word}") + if response.status_code != 200: + raise ValueError("Word not found.") + data = response.json() + definitions = data[0]['meanings'][0]['definitions'][0]['definition'] + result = f"šŸ” Looking up \"{word}\"\nšŸ“– Definition: {definitions}\n\nView More on Dictionary: https://www.google.com/search?q=define+{word}" + return DictoOutput(result=result) + except Exception as e: + return DictoOutput(result=f"Sorry, we couldn't find a definition for \"{word}\" in `{lang}`.\n\nView More on Dictionary: https://www.google.com/search?q=define+{word}")