Description
Server Setup Information
- Weaviate Server Version: 1.25.1
- Deployment Method: docker
- Multi Node? Number of Running Nodes: No
- Client Language and Version: weaviate-client 4.6.3 A python native Weaviate client
- Multitenancy?: NO
Any additional Information
Chainlit version: chainlit 1.1.202
Openai version: openai 1.30.5
Does anyone here have experience with running the Weaviate - Chainlit - OpenAI combination for RAG? If so please chime in on this thread, thanks
I have been banging my head on this today, only to find out that there is something in the internals of weaviate that, when run within chainlit (1.1.202) completely hangs the openai client.
I am running this code:
import asyncio
import os
import chainlit as cl
import weaviate
from openai import AsyncOpenAIimport logginglogging.basicConfig(level=logging.DEBUG)api_key = os.environ.get("OPENAI_API_KEY")settings = {
"model": "gpt-4",
"temperature": 0.7,
"max_tokens": 500,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
}BOT_NAME = "ChatBot"def search_weaviate(query):
with weaviate.connect_to_local() as wva:
documents = wva.collections.get("Document")
results = documents.query.hybrid(query=query, limit=5)
result = results.objects
response_text = ""
for r in result:
doc = r.properties
response_text += (
f"Title: {doc['title']}\n"
f"URL: {doc['url']}\n"
f"Source Type: {doc['source_type']}\n"
f"Chunk: {doc['textChunk']}\n\n"
)
wva.close()
return response_text@cl.on_chat_start
async def start_chat():
cl.user_session.set(
"message_history",
[
{
"role": "system",
"content": "You are a helpful assistant that can answer any question about <this> a company.",
}
],
)
await cl.Avatar(
name="ChatBot",
url="/public/ai.jpg",
).send() msg = cl.Message(
author=BOT_NAME,
content="Hello! I am a helpful assistant that can answer any question about <this> a company.",
)
await msg.send()
@cl.on_message
async def on_message(message):
message_history = cl.user_session.get("message_history")
try:
response_text = search_weaviate(message.content)
except Exception as e:
response_text = f"Error: {str(e)}"
logging.error(response_text)
[logging.info](http://logging.info/)(f"response_text: {response_text}")
message_history.append({"role": "user", "content": message.content})
message_history.append({"role": "assistant", "content": response_text}) msg = cl.Message(author=BOT_NAME, content="")
await msg.send()
[logging.info](http://logging.info/)(f"Before OpenAI request with message_history: {message_history}")
async with AsyncOpenAI(api_key=api_key) as openai_client:
try:
response = await openai_client.chat.completions.create(
messages=message_history, stream=True, **settings
)
[logging.info](http://logging.info/)("OpenAI request successful")
except Exception as e:
logging.error(f"OpenAI request failed: {str(e)}")
full_response = ""
async for chunk in response:
content = chunk.choices[0].delta.content
if content is not None:
full_response += content
await msg.stream_token(content)
openai_client.close()
await msg.send()
message_history.append({"role": "assistant", "content": full_response})
And what happens is that the await openai_client.chat.completions.create
never completes, because the openai
client is never sending the HTTP request to the OpenAI API
if I remove the call to search_weaviate
no problem. But if I run that beforehand… no cigar
If I do calculate the embeddings outside of Weaviate client, and pass the vector to the weaviate client then the problem goes away
But. If I run the same code in ipython
, then the problem doesn’t exist
so it’s not just weaviate that interferes with openai, but it’s weaviate + openai within chainlit
If anyone ran this successfully please ping me and tell me how you managed If not and you have ideas how I can debug (I tried everything in my books) please lmk.Thanks