-
I have a method similar to this: @observe()
def _query_llm(
self, prompt: BasePromptTemplate | Sequence[BaseMessage] | str
) -> Any:
"""
Queries the language model with the given prompt.
"""
is_test = os.getenv("IS_EVAL", "NONE").lower() == "true"
if is_test:
return self.llm.invoke(prompt).content
else:
handler = CallbackHandler(public_key=os.getenv("PUBLIC_KEY"), secret_key=os.getenv("SECRET_KEY")) # standard callback
return self.llm.invoke(
prompt,
config={
"callbacks": [handler],
}, # type: ignore
).content When calling the handler, we get this warning: Now I'm looking at the documentation, and I'm not sure whether I should configure the langfuse_context via the langfuse_context.configure() method or whether the callback handler config is enough? and if so, why is the warning message occurring? I've slightly modified your code locally to ensure the public and secret keys are provided: Additional informationI can confirm that if the langfuse context is setup, then you fetch the handler from the context, the warning message disappears. langfuse_context.configure(
public_key=os.getenv("PUBLIC_KEY"),
secret_key=os.getenv("SECRET_KEY"),
host=os.getenv("NEXTAUTH_URL"),
)
...
@observe()
def _query_llm(
self, prompt: BasePromptTemplate | Sequence[BaseMessage] | str
) -> Any:
"""
Queries the language model with the given prompt.
"""
is_test = os.getenv("IS_EVAL", "NONE").lower() == "true"
if is_test:
return self.llm.invoke(prompt).content
else:
handler = langfuse_context.get_current_langchain_handler()
langfuse_context.update_current_trace(
session_id=self.run_id,
metadata=self.metadata,
)
return self.llm.invoke(
prompt,
config={
"callbacks": [handler],
}, # type: ignore
).content |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I found a similar discussion regarding the configuration of the Langfuse client when using the In your case, the warning message occurs because the When you manually set the Therefore, it's recommended to use |
Beta Was this translation helpful? Give feedback.
-
Hi @FaresKi - the easiest way to make sure all clients are configured correctly is to set the environment variables as described in our docs. That should silence all warnings and deliver events correctly to Langfuse: LANGFUSE_SECRET_KEY="sk-lf-..."
LANGFUSE_PUBLIC_KEY="pk-lf-..."
LANGFUSE_HOST="https://cloud.langfuse.com" # 🇪🇺 EU region
# LANGFUSE_HOST="https://us.cloud.langfuse.com" # 🇺🇸 US region |
Beta Was this translation helpful? Give feedback.
Hi @FaresKi - the easiest way to make sure all clients are configured correctly is to set the environment variables as described in our docs. That should silence all warnings and deliver events correctly to Langfuse: