-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add Ollama provider support #163
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
+135
−0
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
432a9f4
feat: add Ollama provider support
majiayu000 c55f394
fix: forward **kwargs to chat.completions.create() for Ollama engine
majiayu000 02a9da5
refactor: reuse LMMEngineOpenAI for Ollama provider
majiayu000 234450b
fix: restore OLLAMA_HOST env var support
majiayu000 d2271de
feat: add DeepSeek/Qwen support and improve Ollama config
majiayu000 c8f306e
refactor: reuse LMMEngineOpenAI for DeepSeek and Qwen providers
majiayu000 b660189
fix: address review comments (robust params, url normalization, cleanup)
majiayu000 000dd37
fix: clean up test env and normalize ollama param checks
majiayu000 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,72 @@ | ||
| import os | ||
| import unittest | ||
| from unittest.mock import patch, MagicMock | ||
| from gui_agents.s3.core.mllm import LMMAgent | ||
| from gui_agents.s3.core.engine import LMMEngineOpenAI | ||
|
|
||
|
|
||
| class TestProviders(unittest.TestCase): | ||
| def setUp(self): | ||
| # Clear env vars before each test | ||
| if "OLLAMA_HOST" in os.environ: | ||
| del os.environ["OLLAMA_HOST"] | ||
| if "DEEPSEEK_API_KEY" in os.environ: | ||
| del os.environ["DEEPSEEK_API_KEY"] | ||
| if "QWEN_API_KEY" in os.environ: | ||
| del os.environ["QWEN_API_KEY"] | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if "DEEPSEEK_ENDPOINT_URL" in os.environ: | ||
| del os.environ["DEEPSEEK_ENDPOINT_URL"] | ||
| if "QWEN_ENDPOINT_URL" in os.environ: | ||
| del os.environ["QWEN_ENDPOINT_URL"] | ||
|
|
||
| def test_ollama_missing_config(self): | ||
| """Test that Ollama raises ValueError if no endpoint is provided""" | ||
| with self.assertRaises(ValueError) as cm: | ||
| LMMAgent(engine_params={"engine_type": "ollama", "model": "llama3"}) | ||
| self.assertIn("Ollama endpoint must be provided", str(cm.exception)) | ||
|
|
||
| def test_ollama_valid_config_param(self): | ||
| """Test Ollama init with base_url param""" | ||
| agent = LMMAgent( | ||
| engine_params={ | ||
| "engine_type": "ollama", | ||
| "model": "llama3", | ||
| "base_url": "http://example.com/v1", | ||
| } | ||
| ) | ||
| self.assertIsInstance(agent.engine, LMMEngineOpenAI) | ||
| self.assertEqual(agent.engine.base_url, "http://example.com/v1") | ||
|
|
||
| def test_ollama_valid_config_env(self): | ||
| """Test Ollama init with OLLAMA_HOST env var""" | ||
| with patch.dict(os.environ, {"OLLAMA_HOST": "http://env-host:11434"}): | ||
| agent = LMMAgent(engine_params={"engine_type": "ollama", "model": "llama3"}) | ||
| self.assertIsInstance(agent.engine, LMMEngineOpenAI) | ||
| # Check for /v1 addition | ||
| self.assertEqual(agent.engine.base_url, "http://env-host:11434/v1") | ||
|
|
||
| def test_deepseek_init(self): | ||
| """Test DeepSeek initialization""" | ||
| with patch.dict(os.environ, {"DEEPSEEK_API_KEY": "sk-test"}): | ||
| agent = LMMAgent( | ||
| engine_params={"engine_type": "deepseek", "model": "deepseek-coder"} | ||
| ) | ||
| self.assertIsInstance(agent.engine, LMMEngineOpenAI) | ||
| # Default URL | ||
| self.assertEqual(agent.engine.base_url, "https://api.deepseek.com/v1") | ||
| # (Note: engine.py logic resolves default at generate() time or if client created, | ||
| # but init just stores what's passed. Let's verify prompt generation to ensure it doesn't crash on init) | ||
|
|
||
| def test_qwen_init(self): | ||
| """Test Qwen initialization""" | ||
| with patch.dict(os.environ, {"QWEN_API_KEY": "sk-qwen"}): | ||
| agent = LMMAgent(engine_params={"engine_type": "qwen", "model": "qwen-max"}) | ||
| self.assertIsInstance(agent.engine, LMMEngineOpenAI) | ||
| self.assertEqual( | ||
| agent.engine.base_url, | ||
| "https://dashscope.aliyuncs.com/compatible-mode/v1", | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks!
Instead of defaulting to localhost, raising an actionable error is better and easier for devs to debug.
Would you mind including DeepSeek and Qwen into this PR and close #164?
I think we can check in after the change and some test