j6m6
j6m6
LLangfuse
Created by j6m6 on 12/11/2023 in #get-support
Thanks, that would be great. For now, I
That's now in the latest langserve 0.0.36 release. I had to implement something like this using per_req_config_modifier to set callbacks on config:
langfuse = Langfuse(
os.environ["LANGFUSE_PUBLIC_KEY"],
os.environ["LANGFUSE_SECRET_KEY"],
host=os.environ["LANGFUSE_HOST"]
)


def per_req_config_modifier(
config: Dict[str, Any],
request: Request
) -> Dict[str, Any]:
if "callbacks" not in config:
config["callbacks"] = []

trace = langfuse.trace(CreateTrace()) # TODO set id based on conversation_id from request
trace_handler = trace.getNewHandler()

config["callbacks"].extend([trace_handler])
return config


add_routes(app, my_chain, path="/my-chain", per_req_config_modifier=per_req_config_modifier)
langfuse = Langfuse(
os.environ["LANGFUSE_PUBLIC_KEY"],
os.environ["LANGFUSE_SECRET_KEY"],
host=os.environ["LANGFUSE_HOST"]
)


def per_req_config_modifier(
config: Dict[str, Any],
request: Request
) -> Dict[str, Any]:
if "callbacks" not in config:
config["callbacks"] = []

trace = langfuse.trace(CreateTrace()) # TODO set id based on conversation_id from request
trace_handler = trace.getNewHandler()

config["callbacks"].extend([trace_handler])
return config


add_routes(app, my_chain, path="/my-chain", per_req_config_modifier=per_req_config_modifier)
5 replies
LLangfuse
Created by j6m6 on 12/11/2023 in #get-support
Thanks, that would be great. For now, I
It looks like a fix has been proposed https://github.com/langchain-ai/langserve/pull/317. It just needs to be merged to main and then released.
5 replies
LLangfuse
Created by j6m6 on 12/11/2023 in #get-support
Thanks, that would be great. For now, I
I've opened https://github.com/langchain-ai/langserve/issues/311 so that perhaps the upstream project can implement changes to support request callback handlers.
5 replies