Memori icon indicating copy to clipboard operation
Memori copied to clipboard

Fix the AzureOpenAI

Open harshalmore31 opened this issue 3 months ago • 1 comments

It doesn't record the conversation automatically properly, it only records the starting first conversation !

#!/usr/bin/env python3
import os
from dotenv import load_dotenv

from openai import AzureOpenAI
from memori import Memori
from memori.core.providers import ProviderConfig

# --- Load secrets from .env ---
load_dotenv()

# --- Configure Memori with Azure OpenAI ---
azure_provider = ProviderConfig.from_azure(
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    azure_deployment=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
    api_version=os.environ["AZURE_OPENAI_API_VERSION"],
    model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],  # usually same as deployment
)

print("🧠 Initializing Memori memory system...")

memory_system = Memori(
    database_connect="sqlite:///azure_openai_memory.db",
    conscious_ingest=True,
    auto_ingest=True,
    verbose=True,
    provider_config=azure_provider,
    namespace="azure_openai_example",
)
memory_system.enable()

# --- Azure OpenAI client ---
client = AzureOpenAI(
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    api_version=os.environ["AZURE_OPENAI_API_VERSION"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
)

def chat():
    print("\n✅ Setup complete! Chat with your memory-enhanced assistant.")
    print("Type 'quit' or 'exit' to end.\n")

    conversation_count = 0

    while True:
        try:
            user_input = input("You: ").strip()
            if user_input.lower() in ["quit", "exit", "bye"]:
                print("\nAI: Goodbye! I'll remember our conversation. 🤖✨")
                break
            if not user_input:
                continue

            conversation_count += 1
            print(f"\nAI (thinking... #{conversation_count})")

            # --- Call Azure OpenAI directly ---
            response = client.chat.completions.create(
                model=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
                messages=[{"role": "user", "content": user_input}],
            )

            ai_output = response.choices[0].message.content
            print(f"AI: {ai_output}\n")

        except KeyboardInterrupt:
            print("\n\nAI: Goodbye! I'll remember this chat. 🤖✨")
            break
        except Exception as e:
            print(f"\nError: {str(e)}\nPlease try again.\n")

    print("\n📊 Session Summary:")
    print(f"- Conversations processed: {conversation_count}")
    print("- Memory database: azure_openai_memory.db")
    print("- Namespace: azure_openai_example")

if __name__ == "__main__":
    chat()

harshalmore31 avatar Sep 16 '25 03:09 harshalmore31

Hi! I’d like to work on this issue and submit a PR shortly.

lindseystead avatar Dec 12 '25 06:12 lindseystead