-
Notifications
You must be signed in to change notification settings - Fork 40
Fixture testdatapath, refactor and unify testdatapath handling #147
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5269b3b
fix the duplication and inconsistency in testdata path computation an…
bmerkle e3496a6
fix the duplication and inconsistency in testdata path computation an…
bmerkle 6a85f9e
Refactor podcast ingestion and query tools:
bmerkle 18c7c8d
- moved all unit tests from tests/test to tests
bmerkle 75a5f49
The fixture was creating a minimal environment with only API keys, bu…
bmerkle 9c95319
- Add environment variable handling for authentication in test_mcp_se…
bmerkle 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| import argparse | ||
| from dataclasses import dataclass | ||
| import os | ||
| import time | ||
| from typing import Any | ||
|
|
||
|
|
@@ -28,6 +29,9 @@ | |
| from typeagent.storage.memory.semrefindex import TermToSemanticRefIndex | ||
| from typeagent.storage.utils import create_storage_provider | ||
|
|
||
| # Example podcast index path for documentation and error messages | ||
| _EXAMPLE_PODCAST_INDEX = "tests/testdata/Episode_53_AdrianTchaikovsky_index" | ||
|
|
||
|
|
||
| class MCPTypeChatModel(typechat.TypeChatLanguageModel): | ||
| """TypeChat language model that uses MCP sampling API instead of direct API calls.""" | ||
|
|
@@ -142,7 +146,9 @@ async def make_context( | |
| entities_top_k=50, topics_top_k=50, messages_top_k=None, chunking=None | ||
| ) | ||
|
|
||
| query_context = await load_podcast_index_or_database(settings, dbname) | ||
| query_context = await load_podcast_database_or_index( | ||
| settings, dbname, _podcast_index | ||
| ) | ||
|
|
||
| # Use MCP-based model instead of one that requires API keys | ||
| model = MCPTypeChatModel(session) | ||
|
|
@@ -161,24 +167,33 @@ async def make_context( | |
| return context | ||
|
|
||
|
|
||
| async def load_podcast_index_or_database( | ||
| async def load_podcast_database_or_index( | ||
| settings: ConversationSettings, | ||
| dbname: str | None = None, | ||
| podcast_index: str | None = None, | ||
| ) -> query.QueryEvalContext[podcast.PodcastMessage, Any]: | ||
| if dbname is None: | ||
| conversation = await podcast.Podcast.read_from_file( | ||
| "tests/testdata/Episode_53_AdrianTchaikovsky_index", settings | ||
| ) | ||
| else: | ||
| if dbname is not None: | ||
| # Load from SQLite database | ||
| conversation = await podcast.Podcast.create(settings) | ||
| elif podcast_index is not None: | ||
| # Load from JSON index files | ||
| conversation = await podcast.Podcast.read_from_file(podcast_index, settings) | ||
| else: | ||
| raise ValueError( | ||
| "Either --database or --podcast-index must be specified. " | ||
| "Use --podcast-index to specify the path to podcast index files " | ||
| f"(e.g., '{_EXAMPLE_PODCAST_INDEX}')." | ||
| ) | ||
| return query.QueryEvalContext(conversation) | ||
|
|
||
|
|
||
| # Create an MCP server | ||
| mcp = FastMCP("typagent") | ||
|
|
||
| # Global variable to store database path (set via command-line argument) | ||
| # Global variables to store command-line arguments | ||
| # (no other straightforward way to pass to tool handlers) | ||
| _dbname: str | None = None | ||
| _podcast_index: str | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
@@ -245,12 +260,49 @@ async def query_conversation( | |
| "--database", | ||
| type=str, | ||
| default=None, | ||
| help="Path to the SQLite database file (default: load from JSON file)", | ||
| help="Path to a SQLite database file with pre-indexed podcast data", | ||
| ) | ||
| parser.add_argument( | ||
| "-p", | ||
| "--podcast-index", | ||
| type=str, | ||
| default=None, | ||
| help="Path to podcast index files (excluding '_data.json' suffix), " | ||
| f"e.g., '{_EXAMPLE_PODCAST_INDEX}'", | ||
|
Comment on lines
+265
to
+271
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point in the future we should be able to remove --podcast-index altogether, but not yet (and the test uses it). |
||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| # Store database path in global variable (no other straightforward way to pass to tool) | ||
| # Validate arguments | ||
| if args.database is None and args.podcast_index is None: | ||
| parser.error( | ||
| "Either --database or --podcast-index is required.\n" | ||
| "Example: python -m typeagent.mcp.server " | ||
| f"--podcast-index {_EXAMPLE_PODCAST_INDEX}" | ||
| ) | ||
|
|
||
| if args.database is not None and args.podcast_index is not None: | ||
| parser.error("Cannot specify both --database and --podcast-index") | ||
|
|
||
| # Validate file existence | ||
| if args.database is not None and not os.path.exists(args.database): | ||
| parser.error( | ||
| f"Database file not found: {args.database}\n" | ||
| "Please provide a valid path to an existing SQLite database." | ||
| ) | ||
|
|
||
| if args.podcast_index is not None: | ||
| data_file = args.podcast_index + "_data.json" | ||
| if not os.path.exists(data_file): | ||
| parser.error( | ||
| f"Podcast index file not found: {data_file}\n" | ||
| "Please provide a valid path to podcast index files " | ||
| "(without the '_data.json' suffix).\n" | ||
| f"Example: {_EXAMPLE_PODCAST_INDEX}" | ||
| ) | ||
|
|
||
| # Store in global variables for tool handlers | ||
| _dbname = args.database | ||
| _podcast_index = args.podcast_index | ||
|
|
||
| # Use stdio transport for simplicity | ||
| mcp.run(transport="stdio") | ||
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
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.
Oh, excellent. In practice the server almost always should use --database, which should be pre-filled by running one of the ingest tools.