repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from unittest.mock import Mock, patch |
| #2 | |
| #3 | import pytest |
| #4 | |
| #5 | from mem0.configs.llms.lmstudio import LMStudioConfig |
| #6 | from mem0.llms.lmstudio import LMStudioLLM |
| #7 | |
| #8 | |
| #9 | @pytest.fixture |
| #10 | def mock_lm_studio_client(): |
| #11 | with patch("mem0.llms.lmstudio.OpenAI") as mock_openai: # Corrected path |
| #12 | mock_client = Mock() |
| #13 | mock_client.chat.completions.create.return_value = Mock( |
| #14 | choices=[Mock(message=Mock(content="I'm doing well, thank you for asking!"))] |
| #15 | ) |
| #16 | mock_openai.return_value = mock_client |
| #17 | yield mock_client |
| #18 | |
| #19 | |
| #20 | def test_generate_response_without_tools(mock_lm_studio_client): |
| #21 | config = LMStudioConfig( |
| #22 | model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf", |
| #23 | temperature=0.7, |
| #24 | max_tokens=100, |
| #25 | top_p=1.0, |
| #26 | ) |
| #27 | llm = LMStudioLLM(config) |
| #28 | messages = [ |
| #29 | {"role": "system", "content": "You are a helpful assistant."}, |
| #30 | {"role": "user", "content": "Hello, how are you?"}, |
| #31 | ] |
| #32 | |
| #33 | response = llm.generate_response(messages) |
| #34 | |
| #35 | mock_lm_studio_client.chat.completions.create.assert_called_once_with( |
| #36 | model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf", |
| #37 | messages=messages, |
| #38 | temperature=0.7, |
| #39 | max_tokens=100, |
| #40 | top_p=1.0, |
| #41 | response_format={"type": "json_object"}, |
| #42 | ) |
| #43 | |
| #44 | assert response == "I'm doing well, thank you for asking!" |
| #45 | |
| #46 | |
| #47 | def test_generate_response_specifying_response_format(mock_lm_studio_client): |
| #48 | config = LMStudioConfig( |
| #49 | model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf", |
| #50 | temperature=0.7, |
| #51 | max_tokens=100, |
| #52 | top_p=1.0, |
| #53 | lmstudio_response_format={"type": "json_schema"}, # Specifying the response format in config |
| #54 | ) |
| #55 | llm = LMStudioLLM(config) |
| #56 | messages = [ |
| #57 | {"role": "system", "content": "You are a helpful assistant."}, |
| #58 | {"role": "user", "content": "Hello, how are you?"}, |
| #59 | ] |
| #60 | |
| #61 | response = llm.generate_response(messages) |
| #62 | |
| #63 | mock_lm_studio_client.chat.completions.create.assert_called_once_with( |
| #64 | model="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf", |
| #65 | messages=messages, |
| #66 | temperature=0.7, |
| #67 | max_tokens=100, |
| #68 | top_p=1.0, |
| #69 | response_format={"type": "json_schema"}, |
| #70 | ) |
| #71 | |
| #72 | assert response == "I'm doing well, thank you for asking!" |
| #73 |