-
Notifications
You must be signed in to change notification settings - Fork 2
Separate example codes from README and add OpenAI, Claude, MCP examples #23
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a01fec
Initial plan for issue
Copilot a32fbc7
Separate examples from README and add OpenAI, Claude, MCP examples
Copilot 482f667
Restore basic usage instructions to README while maintaining examples…
Copilot d345923
Fix Python 3.9 compatibility issues in test_examples.py
Copilot da1782c
Fix Python 3.9 compatibility issue with isinstance and subscripted ge…
Copilot 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
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,95 @@ | ||
| # Function Schema Examples | ||
|
|
||
| This directory contains practical examples of how to use the `function-schema` library with various AI platforms and protocols. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### 🔧 Basic Usage (`basic_usage.py`) | ||
| Demonstrates the fundamental features of function-schema: | ||
| - Creating functions with type annotations and Doc metadata | ||
| - Generating JSON schemas | ||
| - Using enums and Literal types for parameter constraints | ||
| - Different annotation styles | ||
|
|
||
| **Run:** `python examples/basic_usage.py` | ||
|
|
||
| ### 🤖 OpenAI Integration (`openai_example.py`) | ||
| Shows how to integrate with OpenAI's APIs: | ||
| - Assistant API with tool calling | ||
| - Chat Completion API with function calling | ||
| - Multiple tool definitions | ||
|
|
||
| **Run:** `python examples/openai_example.py` | ||
|
|
||
| ### 🧠 Claude Integration (`claude_example.py`) | ||
| Demonstrates Anthropic Claude tool calling: | ||
| - Basic tool calling setup | ||
| - Multi-turn conversations with tools | ||
| - Claude-specific schema format | ||
|
|
||
| **Run:** `python examples/claude_example.py` | ||
|
|
||
| ### 📟 CLI Usage (`cli_example.py`) | ||
| Examples of using the command-line interface: | ||
| - Generating schemas from Python files | ||
| - Different output formats | ||
| - Working with multiple functions | ||
|
|
||
| **Test the CLI:** | ||
| ```bash | ||
| # Install the package first | ||
| pip install -e . | ||
|
|
||
| # Generate schema for a function | ||
| function_schema examples/cli_example.py get_weather | ||
|
|
||
| # Generate with pretty JSON formatting | ||
| function_schema examples/cli_example.py get_weather | jq | ||
|
|
||
| # Generate for Claude format | ||
| function_schema examples/cli_example.py get_weather claude | ||
| ``` | ||
|
|
||
| ### 🔌 MCP Integration (`mcp_example.py`) | ||
| Shows integration with Model Context Protocol: | ||
| - Creating MCP-compatible tool definitions | ||
| - Server manifest generation | ||
| - Tool calling examples | ||
| - Resource access patterns | ||
|
|
||
| **Run:** `python examples/mcp_example.py` | ||
|
|
||
| ## Running the Examples | ||
|
|
||
| 1. **Install the package:** | ||
| ```bash | ||
| pip install -e . | ||
| ``` | ||
|
|
||
| 2. **Run any example:** | ||
| ```bash | ||
| python examples/basic_usage.py | ||
| python examples/openai_example.py | ||
| python examples/claude_example.py | ||
| python examples/mcp_example.py | ||
| ``` | ||
|
|
||
| 3. **Test CLI functionality:** | ||
| ```bash | ||
| function_schema examples/cli_example.py get_weather | ||
| ``` | ||
|
|
||
| ## Integration Notes | ||
|
|
||
| - **OpenAI**: Requires `openai` library and API key for actual usage | ||
| - **Claude**: Requires `anthropic` library and API key for actual usage | ||
| - **MCP**: Conceptual example showing schema compatibility | ||
| - **CLI**: Works out of the box with the installed package | ||
|
|
||
| ## Schema Formats | ||
|
|
||
| The library supports multiple output formats: | ||
| - **OpenAI format** (default): Uses `parameters` key | ||
| - **Claude format**: Uses `input_schema` key | ||
|
|
||
| Specify format with: `get_function_schema(func, "claude")` |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to leave the most basic usage instructions in the readme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added basic usage instructions back to the README. The main usage section now shows the complete flow from function definition to schema generation with example output, addressing the feedback to keep essential instructions in the README itself. Commit 482f667.