[Python] OpenAI Assistants with citations like【4:2†source】and citeturnXfileY

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    When streaming with OpenAI Assistants

    openai.beta.threads.messages.create(
    thread_id=thread_id,
    role="user",
    content=payload.question
    )

    run = openai.beta.threads.runs.create(
    thread_id=thread_id,
    assistant_id=assistant_id,
    stream=True,
    tool_choice={"type": "file_search"},
    )

    streamed_text = ""
    for event in run:
    if event.event == "thread.message.delta":
    delta_content = event.data.delta.content
    if delta_content and delta_content[0].type == "text":
    text_fragment = delta_content[0].text.value
    streamed_text += text_fragment
    yield {"data": text_fragment}
    if event.event == "thread.run.completed":
    break


    the citations are coming in the formats like 【4:2†source】 or citeturnXfileY

    [​IMG] [​IMG]

    How to fix it?

    Continue reading...

Compartilhe esta Página