Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Jan 19, 2026

Summary

This PR extracts reusable chat and chat_stream functions from the CLI into a new vlmrun/client/chat.py module. 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 completion
  • chat_stream() - Streaming chat completion (yields chunks)
  • collect_stream() - Helper to collect streaming chunks into a single response
  • ChatResponse and ChatStreamChunk dataclasses for structured responses
  • ChatError exception for chat-specific errors

The CLI has been refactored to use these core functions while retaining its presentation layer (Rich output, progress spinners, artifact download UI).

Usage example:

from vlmrun.client import VLMRun, chat, chat_stream
from pathlib import Path

client = VLMRun(api_key="your-api-key")
response = chat(client, "Describe this image", inputs=[Path("image.jpg")])
print(response.content)

Updates since last revision

  • Fixed test failure on Python 3.10 caused by naming collision between the chat function and chat module. The test now uses sys.modules["vlmrun.client.chat"] to explicitly access the module for mocking.

Review & Testing Checklist for Human

  • Verify CLI behavior is unchanged: Run vlmrun chat "Hello" and vlmrun chat "Describe this" -i image.jpg to confirm the CLI still works as expected with both streaming and non-streaming modes
  • Test the new functions directly: Import chat and chat_stream from vlmrun.client and verify they work correctly for the MCP server use case
  • Check error handling: Verify that invalid models, unsupported file types, and API errors are handled gracefully with clear error messages
  • Review naming collision risk: The module vlmrun.client.chat and function chat share the same name - verify this doesn't cause import issues in your MCP server integration

Recommended test plan:

  1. Run make test to verify all tests pass
  2. Test CLI with various inputs: text-only, with images, with documents
  3. Test both --no-stream and default streaming modes
  4. Test JSON output mode with --json
  5. Import and use chat() function directly in a Python script to verify it works for MCP server integration

Notes

…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>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant