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: OpenAI |
| #3 | --- |
| #4 | |
| #5 | To use OpenAI LLM models, you have to set the `OPENAI_API_KEY` environment variable. You can obtain the OpenAI API key from the [OpenAI Platform](https://platform.openai.com/account/api-keys). |
| #6 | |
| #7 | > **Note**: The following are currently unsupported with reasoning models `Parallel tool calling`,`temperature`, `top_p`, `presence_penalty`, `frequency_penalty`, `logprobs`, `top_logprobs`, `logit_bias`, `max_tokens` |
| #8 | |
| #9 | ## Usage |
| #10 | |
| #11 | <CodeGroup> |
| #12 | ```python Python |
| #13 | import os |
| #14 | from mem0 import Memory |
| #15 | |
| #16 | os.environ["OPENAI_API_KEY"] = "your-api-key" |
| #17 | |
| #18 | config = { |
| #19 | "llm": { |
| #20 | "provider": "openai", |
| #21 | "config": { |
| #22 | "model": "gpt-4.1-nano-2025-04-14", |
| #23 | "temperature": 0.2, |
| #24 | "max_tokens": 2000, |
| #25 | } |
| #26 | } |
| #27 | } |
| #28 | |
| #29 | # Use Openrouter by passing it's api key |
| #30 | # os.environ["OPENROUTER_API_KEY"] = "your-api-key" |
| #31 | # config = { |
| #32 | # "llm": { |
| #33 | # "provider": "openai", |
| #34 | # "config": { |
| #35 | # "model": "meta-llama/llama-3.1-70b-instruct", |
| #36 | # } |
| #37 | # } |
| #38 | # } |
| #39 | |
| #40 | m = Memory.from_config(config) |
| #41 | messages = [ |
| #42 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #43 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #44 | {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, |
| #45 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #46 | ] |
| #47 | m.add(messages, user_id="alice", metadata={"category": "movies"}) |
| #48 | ``` |
| #49 | |
| #50 | ```typescript TypeScript |
| #51 | import { Memory } from 'mem0ai/oss'; |
| #52 | |
| #53 | const config = { |
| #54 | llm: { |
| #55 | provider: 'openai', |
| #56 | config: { |
| #57 | apiKey: process.env.OPENAI_API_KEY || '', |
| #58 | model: 'gpt-4-turbo-preview', |
| #59 | temperature: 0.2, |
| #60 | maxTokens: 1500, |
| #61 | }, |
| #62 | }, |
| #63 | }; |
| #64 | |
| #65 | const memory = new Memory(config); |
| #66 | const messages = [ |
| #67 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #68 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #69 | {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, |
| #70 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #71 | ] |
| #72 | await memory.add(messages, { userId: "alice", metadata: { category: "movies" } }); |
| #73 | ``` |
| #74 | </CodeGroup> |
| #75 | |
| #76 | We also support the new [OpenAI structured-outputs](https://platform.openai.com/docs/guides/structured-outputs/introduction) model. |
| #77 | |
| #78 | ```python |
| #79 | import os |
| #80 | from mem0 import Memory |
| #81 | |
| #82 | os.environ["OPENAI_API_KEY"] = "your-api-key" |
| #83 | |
| #84 | config = { |
| #85 | "llm": { |
| #86 | "provider": "openai_structured", |
| #87 | "config": { |
| #88 | "model": "gpt-4.1-nano-2025-04-14", |
| #89 | "temperature": 0.0, |
| #90 | } |
| #91 | } |
| #92 | } |
| #93 | |
| #94 | m = Memory.from_config(config) |
| #95 | ``` |
| #96 | |
| #97 | ## Config |
| #98 | |
| #99 | All available parameters for the `openai` config are present in [Master List of All Params in Config](../config). |
| #100 |