fix: Fix linting issues in examples (whitespace and imports)

This commit is contained in:
Kashyap Murali 2025-09-02 16:17:49 -07:00
parent 6f1513e7d2
commit 42909a5a0e
No known key found for this signature in database
2 changed files with 17 additions and 16 deletions

View file

@ -76,7 +76,7 @@ async def divide_numbers(args: dict[str, Any]) -> dict[str, Any]:
],
"is_error": True
}
result = args["a"] / args["b"]
return {
"content": [
@ -102,7 +102,7 @@ async def square_root(args: dict[str, Any]) -> dict[str, Any]:
],
"is_error": True
}
import math
result = math.sqrt(n)
return {
@ -131,7 +131,7 @@ async def power(args: dict[str, Any]) -> dict[str, Any]:
async def main():
"""Run example calculations using the SDK MCP server."""
# Create the calculator server with all tools
calculator = create_sdk_mcp_server(
name="calculator",
@ -145,14 +145,14 @@ async def main():
power
]
)
# Configure Claude to use the calculator server
options = ClaudeCodeOptions(
mcp_servers={"calc": calculator},
# Allow Claude to use calculator tools without permission prompts
permission_mode="bypassPermissions"
)
# Example prompts to demonstrate calculator usage
prompts = [
"Calculate 15 + 27",
@ -161,12 +161,12 @@ async def main():
"What is 2 raised to the power of 8?",
"Calculate (12 + 8) * 3 - 10" # Complex calculation
]
for prompt in prompts:
print(f"\n{'='*50}")
print(f"Prompt: {prompt}")
print(f"{'='*50}")
async for message in query(prompt=prompt, options=options):
# Print the message content
if hasattr(message, 'content'):
@ -178,4 +178,4 @@ async def main():
if __name__ == "__main__":
asyncio.run(main())
asyncio.run(main())

View file

@ -14,7 +14,7 @@ bash commands, edit files, search the web, fetch web content) to accomplish.
# BASIC STREAMING
# ============================================================================
from claude_code_sdk import ClaudeSDKClient, AssistantMessage, TextBlock, ResultMessage
from claude_code_sdk import AssistantMessage, ClaudeSDKClient, ResultMessage, TextBlock
async with ClaudeSDKClient() as client:
print("User: What is 2+2?")
@ -32,7 +32,8 @@ async with ClaudeSDKClient() as client:
# ============================================================================
import asyncio
from claude_code_sdk import ClaudeSDKClient, AssistantMessage, TextBlock
from claude_code_sdk import AssistantMessage, ClaudeSDKClient, TextBlock
async with ClaudeSDKClient() as client:
async def send_and_receive(prompt):
@ -53,7 +54,7 @@ async with ClaudeSDKClient() as client:
# PERSISTENT CLIENT FOR MULTIPLE QUESTIONS
# ============================================================================
from claude_code_sdk import ClaudeSDKClient, AssistantMessage, TextBlock
from claude_code_sdk import AssistantMessage, ClaudeSDKClient, TextBlock
# Create client
client = ClaudeSDKClient()
@ -88,8 +89,7 @@ await client.disconnect()
# IMPORTANT: Interrupts require active message consumption. You must be
# consuming messages from the client for the interrupt to be processed.
import asyncio
from claude_code_sdk import ClaudeSDKClient, AssistantMessage, TextBlock, ResultMessage
from claude_code_sdk import AssistantMessage, ClaudeSDKClient, TextBlock
async with ClaudeSDKClient() as client:
print("\n--- Sending initial message ---\n")
@ -141,7 +141,7 @@ async with ClaudeSDKClient() as client:
# ERROR HANDLING PATTERN
# ============================================================================
from claude_code_sdk import ClaudeSDKClient, AssistantMessage, TextBlock
from claude_code_sdk import AssistantMessage, ClaudeSDKClient, TextBlock
try:
async with ClaudeSDKClient() as client:
@ -168,7 +168,8 @@ except Exception as e:
# SENDING ASYNC ITERABLE OF MESSAGES
# ============================================================================
from claude_code_sdk import ClaudeSDKClient, AssistantMessage, TextBlock
from claude_code_sdk import AssistantMessage, ClaudeSDKClient, TextBlock
async def message_generator():
"""Generate multiple messages as an async iterable."""
@ -209,7 +210,7 @@ async with ClaudeSDKClient() as client:
# COLLECTING ALL MESSAGES INTO A LIST
# ============================================================================
from claude_code_sdk import ClaudeSDKClient, AssistantMessage, TextBlock, ResultMessage
from claude_code_sdk import AssistantMessage, ClaudeSDKClient, TextBlock
async with ClaudeSDKClient() as client:
print("User: What are the primary colors?")