Assigning name for multiple generation observations #12943
-
Describe your questionI am having many generation observation names as response, I want to assign names for them, how to do Langfuse Cloud or Self-Hosted?Langfuse Cloud If Self-HostedNo response If Langfuse CloudNo response SDK and integration versionsNo response Pre-Submission Checklist
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You can assign custom names to generation observations using the Using the Context ManagerWhen using from langfuse import get_client
langfuse = get_client()
with langfuse.start_as_current_observation(as_type="span", name="outer-process") as outer_span:
with langfuse.start_as_current_observation(as_type="generation", name="llm-step-1") as gen1:
# gen1 is active, child of outer_span
gen1.update(output="LLM 1 output")
with langfuse.start_as_current_observation(as_type="generation", name="llm-step-2") as gen2:
# gen2 is active, child of outer_span
gen2.update(output="LLM 2 output")Each generation observation gets its own descriptive name ( For Nested GenerationsYou can also create generations as children of other spans: with outer_span.start_as_current_observation(name="intermediate-step") as mid_span:
with mid_span.start_as_current_observation(as_type="generation", name="llm-step-2") as gen2:
gen2.update(output="LLM 2 output")Using the @observe DecoratorIf you're using the decorator approach, set the name directly in the decorator: from langfuse import observe
@observe(name="llm-call", as_type="generation")
async def my_async_llm_call(prompt_text):
return "LLM response"For each generation step in your code, simply add the 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
You can assign custom names to generation observations using the
nameparameter when creating them with the context manager.Using the Context Manager
When using
start_as_current_observation(), pass thenameparameter directly: