Skip to content

Commit

Permalink
Merge pull request #1074 from kga245/feature/add-tone-argument
Browse files Browse the repository at this point in the history
Feature/add tone argument
  • Loading branch information
ElishaKay authored Jan 11, 2025
2 parents e074659 + cf8a84e commit e5adce2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
38 changes: 36 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dotenv import load_dotenv

from gpt_researcher import GPTResearcher
from gpt_researcher.utils.enum import ReportType
from gpt_researcher.utils.enum import ReportType, Tone
from backend.report_type import DetailedReport

# =============================================================================
Expand Down Expand Up @@ -64,6 +64,19 @@
choices=choices,
required=True)

# First, let's see what values are actually in the Tone enum
print([t.value for t in Tone])

cli.add_argument(
"--tone",
type=str,
help="The tone of the report (optional).",
choices=["objective", "formal", "analytical", "persuasive", "informative",
"explanatory", "descriptive", "critical", "comparative", "speculative",
"reflective", "narrative", "humorous", "optimistic", "pessimistic"],
default="objective"
)

# =============================================================================
# Main
# =============================================================================
Expand All @@ -83,9 +96,30 @@ async def main(args):

report = await detailed_report.run()
else:
# Convert the simple keyword to the full Tone enum value
tone_map = {
"objective": Tone.Objective,
"formal": Tone.Formal,
"analytical": Tone.Analytical,
"persuasive": Tone.Persuasive,
"informative": Tone.Informative,
"explanatory": Tone.Explanatory,
"descriptive": Tone.Descriptive,
"critical": Tone.Critical,
"comparative": Tone.Comparative,
"speculative": Tone.Speculative,
"reflective": Tone.Reflective,
"narrative": Tone.Narrative,
"humorous": Tone.Humorous,
"optimistic": Tone.Optimistic,
"pessimistic": Tone.Pessimistic
}

researcher = GPTResearcher(
query=args.query,
report_type=args.report_type)
report_type=args.report_type,
tone=tone_map[args.tone]
)

await researcher.conduct_research()

Expand Down
29 changes: 23 additions & 6 deletions docs/docs/gpt-researcher/getting-started/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This command-line interface (CLI) tool allows you to generate research reports u
The basic syntax for using the CLI is:

```
python cli.py "<query>" --report_type <report_type>
python cli.py "<query>" --report_type <report_type> [--tone <tone>]
```

### Arguments
Expand All @@ -36,6 +36,22 @@ python cli.py "<query>" --report_type <report_type>
- `outline_report`
- `custom_report`
- `subtopic_report`
- `--tone` (optional): The tone of the report. Defaults to 'objective'. Options include:
- `objective`: Impartial and unbiased presentation
- `formal`: Academic standards with sophisticated language
- `analytical`: Critical evaluation and examination
- `persuasive`: Convincing viewpoint
- `informative`: Clear and comprehensive information
- `explanatory`: Clarifying complex concepts
- `descriptive`: Detailed depiction
- `critical`: Judging validity and relevance
- `comparative`: Juxtaposing different theories
- `speculative`: Exploring hypotheses
- `reflective`: Personal insights
- `narrative`: Story-based presentation
- `humorous`: Light-hearted and engaging
- `optimistic`: Highlighting positive aspects
- `pessimistic`: Focusing on challenges

## Examples

Expand All @@ -44,14 +60,14 @@ python cli.py "<query>" --report_type <report_type>
python cli.py "What are the main causes of climate change?" --report_type research_report
```

2. Create a detailed report on artificial intelligence:
2. Create a detailed report on artificial intelligence with an analytical tone:
```
python cli.py "The impact of artificial intelligence on job markets" --report_type detailed_report
python cli.py "The impact of artificial intelligence on job markets" --report_type detailed_report --tone analytical
```

3. Generate an outline report on renewable energy:
3. Generate an outline report on renewable energy with a persuasive tone:
```
python cli.py "Renewable energy sources and their potential" --report_type outline_report
python cli.py "Renewable energy sources and their potential" --report_type outline_report --tone persuasive
```

## Output
Expand All @@ -61,4 +77,5 @@ The generated report will be saved as a Markdown file in the `outputs` directory
## Note

- The execution time may vary depending on the complexity of the query and the type of report requested.
- Make sure you have the necessary API keys and permissions set up in your `.env` file for the tool to function correctly.
- Make sure you have the necessary API keys and permissions set up in your `.env` file for the tool to function correctly.
- All tone options should be provided in lowercase.

0 comments on commit e5adce2

Please sign in to comment.