How to return citations from Agent? #27208 #27235
Replies: 1 comment 6 replies
-
I found a similar discussion on how to return citations from an Agent in LangChain [1]. Here's how you can add inline citations to text using the Agent:
Here's an example setup: from langchain.chains import create_citation_fuzzy_match_chain
from langchain_openai import ChatOpenAI
question = "What did the author do during college?"
context = """
My name is Jason Liu, and I grew up in Toronto Canada but I was born in China.
I went to an arts highschool but in university I studied Computational Mathematics and physics.
As part of coop I worked at many companies including Stitchfix, Facebook.
I also started the Data Science club at the University of Waterloo and I was the president of the club for 2 years.
"""
llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613")
chain = create_citation_fuzzy_match_chain(llm)
result = chain.run(question=question, context=context)
def highlight(text, span):
return (
"..."
+ text[span[0] - 20 : span[0]]
+ "*"
+ "\033[91m"
+ text[span[0] : span[1]]
+ "\033[0m"
+ "*"
+ text[span[1] : span[1] + 20]
+ "..."
)
for fact in result.answer:
print("Statement:", fact.fact)
for span in fact.get_spans(context):
print("Citation:", highlight(context, span))
print() This setup will allow you to generate text with inline citations based on the agent's observations and grounded answers [2][3][4][5]. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am using Agent from Langchain and would like to return inline citations in a text. For example: "Messi is a.... [1]" where [1] is a citation and I can display it.
Currently, my application allows me to return output from tools so I have access to the whole fetched content from different tools but I would like to add inline citations with core information.
Is it possible to do it?
I saw the documentation but I don't understand how to add it to Agent.
Beta Was this translation helpful? Give feedback.
All reactions