Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open AI env var fix #2384

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

PranavPuranik
Copy link
Contributor

@PranavPuranik PranavPuranik commented Mar 16, 2025

Description

Adds the official environment variable support for base URL key of openai - OPENAI_BASE_URL

This

Fixes #2356

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

  • Unit Test
  • Test Script (please provide)

Mem0 -->

import os
from mem0 import Memory

os.environ["OPENAI_API_KEY"] = ""
os.environ["OPENAI_BASE_URL"] = 'https://api.openai.com/v1'

config_openai = {
    "llm": {
        "provider": "openai",
        "config": {
            "model": "gpt-4o",
            "temperature": 0.2,
            "max_tokens": 1500,
        }
    },
    "embedder": {
        "provider": "openai",
        "config": {
            "model": "text-embedding-3-large"
        }
    },
    "version": "v1.1"
}

def main():
    
    m = Memory.from_config(config_openai)

    result = m.add("I am working on improving my tennis skills. Suggest some online courses.", user_id="alice", metadata={"category": "hobbies"})
    print(result)

    all_memories = m.get_all()
    print(all_memories)

    related_memories = m.search(query="What are Alice's hobbies?", user_id="alice")
    print(related_memories)

if __name__ == "__main__":
    main()

Embedchain -->

import os
from embedchain import App

os.environ["OPENAI_API_KEY"] = ""
os.environ["OPENAI_BASE_URL"] = 'https://api.openai.com/v1'


config = {
    "llm": {
        "provider": "openai",
        "config": {
            "model": "gpt-4o-mini",
        }
    },
    "embedder": {
        "provider": "openai",
        "config": {
            "model": 'text-embedding-3-small',
        }
    }
}


app = App.from_config(config=config)

app.add("https://www.forbes.com/profile/elon-musk")
answer = app.query("What is the net worth of Elon Musk today?")
print(answer)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed

Copy link

vercel bot commented Mar 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
multimodal-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 16, 2025 3:08am

Copy link
Member

@Dev-Khant Dev-Khant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @PranavPuranik We only want to have OPENAI_BASE_URL.

@PranavPuranik
Copy link
Contributor Author

Hey @PranavPuranik We only want to have OPENAI_BASE_URL.

Hey @Dev-Khant, I think there might be projects already using OPENAI_API_BASE and we don't want to cause a breaking change here.

This is why I first check for OPENAI_API_BASE then for OPENAI_BASE_URL, and finally have https://api.openai.com/v1 by default.

Let me know if I am missing something.

@Dev-Khant
Copy link
Member

Hey @PranavPuranik Then we should add a deprecation warning where OPENAI_API_BASE should be deprecated in version 0.1.80.

@PranavPuranik
Copy link
Contributor Author

0.1.80

Is that for mem0 and embedchain both? or just mem0?

@Dev-Khant
Copy link
Member

0.1.80

Is that for mem0 and embedchain both? or just mem0?

It would be for mem0 and 0.1.140 for embedchain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It is recommended to unify with the environment variable names of the OpenAI SDK.
2 participants