Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
devjsc authored Nov 26, 2024
2 parents b4d0f3e + dbf41c1 commit d8ff95f
Show file tree
Hide file tree
Showing 40 changed files with 677 additions and 589 deletions.
52 changes: 22 additions & 30 deletions .github/spelling/check_spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@
jsx_like_tags_pattern = re.compile(r'<[^>]*>[\s\S]*?<\/[^>]*>|<[^>]*?/>', re.DOTALL)
path_pattern = re.compile(r'path:\s*"/[^"]*"')
guidebox_pattern = re.compile(r'<GuideBox[\s\S]*?/>', re.IGNORECASE)
hex_colours = re.compile(r'([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})')

# New patterns to remove content inside <GithubCodeSegment> and <CodeGroup> tags
github_code_segment_pattern = re.compile(r'<GithubCodeSegment[\s\S]*?</GithubCodeSegment>', re.IGNORECASE)
code_group_pattern = re.compile(r'<CodeGroup[\s\S]*?</CodeGroup>', re.IGNORECASE)

# Corrected word pattern to allow apostrophes in valid words
word_pattern = re.compile(r"\b\w+(?:'\w+)?\b")

# Pattern to exclude words containing escape sequences (\n, \u, etc.)
escape_sequence_pattern = re.compile(r'\\[nu][0-9a-fA-F]+|u[0-9a-fA-F]{4}')

# Function to extract text while ignoring specified components and handling code blocks differently
# Function to extract text while ignoring specified components and skipping code blocks
def extract_text_from_mdx(file_path):
with open(file_path, 'r') as file:
content = file.read()

# Remove content inside <GithubCodeSegment> and <CodeGroup> tags
content = github_code_segment_pattern.sub('', content)
content = code_group_pattern.sub('', content)

# Remove import statements
content = import_pattern.sub('', content)

Expand All @@ -46,20 +53,15 @@ def extract_text_from_mdx(file_path):
md = MarkdownIt()
parsed = md.parse(content)

# Extract text while separating code blocks for warnings
# Extract text while skipping code blocks
text = []
code_blocks = []
in_code_block = False

def traverse(node):
nonlocal in_code_block
if node.type == 'fence':
if not in_code_block:
code_blocks.append(node.content) # Capture code block content
in_code_block = not in_code_block
elif node.type == 'code_inline' and not in_code_block:
if node.type == 'fence': # Skip fenced code blocks
return
elif node.type == 'code_inline': # Skip inline code
return
elif node.type == 'text' and not in_code_block:
elif node.type == 'text':
text.append(node.content)

for child in node.children or []:
Expand All @@ -68,10 +70,10 @@ def traverse(node):
for node in parsed:
traverse(node)

return '\n'.join(text), code_blocks
return '\n'.join(text)

# Function to check for spelling errors
def check_spelling(text, is_code_block=False):
def check_spelling(text):
def split_underscore_words(word):
return re.split(r'[_\s]+', word)

Expand All @@ -89,7 +91,7 @@ def split_underscore_words(word):
css_value_pattern = re.compile(r'^\d+(px|%|em|rem|vh|vw|pt|cm|mm|in|s|ms|deg)?$') # CSS values
hex_color_pattern = re.compile(r'^(#?[A-Fa-f0-9]{3}|#?[A-Fa-f0-9]{6})$') # Hex colors
eth_address_pattern = re.compile(r'^0x[a-fA-F0-9]{40}$') # Ethereum addresses
hash_pattern = re.compile(r'^[a-f0-9]{40}$') # Hash-like strings (40 hex characters)
hash_pattern = re.compile(r'^[a-f0-9]{40}$') # Hash-like strings

# Filter out custom words, valid words with apostrophes,
# words matching escape sequences, "n-prefixed" words, CSS values, hex colors, ETH addresses, and hash strings
Expand All @@ -109,8 +111,8 @@ def split_underscore_words(word):
]
misspelled = spell.unknown(reduced_words)

# Return misspelled words with a flag indicating if they came from code
return misspelled if not is_code_block else {'warnings': misspelled}
# Return misspelled words
return misspelled

# Function to check all .mdx files in a directory
def check_directory(directory):
Expand All @@ -122,8 +124,8 @@ def check_directory(directory):
file_path = os.path.join(root, file)
print(f'========== Checking file: {file_path} ==========')

# Extract text and code blocks from the MDX file
text, code_blocks = extract_text_from_mdx(file_path)
# Extract text from the MDX file
text = extract_text_from_mdx(file_path)

# Check for spelling errors in text
errors = check_spelling(text)
Expand All @@ -133,21 +135,11 @@ def check_directory(directory):
print(f' - {error}')
has_errors = True

# Check for spelling errors in code blocks (warnings)
warnings = []
for code_block in code_blocks:
warnings = check_spelling(code_block, is_code_block=True).get('warnings', [])

if warnings:
print(f'Warnings (spelling errors in code block) in {file_path}:')
for warning in warnings:
print(f' - {warning}')

return has_errors

# Directory to check
directory_path = 'pages'
has_errors = check_directory(directory_path)

