Open scchengaiah opened 4 months ago
Same issue as above, is there a fix or workaround for this as we need to use claude 3 for our usecase and can't find any solution to use along with nemo.
We have applied a workaround by attaching the callback handler to the llm instance and streamed response.
# Custom callback handler class to attach to the llm instance
class BotStreamingCallbackHandler(BaseCallbackHandler):
def __init__(self):
# Initialize required objects for streaming capabilities. For example: chat interface object
pass
async def on_llm_new_token(self, token, **kwargs) -> None:
# Stream tokens to the chat interface.
pass
def __call__(self, *args, **kwargs):
pass
@action(is_system_action=True)
async def call_llm(user_query: str, llm: Optional[BaseLLM]) -> str:
if llm.callbacks is None:
llm.callbacks = [BotStreamingCallbackHandler()]
else:
llm.callbacks.append(BotStreamingCallbackHandler())
response = await llm.ainvoke(user_query)
return response.content
Please note that if you do not want to stream the response generated by guardrails invocation, then use dedicated llm object instance inside the call_llm
method and attach the callback handler to the same.
Hope this can help 🙂
Hello,
When using
BedrockChat
through langchain, the streaming functionality does not work.Claude3
models requiresBedrockChat
interface to be used. When I switch to theBedrock
interface with older Claude models, the streaming feature works fine.Here is the example to replicate the behavior.
In the above code, streaming works when replacing
BedrockChat
withBedrock
. However, for latest Claude3 models, we have to useBedrockChat
.Can someone help with the workaround or an approach to tackle the above scenario ?
Thank you.