* Add Azure OpenAI example with Neo4j 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Convert Azure OpenAI example to use uv - Remove requirements.txt (uv uses pyproject.toml) - Update README to use 'uv sync' and 'uv run' 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update Azure OpenAI example to use gpt-4.1 - Change default deployment from gpt-4 to gpt-4.1 - Update README recommendations to prioritize gpt-4.1 models 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove model recommendations from Azure OpenAI example Model recommendations quickly become outdated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Add default Neo4j credentials to docker-compose Set sensible defaults (neo4j/password) to prevent NEO4J_AUTH error when .env file is not present. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update Azure OpenAI documentation to use v1 API - Simplified Azure OpenAI setup using AsyncOpenAI with v1 endpoint - Updated main README with clearer Quick Start example - Removed outdated API version configuration - Updated example deployment to gpt-5-mini - Added note about v1 API endpoint format 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update LLMConfig to include both model and small_model Both parameters are needed for proper LLM configuration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Address PR review feedback - Remove flawed validation check in azure_openai_neo4j.py - Remove unused azure-identity dependency - Update docstrings to reflect dual client support (AsyncAzureOpenAI and AsyncOpenAI) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
"""
|
|
Copyright 2024, Zep Software, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from openai import AsyncAzureOpenAI, AsyncOpenAI
|
|
|
|
from .client import EmbedderClient
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class AzureOpenAIEmbedderClient(EmbedderClient):
|
|
"""Wrapper class for Azure OpenAI that implements the EmbedderClient interface.
|
|
|
|
Supports both AsyncAzureOpenAI and AsyncOpenAI (with Azure v1 API endpoint).
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
azure_client: AsyncAzureOpenAI | AsyncOpenAI,
|
|
model: str = "text-embedding-3-small",
|
|
):
|
|
self.azure_client = azure_client
|
|
self.model = model
|
|
|
|
async def create(self, input_data: str | list[str] | Any) -> list[float]:
|
|
"""Create embeddings using Azure OpenAI client."""
|
|
try:
|
|
# Handle different input types
|
|
if isinstance(input_data, str):
|
|
text_input = [input_data]
|
|
elif isinstance(input_data, list) and all(
|
|
isinstance(item, str) for item in input_data
|
|
):
|
|
text_input = input_data
|
|
else:
|
|
# Convert to string list for other types
|
|
text_input = [str(input_data)]
|
|
|
|
response = await self.azure_client.embeddings.create(
|
|
model=self.model, input=text_input
|
|
)
|
|
|
|
# Return the first embedding as a list of floats
|
|
return response.data[0].embedding
|
|
except Exception as e:
|
|
logger.error(f"Error in Azure OpenAI embedding: {e}")
|
|
raise
|
|
|
|
async def create_batch(self, input_data_list: list[str]) -> list[list[float]]:
|
|
"""Create batch embeddings using Azure OpenAI client."""
|
|
try:
|
|
response = await self.azure_client.embeddings.create(
|
|
model=self.model, input=input_data_list
|
|
)
|
|
|
|
return [embedding.embedding for embedding in response.data]
|
|
except Exception as e:
|
|
logger.error(f"Error in Azure OpenAI batch embedding: {e}")
|
|
raise
|