Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] TypeError: 'ChatCitation' object is not subscriptable #97

Conversation

interimblue
Copy link
Contributor

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"
}

@interimblue interimblue requested a review from a team as a code owner September 3, 2024 19:40
@billytrend-cohere billytrend-cohere merged commit 8acedf2 into cohere-ai:main Sep 18, 2024
1 check failed
billytrend-cohere pushed a commit that referenced this pull request Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants