Comments (2)
You can just adjust your prompts to the LLM of your choosing.
Here is an example from Anthropic:
https://docs.anthropic.com/claude/page/cite-your-sources
My point is, llamaIndex and all these libraries very often don't do anything special, but just have prompt templates they use agains the LLM you choose.
You can inspect the source code yourself here: https://github.com/run-llama/llama_index/blob/cfb2d7a58a8b8fe070ece26322b7df39e8d2b804/llama-index-core/llama_index/core/query_engine/citation_query_engine.py#L32
from raptor.
Adding on to @tskippervold answer, you can adjust define your own custom prompt by defining your own QAModel.
For example, to use your GPT-3 Turbo as a QA model with a prompt asking for citations, you can do the following:
from raptor import RetrievalAugmentation, RetrievalAugmentationConfig, BaseQAModel
from openai import OpenAI
from tenacity import retry, stop_after_attempt, wait_random_exponential
class GPT3TurboCitationQAModel(BaseQAModel):
def __init__(self, model="gpt-3.5-turbo"):
self.model = model
self.client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
@retry(wait=wait_random_exponential(min=1, max=20), stop=stop_after_attempt(6))
def _attempt_answer_question(
self, context, question, max_tokens=150, stop_sequence=None
):
response = self.client.chat.completions.create(
model=self.model,
messages=[
{"role": "system", "content": "You are an expert research assistant."},
{
"role": "user",
"content": f"Given the following context:\n\n{context}\n\nAnswer the question: {question}\n\nPlease provide the most relevant and concise answer, and cite the specific parts of the context that support your answer.",
},
],
temperature=0,
)
return response.choices[0].message.content.strip()
@retry(wait=wait_random_exponential(min=1, max=20), stop=stop_after_attempt(6))
def answer_question(self, context, question, max_tokens=150, stop_sequence=None):
try:
return self._attempt_answer_question(
context, question, max_tokens=max_tokens, stop_sequence=stop_sequence
)
except Exception as e:
print(e)
return e
RAC = RetrievalAugmentationConfig(qa_model=GPT3TurboCitationQAModel())
RA = RetrievalAugmentation(config=RAC)
RA.add_documents(text)
You can try experimenting with different prompts, or even try stronger models. If you have a sample dataset of questions and answers with citations, you could also use DSPy (https://github.com/stanfordnlp/dspy) to automatically optimize the prompt for your specific use case.
from raptor.
Related Issues (20)
- Question: How to get the context used when calling `RA.answer_question`? HOT 2
- Want to use RAPTOR for legal research. How to add legislation citation? HOT 2
- Clarification about the experiment setting in the paper HOT 2
- NarrativeQA metrics
- TypeError: Cannot use scipy.linalg.eigh for sparse A with k >= N. Use scipy.linalg.eigh(A.toarray()) or reduce k. HOT 4
- Question about multiple texts HOT 3
- Question about experiment HOT 3
- When the text gets longer, the embedding API does not seem to work. HOT 5
- Missing implied functionality `add to existing` HOT 3
- Support for Azure OpenAi HOT 2
- Constructing Layer Issue HOT 3
- Is it not possible to use in AZURE? HOT 1
- Adding new Document to the existing RAPTOR setup
- num_layers acts like max_num_layers HOT 2
- UMAP n_neighbors must be greater than 1 HOT 10
- Inquiring about Vector DB implementation HOT 2
- RAG seems lazy and don't understand the sample HOT 1
- Sorry! We've encountered an issue with repetitive patterns in your prompt. Please try again with a different prompt HOT 10
- `RA.retrieve`: AttributeError: 'NoneType' object has no attribute 'encode'" HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raptor.