-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Error using callbacks on RetrievalQAWithSourcesChain #4118
Comments
Updated to langain 0.0.161 and made it work (but getting the actual stream to work was quite something.) |
@tomatefarcie123 can you provide code as to how you got this working? |
Hey @tomatefarcie123 did you enable streaming via api for local huggingface LLMs? |
@xerxes01 I'm only using openai |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get TypeError: 'tuple' object is not callable running this code. I guess it's because a run call doesn't work on a chain with multiple outputs,
How then can I use callbacks on that chain?
from flask import Flask, render_template
from flask_socketio import SocketIO
from initialize_llm_chain import build_chain
from langchain.callbacks.base import BaseCallbackHandler
Create a custom handler to stream llm response
class StreamingHandler(BaseCallbackHandler):
def on_llm_new_token(self, token: str, **kwargs) -> None:
socketio.emit('new_token', token)
Build the langchain chain
qa_chain = build_chain()
Instantiate the handler
handler = StreamingHandler()
Initialize flask app
app = Flask(name)
socketio = SocketIO(app)
Define source route
@app.route('/')
def index():
return render_template('index.html')
Define socket query
@socketio.on('query', namespace='/results')
def handle_query(data):
results = qa_chain(data, callbacks=[handler])
('results', results["answer"])
if name == 'main':
socketio.run(app, host='localhost', port=9000, debug=True)
The text was updated successfully, but these errors were encountered: