-
Notifications
You must be signed in to change notification settings - Fork 705
Dictionary Word Lookup Skill - dicto #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Negred0
wants to merge
8
commits into
crestalnetwork:main
Choose a base branch
from
Negred0:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d904de3
Dictionary Word Lookup Skill - dicto
84ba130
Update README.md
Negred0 24e86bd
Update word_lookup.py
Negred0 434dda5
Create models.py
Negred0 5e17bb1
Update word_lookup.py
Negred0 0e5c518
Merge branch 'main' into main
bluntbrain 434139b
Delete skills/dicto/test_skill.py
Negred0 6a8ecb4
Update schema.json
Negred0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from .word_lookup import LookupWord | ||
|
|
||
| def get_skills(): | ||
| return { | ||
| "word_lookup": LookupWord, | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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://cdn-icons-png.flaticon.com/512/2845/2845980.png", // <-- replace with your own icon if needed | ||
| "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 | ||
| } | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from word_lookup import LookupWord | ||
|
Negred0 marked this conversation as resolved.
Outdated
|
||
|
|
||
| def test_skill(): | ||
| # Initialize the skill (you can pass the config if needed) | ||
| skill = LookupWord() | ||
|
|
||
| # Test inputs (you can modify this list to test more words) | ||
| test_inputs = [ | ||
| "bonjour", # French word | ||
| "Jack", | ||
| "actor", | ||
| "FAN", | ||
| "JUPITER", | ||
| "run", # English word | ||
| "comer es bueno", # Spanish phrase (note: only the first word 'comer' will be considered) | ||
| "geschirrspüler", # German word | ||
| "ありがとう", # Japanese word | ||
| "serendipity", # English word | ||
| ] | ||
|
|
||
| # Test each input | ||
| for input_text in test_inputs: | ||
| print(f"Testing word: {input_text}") | ||
| response = skill.run(input_text) | ||
| print(f"Response: {response}\n") | ||
|
|
||
| if __name__ == "__main__": | ||
| test_skill() | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.