[fix] TypeError: 'ChatCitation' object is not subscriptable #97
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Page:
https://docs.cohere.com/docs/crafting-effective-prompts
Code: https://github.com/cohere-ai/cohere-developer-experience/blob/main/fern/pages/text-generation/prompt-engineering/crafting-effective-prompts.mdx
Description
ChatCitation object appears to have formerly been a dict type and is now object type. Thus, access patterns for attributes 'start', 'end' and 'document_ids' have changed.
Old access pattern:
citation['start']
yield an "object is not subscriptable" error
New access pattern:
citation.start
works as intended
Stack trace
{
"name": "TypeError",
"message": "'ChatCitation' object is not subscriptable",
"stack": "---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[44], line 1
----> 1 print(insert_citations(response.text, response.citations))
Cell In[43], line 9, in insert_citations(text, citations)
6 # Process citations in the order they were provided
7 for citation in citations:
8 # Adjust start/end with offset
----> 9 start, end = citation['start'] + offset, citation['end'] + offset
10 cited_docs = [str(int(doc[4:]) + 1) for doc in citation["document_ids"]]
11 # Shorten citations if they're too long for convenience
TypeError: 'ChatCitation' object is not subscriptable"
}