Question Answering
This example demonstrates how to use the QuestionAnswer
function in gollm to create a flexible question-answering system. It showcases the ability to provide context, examples, and specific directives to guide the LLM in generating a relevant and concise answer.
The use of prompt templates and options in both the implementation and usage of the QuestionAnswer
function highlights the flexibility and power of the gollm package in handling various NLP tasks.
Let's start with the question_answer.go
file:
Prompt Template Definition: A prompt template for question answering is defined:
This template includes a default directive to provide a clear and concise answer, and specifies an output format.
QuestionAnswer Function: The
QuestionAnswer
function is implemented as follows:This function:
Executes the question answer template with the provided question
Applies any additional options passed to the function
Generates a response using the LLM client
Returns the generated answer
Now, let's look at the question_answer_example.go
file:
Initializing the LLM Client: The example starts by creating an LLM instance with a maximum token limit:
Defining the Question and Context: A question about quantum computing challenges is defined, along with some context information:
Using the QuestionAnswer Function: The example uses the
gollm.QuestionAnswer
function to generate an answer:This call to
QuestionAnswer
includes several options:WithContext
: Provides additional context about quantum computingWithExamples
: Gives an example of how to structure the answerWithMaxLength
: Limits the answer to 200 wordsWithDirectives
: Provides specific instructions for answering the question
Displaying the Results: Finally, the example prints the question, context, and the generated answer.
Last updated