Navneeth Krishnan
09/22/2025, 2:55 PM"content": [
{"type": "text", "text": lab_prompt},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{image_data}"
}
}
]
Hey guys! At the moment llm_generate function does not support prompt message content like the one above…. I tried, but get type error and other issues. Is this assumption correct or am I doing something wrong?
Also, in the llm_generate function implementation, while the expected value type of prompt content is “str” (which is not always the case especially when working with vision models as shown above) …I noticed that prompt content is passed as it is… but then I still face type issues.
Can I go around this limitation somehow or do I need to write my own udf for this?Kevin Wang
09/22/2025, 5:41 PMllm_generate , would you happen to know how to get this to work?Everett Kleven
09/22/2025, 6:09 PMfrom typing import Any
import asyncio
import daft
from openai import AsyncOpenAI
@daft.udf(return_dtype=daft.DataType.string())
class StructuredOutputsProdUDF:
def __init__(self, base_url: str, api_key: str):
self.client = AsyncOpenAI(base_url=base_url, api_key=api_key)
try:
self.loop = asyncio.get_running_loop()
except RuntimeError:
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def __call__(self,
model_id: str,
text_col: daft.Series,
image_col: daft.Series,
sampling_params: dict[str, Any] | None = None,
extra_body: dict[str, Any] | None = None
) -> list[str]:
async def generate(text: str, image: str) -> str:
content = []
if image:
content.append({
"type": "image_url",
"image_url": {"url": f"data:image/png;base64,{image}"},
})
if text:
content.append({"type": "text", "text": text})
result = await self.client.chat.completions.create(
messages=[
{
"role": "user",
"content": content # Dataset prefers image first
}
],
model=model_id,
extra_body=extra_body,
**sampling_params
)
return result.choices[0].message.content
async def gather_completions(texts,images) -> list[str]:
tasks = [generate(t,i) for t,i in zip(texts,images)]
return await asyncio.gather(*tasks)
texts = text_col.to_pylist()
images = image_col.to_pylist()
return self.loop.run_until_complete(gather_completions(texts,images))Everett Kleven
09/22/2025, 6:12 PMNavneeth Krishnan
09/22/2025, 6:15 PM