refactor(chat): extract reusable chat and chat_stream functions for MCP server#144
Closed
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Closed
refactor(chat): extract reusable chat and chat_stream functions for MCP server#144devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
…CP server - Create new vlmrun/client/chat.py module with reusable functions: - chat(): Non-streaming chat completion - chat_stream(): Streaming chat completion - collect_stream(): Helper to collect streaming chunks - ChatResponse and ChatStreamChunk dataclasses - ChatError exception class - Helper functions for file upload, message building, validation - Refactor CLI chat command to use the new reusable functions - CLI now focuses on presentation layer (Rich output, progress spinners) - Core logic delegated to vlmrun.client.chat module - Expose new functions in vlmrun.client.__init__.py for easy import: - chat, chat_stream, collect_stream - ChatResponse, ChatStreamChunk, ChatError - AVAILABLE_MODELS, DEFAULT_MODEL, extract_artifact_refs - Update tests to use new module paths Co-Authored-By: Sudeep Pillai <sudeep.pillai@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Fix test failure on Python 3.10 where the patch path 'vlmrun.client.chat._upload_files' was resolving to the 'chat' function instead of the 'chat' module due to the naming collision in vlmrun.client.__init__.py. Use sys.modules to explicitly get the chat module and patch.object to mock the _upload_files function. Co-Authored-By: Sudeep Pillai <sudeep.pillai@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR extracts reusable
chatandchat_streamfunctions from the CLI into a newvlmrun/client/chat.pymodule. These functions can now be imported and used by the MCP server or any other client code.The new module provides:
chat()- Non-streaming chat completionchat_stream()- Streaming chat completion (yields chunks)collect_stream()- Helper to collect streaming chunks into a single responseChatResponseandChatStreamChunkdataclasses for structured responsesChatErrorexception for chat-specific errorsThe CLI has been refactored to use these core functions while retaining its presentation layer (Rich output, progress spinners, artifact download UI).
Usage example:
Updates since last revision
chatfunction andchatmodule. The test now usessys.modules["vlmrun.client.chat"]to explicitly access the module for mocking.Review & Testing Checklist for Human
vlmrun chat "Hello"andvlmrun chat "Describe this" -i image.jpgto confirm the CLI still works as expected with both streaming and non-streaming modeschatandchat_streamfromvlmrun.clientand verify they work correctly for the MCP server use casevlmrun.client.chatand functionchatshare the same name - verify this doesn't cause import issues in your MCP server integrationRecommended test plan:
make testto verify all tests pass--no-streamand default streaming modes--jsonchat()function directly in a Python script to verify it works for MCP server integrationNotes
collect_stream()usesDEFAULT_MODELsince the model isn't available from stream chunks