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

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

Open
zhangleinice opened this issue Nov 13, 2023 · 0 comments

Comments

@zhangleinice
Copy link

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
    

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