Files
mem0/embedchain/notebooks/openai.ipynb

3.6 KiB

Cookbook for using OpenAI with Embedchain

Step-1: Install embedchain package

In [ ]:
!pip install embedchain

Step-2: Set OpenAI environment variables

You can find this env variable on your OpenAI dashboard.

In [ ]:
import os
from embedchain import App

os.environ["OPENAI_API_KEY"] = "sk-xxx"

Step-3 Create embedchain app and define your config

In [ ]:
app = App.from_config(config={
    "llm": {
        "provider": "openai",
        "config": {
            "model": "gpt-4o-mini",
            "temperature": 0.5,
            "max_tokens": 1000,
            "top_p": 1,
            "stream": False
        }
    },
    "embedder": {
        "provider": "openai",
        "config": {
            "model": "text-embedding-ada-002"
        }
    }
})

Step-4: Add data sources to your app

In [ ]:
app.add("https://www.forbes.com/profile/elon-musk")
In [ ]:
while(True):
    question = input("Enter question: ")
    if question in ['q', 'exit', 'quit']:
        break
    answer = app.query(question)
    print(answer)