# Return False if errors were found
sys.exit(1 if has_errors else 0)
sys.exit(1 if has_errors else 0)
32 changes: 12 additions & 20 deletions .github/spelling/known_words_corpus.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
100atestfet
10px
14th
150p
1atestfet
9a
AA
ABI
API
APIs
APR
ASI
AVCTL
AVX2
AcceptChitChatDialogue
Agentic
Agentverse
AiEngine
Almanac
AlmanacContract
ApiResponses
Expand All @@ -33,8 +26,6 @@ BroadcastExampleResponse
CI
CL
CLI
CMA
CMD
CSV
CTRL
CW20
Expand Down Expand Up @@ -133,7 +124,6 @@ Liam
Linux
LocalWallet
London
London
Luke
ML
MM
Expand Down Expand Up @@ -384,7 +374,6 @@ defaultcredentialserror
delegator
delegators
deltagenerator
dff0d8
diff
dir
discoverability
Expand Down Expand Up @@ -439,9 +428,7 @@ geopy
getFunctionGroups
getMessages
getenv
github
gnews
google
googleapis
graphql
greaterThanOrEqualTo
Expand Down Expand Up @@ -572,8 +559,6 @@ pathlib
pb2
pc
pdfs
pg
pgdg120
phonebook
pk
pkill
Expand Down Expand Up @@ -715,8 +700,6 @@ useState
utc
utilising
utils
uuid
uuid4
uvicorn
v0
v1
Expand All @@ -742,9 +725,18 @@ www
x86
xlabel
xml
xvfb
xyz
ylabel
yml
yscale
zyx
GlobalResolver
ReceiverAgent
TESTFET
1FET
pg
IntervalCallback
abi
14th
zyx
nlp
CMA
AA
12 changes: 4 additions & 8 deletions .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,23 @@ jobs:
matrix:
python-version: [3.9]
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v2

# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

# Step 3: Install dependencies
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y aspell aspell-en # Install aspell and the English dictionary
sudo apt-get install -y aspell aspell-en
python -m pip install --upgrade pip
pip install spacy markdown-it-py pyspellchecker
python -m spacy download en_core_web_sm # Install spaCy language model
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m spacy download en_core_web_sm
# Step 4: Run the custom Python spell-checking script
- name: Run spell-check script
run: |
python .github/spelling/check_spelling.py || exit 1
set -e
python .github/spelling/check_spelling.py
3 changes: 1 addition & 2 deletions pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"concepts": "Concepts",
"guides": "Guides",
"examples": {
"title": "Examples",
"href": "examples/first-agent"
"title": "Examples"
},
"references": "References",
"apis": "APIs"
Expand Down
15 changes: 12 additions & 3 deletions pages/examples/_meta.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"easy": {
"title": "Easy Topics"
"title": "Easy Topics",
"theme": {
"collapsed": false
}
},
"intermediate": {
"title": "Intermediate Topics"
"title": "Intermediate Topics",
"theme": {
"collapsed": false
}
},
"advanced": {
"title": "Advanced Topics"
"title": "Advanced Topics",
"theme": {
"collapsed": false
}
},
"postgres-database-with-an-agent": {
"title": "Postgres Database with an Agent",
Expand Down
10 changes: 5 additions & 5 deletions pages/examples/advanced/_meta.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"open-dialogue-chitchat": {
"title": "Open Dialogue Chit-Chat",
"tags": ["Advanced", "Python", "Dialogues", "Use cases"],
"tags": ["Advanced", "Python", "Dialogues", "Use cases", "Local"],
"timestamp": true
},
"predefined-dialogue-chitchat": {
"title": "Predefined Dialogue Chit-Chat",
"tags": ["Advanced", "Python", "Dialogues", "Use cases"],
"tags": ["Advanced", "Python", "Dialogues", "Use cases", "Local"],
"timestamp": true
},
"async-loops": {
"title": "Asynchronous Loops",
"tags": ["Advanced", "Python", "Communication", "Use Cases"],
"tags": ["Advanced", "Python", "Communication", "Use Cases", "Local"],
"timestamp": true
},
"chat_api_example": {
"title": "Chat API example",
"tags": ["Advanced", "Python", "Dialogues", "Use cases"],
"tags": ["Advanced", "Python", "Dialogues", "Use cases", "Hosted"],
"timestamp": true
},
"deltaV-dialogues": {
"title": "DeltaV Dialogue Chit-Chat",
"tags": ["Advanced", "Python", "Dialogues", "DeltaV"],
"tags": ["Advanced", "Python", "Dialogues", "DeltaV", "Hosted"],
"timestamp": true
}
}
2 changes: 1 addition & 1 deletion pages/examples/advanced/chat_api_example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ while True:
last_question = current_message_text.split('?')[0] if '?' in current_message_text else current_message_text
```

Save this script as chatAPI.py and replace email and fauna_token in the script.
Save this script as `chatAPI.py` and replace `email` and `fauna_token` in the script.

Running this app on the terminal:

Expand Down
2 changes: 1 addition & 1 deletion pages/examples/intermediate/langchain-rag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class RagRequest(Model):

### Langchain RAG agent

This agent answers questions by fetching and summarizing information from a given website. It checks and scrapes URLs, uses LangChain to find important documents, and generates answers with OpenAI's GPT-4o-mini model.
This agent answers questions by fetching and summarizing information from a given website. It checks and scrapes URLs, uses LangChain to find important documents, and generates answers with OpenAI's GPT-40-mini model.

<CodeGroup hasCopy isLocalHostedFile>
<DocsCode local={true}>
Expand Down
Loading

0 comments on commit d8ff95f

Please sign in to comment.