Skip to content

把model.agenerate换成llmchain之后,chain.acall不能运行了;请问下是什么问题 #4

Open
@zhangleinice

Description

@zhangleinice
loader = TextLoader("static/faq/ecommerce_faq.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)

docsearch = Chroma.from_documents(texts, embeddings)

faq_chain = RetrievalQA.from_chain_type(
    llm, 
    chain_type="stuff", 
    retriever=docsearch.as_retriever()
)

@tool("FAQ")
def faq(intput: str) -> str:
    """"useful for when you need to answer questions about shopping policies, like return policy, shipping policy, etc."""
    return faq_chain.acall(intput)
    
async def call_openai(question):

    callback = AsyncIteratorCallbackHandler()

    # coroutine = wait_done(model.agenerate(messages=[[HumanMessage(content=question)]]), callback.done)

    coroutine = wait_done(faq(question), callback.done)

    task = asyncio.create_task(coroutine)

    print('coroutine', callback.aiter())
    # <async_generator object AsyncIteratorCallbackHandler.aiter at 0x11e4ffa40>

    async for token in callback.aiter():
        yield f"{token}"

    await task
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions