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: Azure OpenAI |
| #3 | --- |
| #4 | |
| #5 | To use Azure OpenAI embedding models, set the `EMBEDDING_AZURE_OPENAI_API_KEY`, `EMBEDDING_AZURE_DEPLOYMENT`, `EMBEDDING_AZURE_ENDPOINT` and `EMBEDDING_AZURE_API_VERSION` environment variables. You can obtain the Azure OpenAI API key from the Azure. |
| #6 | |
| #7 | ### Usage |
| #8 | |
| #9 | <CodeGroup> |
| #10 | ```python Python |
| #11 | import os |
| #12 | from mem0 import Memory |
| #13 | |
| #14 | os.environ["EMBEDDING_AZURE_OPENAI_API_KEY"] = "your-api-key" |
| #15 | os.environ["EMBEDDING_AZURE_DEPLOYMENT"] = "your-deployment-name" |
| #16 | os.environ["EMBEDDING_AZURE_ENDPOINT"] = "your-api-base-url" |
| #17 | os.environ["EMBEDDING_AZURE_API_VERSION"] = "version-to-use" |
| #18 | |
| #19 | os.environ["OPENAI_API_KEY"] = "your_api_key" # For LLM |
| #20 | |
| #21 | |
| #22 | config = { |
| #23 | "embedder": { |
| #24 | "provider": "azure_openai", |
| #25 | "config": { |
| #26 | "model": "text-embedding-3-large", |
| #27 | "azure_kwargs": { |
| #28 | "api_version": "", |
| #29 | "azure_deployment": "", |
| #30 | "azure_endpoint": "", |
| #31 | "api_key": "", |
| #32 | "default_headers": { |
| #33 | "CustomHeader": "your-custom-header", |
| #34 | } |
| #35 | } |
| #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="john") |
| #48 | ``` |
| #49 | |
| #50 | ```typescript TypeScript |
| #51 | import { Memory } from 'mem0ai/oss'; |
| #52 | |
| #53 | const config = { |
| #54 | embedder: { |
| #55 | provider: "azure_openai", |
| #56 | config: { |
| #57 | model: "text-embedding-3-large", |
| #58 | modelProperties: { |
| #59 | endpoint: "your-api-base-url", |
| #60 | deployment: "your-deployment-name", |
| #61 | apiVersion: "version-to-use", |
| #62 | } |
| #63 | } |
| #64 | } |
| #65 | } |
| #66 | |
| #67 | const memory = new Memory(config); |
| #68 | |
| #69 | const messages = [ |
| #70 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #71 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #72 | {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."}, |
| #73 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #74 | ] |
| #75 | |
| #76 | await memory.add(messages, { userId: "john" }); |
| #77 | ``` |
| #78 | </CodeGroup> |
| #79 | |
| #80 | As an alternative to using an API key, the Azure Identity credential chain can be used to authenticate with [Azure OpenAI role-based security](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/role-based-access-control). |
| #81 | |
| #82 | <Note> If an API key is provided, it will be used for authentication over an Azure Identity </Note> |
| #83 | |
| #84 | Below is a sample configuration for using Mem0 with Azure OpenAI and Azure Identity: |
| #85 | |
| #86 | ```python |
| #87 | import os |
| #88 | from mem0 import Memory |
| #89 | # You can set the values directly in the config dictionary or use environment variables |
| #90 | |
| #91 | os.environ["LLM_AZURE_DEPLOYMENT"] = "your-deployment-name" |
| #92 | os.environ["LLM_AZURE_ENDPOINT"] = "your-api-base-url" |
| #93 | os.environ["LLM_AZURE_API_VERSION"] = "version-to-use" |
| #94 | |
| #95 | config = { |
| #96 | "llm": { |
| #97 | "provider": "azure_openai_structured", |
| #98 | "config": { |
| #99 | "model": "your-deployment-name", |
| #100 | "temperature": 0.1, |
| #101 | "max_tokens": 2000, |
| #102 | "azure_kwargs": { |
| #103 | "azure_deployment": "<your-deployment-name>", |
| #104 | "api_version": "<version-to-use>", |
| #105 | "azure_endpoint": "<your-api-base-url>", |
| #106 | "default_headers": { |
| #107 | "CustomHeader": "your-custom-header", |
| #108 | } |
| #109 | } |
| #110 | } |
| #111 | } |
| #112 | } |
| #113 | ``` |
| #114 | |
| #115 | Refer to [Azure Identity troubleshooting tips](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TROUBLESHOOTING.md#troubleshoot-environmentcredential-authentication-issues) for setting up an Azure Identity credential. |
| #116 | |
| #117 | ### Config |
| #118 | |
| #119 | Here are the parameters available for configuring Azure OpenAI embedder: |
| #120 | <Tabs> |
| #121 | <Tab title="Python"> |
| #122 | | Parameter | Description | Default Value | |
| #123 | | --- | --- | --- | |
| #124 | | `model` | The name of the embedding model to use | `text-embedding-3-small` | |
| #125 | | `embedding_dims` | Dimensions of the embedding model | `1536` | |
| #126 | | `azure_kwargs` | The Azure OpenAI configs | `config_keys` | |
| #127 | </Tab> |
| #128 | <Tab title="TypeScript"> |
| #129 | | Parameter | Description | Default Value | |
| #130 | | ----------------- | --------------------------------------------- | -------------------------- | |
| #131 | | `model` | The name of the embedding model to use | `text-embedding-3-small` | |
| #132 | | `embeddingDims` | Dimensions of the embedding model | `1536` | |
| #133 | | `apiKey` | Azure OpenAI API key | `None` | |
| #134 | | `modelProperties` | Object containing endpoint and other settings | `{ endpoint: "",...rest }`| |
| #135 | </Tab> |
| #136 | </Tabs> |
| #137 |