Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How fix retrieval_qa_chain issue in chainlit #110

Open
QsingularityAi opened this issue May 6, 2024 · 0 comments
Open

How fix retrieval_qa_chain issue in chainlit #110

QsingularityAi opened this issue May 6, 2024 · 0 comments

Comments

@QsingularityAi
Copy link

def retrieval_qa_chain(model, retriever_instance):
# Convert the functions to runnables using RunnableLambda
split_image_text_types_runnable = RunnableLambda(split_image_text_types)
img_prompt_func_runnable = RunnableLambda(img_prompt_func)

# Create a runnable chain
qa_chain = (
    RunnablePassthrough.assign(
        context=retriever_instance | split_image_text_types_runnable
    )
    | img_prompt_func_runnable
    | model
    | StrOutputParser()
)

return qa_chain

def qa_bot():
llm = load_model()
qa = retrieval_qa_chain(llm, retriever_instance)
return qa

@cl.on_chat_start
async def start():
"""
Initializes the bot when a new chat starts.

This asynchronous function creates a new instance of the retrieval QA bot,
sends a welcome message, and stores the bot instance in the user's session.
"""
chain = qa_bot()
welcome_message = cl.Message(content="Starting the bot...")
await welcome_message.send()
welcome_message.content = (
    "Hi, Welcome to Chat With Data."
)
await welcome_message.update()
cl.user_session.set("chain", chain)
return qa_chain

Error Issue 

TypeError: Expected a Runnable, callable or dict.Instead got an unsupported type: <class 'NoneType'>
2024-05-06 10:21:04 - Translation file for en-GB not found. Using default translation en-US.
2024-05-06 10:21:05 - Translated markdown file for en-GB not found. Defaulting to chainlit.md.
2024-05-06 10:21:05 - Expected a Runnable, callable or dict.Instead got an unsupported type: <class 'NoneType'>
Traceback (most recent call last):
File "/home/anurag/conda3/envs/botgpt/lib/python3.8/site-packages/chainlit/utils.py", line 39, in wrapper
return await user_function(**params_values)
File "main.py", line 121, in start
chain = qa_bot()
File "main.py", line 110, in qa_bot
qa = retrieval_qa_chain(llm, retriever_instance)
File "main.py", line 99, in retrieval_qa_chain
context=retriever_instance | split_image_text_types_runnable
File "/home/anurag/conda3/envs/botgpt/lib/python3.8/site-packages/langchain_core/runnables/base.py", line 434, in ror
return RunnableSequence(coerce_to_runnable(other), self)
File "/home/anurag/conda3/envs/botgpt/lib/python3.8/site-packages/langchain_core/runnables/base.py", line 4734, in coerce_to_runnable
raise TypeError(
TypeError: Expected a Runnable, callable or dict.Instead got an unsupported type: <class 'NoneType'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant