|
24 | 24 | OpenAI, |
25 | 25 | ) |
26 | 26 |
|
27 | | -from langfuse.callback import CallbackHandler |
28 | | -from langfuse.extract_model import _extract_model_name |
| 27 | +from langfuse.langchain import CallbackHandler |
| 28 | +from langfuse.langchain.utils import _extract_model_name |
29 | 29 | from tests.utils import get_api |
30 | 30 |
|
31 | 31 |
|
@@ -134,20 +134,24 @@ def test_models(expected_model: str, model: Any): |
134 | 134 | ) |
135 | 135 | def test_entire_llm_call(expected_model, model): |
136 | 136 | callback = CallbackHandler() |
137 | | - try: |
138 | | - # LLM calls are failing, because of missing API keys etc. |
139 | | - # However, we are still able to extract the model names beforehand. |
140 | | - model.invoke("Hello, how are you?", config={"callbacks": [callback]}) |
141 | | - except Exception as e: |
142 | | - print(e) |
143 | | - pass |
144 | 137 |
|
145 | | - callback.flush() |
| 138 | + with callback.langfuse_client.start_as_current_span(name="parent") as span: |
| 139 | + trace_id = span.trace_id |
| 140 | + |
| 141 | + try: |
| 142 | + # LLM calls are failing, because of missing API keys etc. |
| 143 | + # However, we are still able to extract the model names beforehand. |
| 144 | + model.invoke("Hello, how are you?", config={"callbacks": [callback]}) |
| 145 | + except Exception as e: |
| 146 | + print(e) |
| 147 | + pass |
| 148 | + |
| 149 | + callback.langfuse_client.flush() |
146 | 150 | api = get_api() |
147 | 151 |
|
148 | | - trace = api.trace.get(callback.get_trace_id()) |
| 152 | + trace = api.trace.get(trace_id) |
149 | 153 |
|
150 | | - assert len(trace.observations) == 1 |
| 154 | + assert len(trace.observations) == 2 |
151 | 155 |
|
152 | 156 | generation = list(filter(lambda o: o.type == "GENERATION", trace.observations))[0] |
153 | 157 | assert generation.model == expected_model |
0 commit comments