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 | --- |
| #2 | title: LangChain |
| #3 | --- |
| #4 | |
| #5 | |
| #6 | Mem0 supports LangChain as a provider to access a wide range of LLM models. LangChain is a framework for developing applications powered by language models, making it easy to integrate various LLM providers through a consistent interface. |
| #7 | |
| #8 | For a complete list of available chat models supported by LangChain, refer to the [LangChain Chat Models documentation](https://python.langchain.com/docs/integrations/chat). |
| #9 | |
| #10 | ## Usage |
| #11 | |
| #12 | <CodeGroup> |
| #13 | ```python Python |
| #14 | import os |
| #15 | from mem0 import Memory |
| #16 | from langchain_openai import ChatOpenAI |
| #17 | |
| #18 | # Set necessary environment variables for your chosen LangChain provider |
| #19 | os.environ["OPENAI_API_KEY"] = "your-api-key" |
| #20 | |
| #21 | # Initialize a LangChain model directly |
| #22 | openai_model = ChatOpenAI( |
| #23 | model="gpt-4.1-nano-2025-04-14", |
| #24 | temperature=0.2, |
| #25 | max_tokens=2000 |
| #26 | ) |
| #27 | |
| #28 | # Pass the initialized model to the config |
| #29 | config = { |
| #30 | "llm": { |
| #31 | "provider": "langchain", |
| #32 | "config": { |
| #33 | "model": openai_model |
| #34 | } |
| #35 | } |
| #36 | } |
| #37 | |
| #38 | m = Memory.from_config(config) |
| #39 | messages = [ |
| #40 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #41 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #42 | {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| #43 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #44 | ] |
| #45 | m.add(messages, user_id="alice", metadata={"category": "movies"}) |
| #46 | ``` |
| #47 | |
| #48 | ```typescript TypeScript |
| #49 | import { Memory } from 'mem0ai/oss'; |
| #50 | import { ChatOpenAI } from "@langchain/openai"; |
| #51 | |
| #52 | // Initialize a LangChain model directly |
| #53 | const openaiModel = new ChatOpenAI({ |
| #54 | modelName: "gpt-4", |
| #55 | temperature: 0.2, |
| #56 | maxTokens: 2000, |
| #57 | apiKey: process.env.OPENAI_API_KEY, |
| #58 | }); |
| #59 | |
| #60 | const config = { |
| #61 | llm: { |
| #62 | provider: 'langchain', |
| #63 | config: { |
| #64 | model: openaiModel, |
| #65 | }, |
| #66 | }, |
| #67 | }; |
| #68 | |
| #69 | const memory = new Memory(config); |
| #70 | const messages = [ |
| #71 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #72 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #73 | {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| #74 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #75 | ] |
| #76 | await memory.add(messages, { userId: "alice", metadata: { category: "movies" } }); |
| #77 | ``` |
| #78 | </CodeGroup> |
| #79 | |
| #80 | ## Supported LangChain Providers |
| #81 | |
| #82 | LangChain supports a wide range of LLM providers, including: |
| #83 | |
| #84 | - OpenAI (`ChatOpenAI`) |
| #85 | - Anthropic (`ChatAnthropic`) |
| #86 | - Google (`ChatGoogleGenerativeAI`, `ChatGooglePalm`) |
| #87 | - Mistral (`ChatMistralAI`) |
| #88 | - Ollama (`ChatOllama`) |
| #89 | - Azure OpenAI (`AzureChatOpenAI`) |
| #90 | - HuggingFace (`HuggingFaceChatEndpoint`) |
| #91 | - And many more |
| #92 | |
| #93 | You can use any of these model instances directly in your configuration. For a complete and up-to-date list of available providers, refer to the [LangChain Chat Models documentation](https://python.langchain.com/docs/integrations/chat). |
| #94 | |
| #95 | ## Provider-Specific Configuration |
| #96 | |
| #97 | When using LangChain as a provider, you'll need to: |
| #98 | |
| #99 | 1. Set the appropriate environment variables for your chosen LLM provider |
| #100 | 2. Import and initialize the specific model class you want to use |
| #101 | 3. Pass the initialized model instance to the config |
| #102 | |
| #103 | <Note> |
| #104 | Make sure to install the necessary LangChain packages and any provider-specific dependencies. |
| #105 | </Note> |
| #106 | |
| #107 | ## Config |
| #108 | |
| #109 | All available parameters for the `langchain` config are present in [Master List of All Params in Config](../config). |
| #110 |