|
| 1 | +--- |
| 2 | +title: LM Studio |
| 3 | +--- |
| 4 | + |
| 5 | +To use LM Studio with Mem0, you'll need to have LM Studio running locally with its server enabled. LM Studio provides a way to run local LLMs with an OpenAI-compatible API. |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +<CodeGroup> |
| 10 | +```python Python |
| 11 | +import os |
| 12 | +from mem0 import Memory |
| 13 | + |
| 14 | +os.environ["OPENAI_API_KEY"] = "your-api-key" # used for embedding model |
| 15 | + |
| 16 | +config = { |
| 17 | + "llm": { |
| 18 | + "provider": "lmstudio", |
| 19 | + "config": { |
| 20 | + "model": "lmstudio-community/Meta-Llama-3.1-70B-Instruct-GGUF/Meta-Llama-3.1-70B-Instruct-IQ2_M.gguf", |
| 21 | + "temperature": 0.2, |
| 22 | + "max_tokens": 2000, |
| 23 | + "lmstudio_base_url": "http://localhost:1234/v1", # default LM Studio API URL |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +m = Memory.from_config(config) |
| 29 | +messages = [ |
| 30 | + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| 31 | + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, |
| 32 | + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| 33 | + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| 34 | +] |
| 35 | +m.add(messages, user_id="alice", metadata={"category": "movies"}) |
| 36 | +``` |
| 37 | +</CodeGroup> |
| 38 | + |
| 39 | +### Running Completely Locally |
| 40 | + |
| 41 | +You can also use LM Studio for both LLM and embedding to run Mem0 entirely locally: |
| 42 | + |
| 43 | +```python |
| 44 | +from mem0 import Memory |
| 45 | + |
| 46 | +# No external API keys needed! |
| 47 | +config = { |
| 48 | + "llm": { |
| 49 | + "provider": "lmstudio" |
| 50 | + }, |
| 51 | + "embedder": { |
| 52 | + "provider": "lmstudio" |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +m = Memory.from_config(config) |
| 57 | +messages = [ |
| 58 | + {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| 59 | + {"role": "assistant", "content": "How about a thriller movies? They can be quite engaging."}, |
| 60 | + {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| 61 | + {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| 62 | +] |
| 63 | +m.add(messages, user_id="alice123", metadata={"category": "movies"}) |
| 64 | +``` |
| 65 | + |
| 66 | +<Note> |
| 67 | + When using LM Studio for both LLM and embedding, make sure you have: |
| 68 | + 1. An LLM model loaded for generating responses |
| 69 | + 2. An embedding model loaded for vector embeddings |
| 70 | + 3. The server enabled with the correct endpoints accessible |
| 71 | +</Note> |
| 72 | + |
| 73 | +<Note> |
| 74 | + To use LM Studio, you need to: |
| 75 | + 1. Download and install [LM Studio](https://lmstudio.ai/) |
| 76 | + 2. Start a local server from the "Server" tab |
| 77 | + 3. Set the appropriate `lmstudio_base_url` in your configuration (default is usually http://localhost:1234/v1) |
| 78 | +</Note> |
| 79 | + |
| 80 | +## Config |
| 81 | + |
| 82 | +All available parameters for the `lmstudio` config are present in [Master List of All Params in Config](../config). |
0 commit comments