Skip to content

Unable to specify http_client as a parameter to OpenAILLM #401

@yohei1126

Description

@yohei1126

Hi,

We have a self hosted litellm gateway in front of Azure Open AI API and Gemini API. https://www.litellm.ai
A self signed private root CA certificate is used to sign a server certificate of this server. so I tried to private http_client with private root CA certificate as a parameter to OpenAIEmbeddings and OpenAILLM class.

main.py

from neo4j import GraphDatabase
from neo4j_graphrag.retrievers import VectorRetriever
from neo4j_graphrag.llm import OpenAILLM
from neo4j_graphrag.generation import GraphRAG
from neo4j_graphrag.embeddings import OpenAIEmbeddings
import os
import httpx

# 1. Neo4j driver
URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "password123")
INDEX_NAME = "index-name"
AI_GW_BASE_URL = os.getenv("AI_GW_BASE_URL")
AI_GW_API_KEY = os.getenv("AI_GW_API_KEY")

# Path to your CA certificate
CA_CERT_PATH = "./Root-CA-V2.pem"

# Create HTTP client with custom CA certificate
http_client = httpx.Client(verify=CA_CERT_PATH)

# Connect to Neo4j database
driver = GraphDatabase.driver(URI, auth=AUTH)

# 2. Retriever
# Create Embedder object, needed to convert the user question (text) to a vector
embedder = OpenAIEmbeddings(
    base_url=AI_GW_BASE_URL,
    api_key=AI_GW_API_KEY,
    model="text-embedding-3-large",
    http_client=http_client)

# 3. LLM
llm = OpenAILLM(
    base_url=AI_GW_BASE_URL,
    api_key=AI_GW_API_KEY,
    model_name="gpt-4o",
    model_params={"temperature": 0},
    http_client=http_client)
llm.invoke("what is graph RAG")

# Initialize the retriever
retriever = VectorRetriever(
    driver=driver,
    index_name=INDEX_NAME,
    embedder=embedder)

# Initialize the RAG pipeline
rag = GraphRAG(retriever=retriever, llm=llm)

# Query the graph
QUERY_TEXT = "How do I do similarity search in Neo4j?"
response = rag.search(query_text=QUERY_TEXT, retriever_config={"top_k": 5})
print(response.answer)

pyproject.toml

[project]
name = "dde-graph-rag-builder"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "httpx>=0.28.1",
    "neo4j-graphrag[openai]==1.9.0",
]

but the main.py script as follows

uv run main.py
Traceback (most recent call last):
  File "/Users/yohei.onishi/work/dde_graph_rag_builder/main.py", line 35, in <module>
    llm = OpenAILLM(
          ^^^^^^^^^^
  File "/Users/yohei.onishi/work/dde_graph_rag_builder/.venv/lib/python3.12/site-packages/neo4j_graphrag/llm/openai_llm.py", line 377, in __init__
    self.async_client = self.openai.AsyncOpenAI(**kwargs)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yohei.onishi/work/dde_graph_rag_builder/.venv/lib/python3.12/site-packages/openai/_client.py", line 473, in __init__
    super().__init__(
  File "/Users/yohei.onishi/work/dde_graph_rag_builder/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1392, in __init__
    raise TypeError(
TypeError: Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got <class 'httpx.Client'>

As both sync client and async client are initialised with the same parameters so we can not specify http_client.
https://github.com/neo4j/neo4j-graphrag-python/blob/main/src/neo4j_graphrag/llm/openai_llm.py#L375

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions