Skip to content

blks2cited_txt crashes when displaying document-based citations #100

@erikgaas

Description

@erikgaas

When using the Citations API with documents (via mk_ant_doc), the response displays correctly in raw form but crashes when claudette tries to pretty-print it.

To reproduce:

from claudette import Chat, models
from msglm import mk_ant_doc

doc = mk_ant_doc("The capital of France is Paris.", title="France Facts")
chat = Chat(model=models[1])
r = chat([doc, "What is the capital of France?"])
r  # crashes here

Error:

AttributeError: 'CitationCharLocation' object has no attribute 'url'

Cause:

_cite() in blks2cited_txt() assumes web search citations (which have .url), but document citations have .document_title instead.

Suggested fix:

def _cite(i, cit):
    esc = cit.cited_text.replace('"', r'\"')
    src = getattr(cit, 'url', None) or cit.document_title
    return f'[^{i+1}]: {src}\n\t"{esc}"'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions