Implementation:AI4Finance Foundation FinGPT get prompt
| Knowledge Sources | |
|---|---|
| Domains | NLP, Prompt_Engineering |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for formatting instruction-response prompts from templates provided by the FinGPT Benchmark utilities.
Description
The get_prompt function formats an instruction and input text using a predefined template. The default template is `Instruction: {instruction}\nInput: {input}\nAnswer: `. If no instruction is provided, it returns the input text directly. This function is used by the `tokenize` function to construct the prompt portion of training examples.
Usage
Import this function when you need to format instructions into a standard prompt template:
- Benchmark training: Formatting financial task instructions for tokenization.
- Custom templates: Using alternative instruction templates via the template_dict.
Code Reference
Source Location
- Repository: FinGPT
- File: fingpt/FinGPT_Benchmark/utils.py
- Lines: L5-45
Signature
template_dict = {
'default': 'Instruction: {instruction}\nInput: {input}\nAnswer: '
}
def get_prompt(
template: str,
instruction: str,
input_text: str,
) -> str
Import
from utils import get_prompt
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| template | str | Yes | Template key in template_dict (e.g., 'default') |
| instruction | str | Yes | Instruction text (empty returns input_text only) |
| input_text | str | Yes | Input text to include in the prompt |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | str | Formatted prompt string |
Usage Examples
Format Standard Instruction Prompt
from utils import get_prompt
prompt = get_prompt(
template='default',
instruction='What is the sentiment of this news?',
input='Apple reported record quarterly earnings.',
)
# "Instruction: What is the sentiment of this news?\n
# Input: Apple reported record quarterly earnings.\nAnswer: "