OpenAIQAWithSourcesChain class
A chain that answers questions returning a QAWithSources object containing the answers with the sources used to answer the question.
Example:
final llm = ChatOpenAI(
apiKey: openaiApiKey,
model: 'gpt-3.5-turbo-0613',
temperature: 0,
);
final qaChain = OpenAIQAWithSourcesChain(llm: llm);
final docPrompt = PromptTemplate.fromTemplate(
'Content: {page_content}\nSource: {source}',
);
final finalQAChain = StuffDocumentsChain(
llmChain: qaChain,
documentPrompt: docPrompt,
);
final retrievalQA = RetrievalQAChain(
retriever: vectorStore.asRetriever(),
combineDocumentsChain: finalQAChain,
);
const query = 'What did President Biden say about Russia?';
final res = await retrievalQA(query);
- Inheritance
-
- Object
- OpenAIQAWithStructureChain<
Object> - OpenAIQAWithSourcesChain
Constructors
- OpenAIQAWithSourcesChain({required ChatOpenAI llm})
- A chain that answers questions returning a QAWithSources object containing the answers with the sources used to answer the question.
Properties
- chainType → String
-
Return the string type key uniquely identifying this class of chain.
no setterinherited
- defaultOptions → ChainOptions
-
The default options to use when invoking the
Runnable
.finalinherited - hashCode → int
-
The hash code for this object.
no setterinherited
-
inputKeys
→ Set<
String> -
Input keys for this chain.
no setterinherited
- llm → ChatOpenAI
-
Language model to call.
finalinherited
- llmOptions → ChatOpenAIOptions?
-
Options to pass to the language model.
finalinherited
- memory → BaseChatMemory?
-
Memory to use for this chain.
finalinherited
- outputKey → String
-
Key to use for output.
finalinherited
-
outputKeys
→ Set<
String> -
Output keys for this chain.
no setterinherited
-
outputParser
→ BaseOutputParser<
Object?, OutputParserOptions, Object?> ? -
OutputParser to use.
finalinherited
- prompt → BasePromptTemplate
-
Prompt object to use.
finalinherited
- returnFinalOnly → bool
-
Whether to return only the final parsed result.
If false, it will return a bunch of extra information about the
generation.
finalinherited
- runOutputKey → String
-
Output key from where the run method needs to take the return value.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
apply(
List< ChainValues> inputs) → Future<List< ChainValues> > -
Call the chain on all inputs in the list.
inherited
-
batch(
List< ChainValues> inputs, {List<ChainOptions> ? options}) → Future<List< ChainValues> > -
Batches the invocation of the
Runnable
on the giveninputs
.inherited -
bind(
ChainOptions options) → RunnableBinding< ChainValues, ChainOptions, ChainValues> -
Binds the
Runnable
to the givenoptions
.inherited -
call(
dynamic input, {bool returnOnlyOutputs = false}) → Future< ChainValues> -
Runs the core logic of this chain with the given values.
If memory is not null, it will be used to load and save values.
inherited
-
callInternal(
ChainValues inputs) → Future< ChainValues> -
Call method to be implemented by subclasses (called by call).
This is where the core logic of the chain should be implemented.
inherited
-
close(
) → void -
Cleans up any resources associated with it the
Runnable
.inherited -
getCompatibleOptions(
RunnableOptions? options) → ChainOptions? -
Returns the given
options
if they are compatible with theRunnable
, otherwise returnsnull
.inherited -
invoke(
ChainValues input, {ChainOptions? options}) → Future< ChainValues> -
Runs the core logic of this chain with the given input.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pipe<
NewRunOutput extends Object?, NewCallOptions extends RunnableOptions> (Runnable< ChainValues, NewCallOptions, NewRunOutput> next) → RunnableSequence<ChainValues, NewRunOutput> -
Pipes the output of this
Runnable
into anotherRunnable
using aRunnableSequence
.inherited -
run(
dynamic input) → Future< String> -
Convenience method for executing chain when there's a single string
output.
inherited
-
stream(
ChainValues input, {ChainOptions? options}) → Stream< ChainValues> -
Streams the output of invoking the
Runnable
on the giveninput
.inherited -
streamFromInputStream(
Stream< ChainValues> inputStream, {ChainOptions? options}) → Stream<ChainValues> -
Streams the output of invoking the
Runnable
on the giveninputStream
.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited