|
36 | 36 | from langfuse.callback import CallbackHandler |
37 | 37 | from langfuse.client import Langfuse |
38 | 38 | from tests.api_wrapper import LangfuseAPI |
39 | | -from tests.utils import create_uuid, get_api |
| 39 | +from tests.utils import create_uuid, encode_file_to_base64, get_api |
40 | 40 |
|
41 | 41 |
|
42 | 42 | def test_callback_init(): |
@@ -2210,3 +2210,39 @@ def _generate_random_dict(n: int, key_length: int = 8) -> Dict[str, Any]: |
2210 | 2210 | print(f"Full execution took {duration_full}ms") |
2211 | 2211 |
|
2212 | 2212 | assert duration_full > 1000, "Full execution should take longer than 1 second" |
| 2213 | + |
| 2214 | + |
| 2215 | +def test_multimodal(): |
| 2216 | + api = get_api() |
| 2217 | + handler = CallbackHandler() |
| 2218 | + model = ChatOpenAI(model="gpt-4o-mini") |
| 2219 | + |
| 2220 | + image_data = encode_file_to_base64("static/puton.jpg") |
| 2221 | + |
| 2222 | + message = HumanMessage( |
| 2223 | + content=[ |
| 2224 | + {"type": "text", "text": "What's in this image?"}, |
| 2225 | + { |
| 2226 | + "type": "image_url", |
| 2227 | + "image_url": {"url": f"data:image/jpeg;base64,{image_data}"}, |
| 2228 | + }, |
| 2229 | + ], |
| 2230 | + ) |
| 2231 | + |
| 2232 | + response = model.invoke([message], config={"callbacks": [handler]}) |
| 2233 | + |
| 2234 | + print(response.content) |
| 2235 | + |
| 2236 | + handler.flush() |
| 2237 | + |
| 2238 | + trace = api.trace.get(handler.get_trace_id()) |
| 2239 | + |
| 2240 | + assert len(trace.observations) == 1 |
| 2241 | + assert trace.observations[0].type == "GENERATION" |
| 2242 | + |
| 2243 | + print(trace.observations[0].input) |
| 2244 | + |
| 2245 | + assert ( |
| 2246 | + "@@@langfuseMedia:type=image/jpeg|id=" |
| 2247 | + in trace.observations[0].input[0]["content"][1]["image_url"]["url"] |
| 2248 | + ) |
0 commit comments