Skip to content

Commit c48d0c8

Browse files
committed
fix: Correct the file and funciton
1 parent 1af829d commit c48d0c8

File tree

5 files changed

+252
-39
lines changed

5 files changed

+252
-39
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 perplexity
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ To use any of the projects in this repository, you'll need:
3434
Each project includes its own README with specific installation and usage instructions.
3535

3636

37+
## License
38+
39+
Unless otherwise specified, all projects in this repository are licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
3740

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,107 @@
1-
# Research Finder CLI
1+
# Academic Research Finder CLI
22

3-
A tool to research topics using Perplexity Sonar API.
3+
A command-line tool that uses Perplexity's Sonar API to find and summarize academic literature (research papers, articles, etc.) related to a given question or topic.
44

5-
*More details to come.*
5+
## Features
6+
7+
- Takes a natural language question or topic as input, ideally suited for academic inquiry.
8+
- Leverages Perplexity Sonar API, guided by a specialized prompt to prioritize scholarly sources (e.g., journals, conference proceedings, academic databases).
9+
- Outputs a concise summary based on the findings from academic literature.
10+
- Lists the primary academic sources used, aiming to include details like authors, year, title, publication, and DOI/link when possible.
11+
- Supports different Perplexity models (defaults to `sonar-pro`).
12+
- Allows results to be output in JSON format.
13+
14+
## Installation
15+
16+
### 1. Install required dependencies
17+
18+
Ensure you are using the Python environment you intend to run the script with (e.g., `python3.10` if that's your target).
19+
20+
```bash
21+
pip install requests
22+
```
23+
*(Note: `requests` is the primary dependency. Ensure your Python environment can execute it.)*
24+
25+
### 2. Make the script executable (Optional)
26+
27+
```bash
28+
chmod +x research_finder.py
29+
```
30+
Alternatively, you can run the script using `python3 research_finder.py ...`.
31+
32+
## API Key Setup
33+
34+
The tool requires a Perplexity API key (`PPLX_API_KEY`) to function. You can provide it in one of these ways (checked in this order):
35+
36+
1. **As a command-line argument:**
37+
```bash
38+
python3 research_finder.py "Your query" --api-key YOUR_API_KEY
39+
```
40+
2. **As an environment variable:**
41+
```bash
42+
export PPLX_API_KEY=YOUR_API_KEY
43+
python3 research_finder.py "Your query"
44+
```
45+
3. **In a file:** Create a file named `pplx_api_key`, `.pplx_api_key`, `PPLX_API_KEY`, or `.PPLX_API_KEY` in the *same directory as the script* or in the *current working directory* containing just your API key.
46+
```bash
47+
echo "YOUR_API_KEY" > .pplx_api_key
48+
chmod 600 .pplx_api_key # Optional: restrict permissions
49+
python3 research_finder.py "Your query"
50+
```
51+
52+
## Usage
53+
54+
Run the script from the `sonar-use-cases/research_finder` directory or provide the full path.
55+
56+
```bash
57+
# Basic usage
58+
python3 research_finder.py "What are the latest advancements in quantum computing?"
59+
60+
# Using a specific model
61+
python3 research_finder.py "Explain the concept of Large Language Models" --model sonar-small-online
62+
63+
# Getting output as JSON
64+
python3 research_finder.py "Summarize the plot of Dune Part Two" --json
65+
66+
# Using a custom system prompt file
67+
python3 research_finder.py "Benefits of renewable energy" --prompt-file /path/to/your/custom_prompt.md
68+
69+
# Using an API key via argument
70+
python3 research_finder.py "Who won the last FIFA World Cup?" --api-key sk-...
71+
72+
# Using the executable (if chmod +x was used)
73+
./research_finder.py "Latest news about Mars exploration"
74+
```
75+
76+
### Arguments
77+
78+
- `query`: (Required) The research question or topic (enclose in quotes if it contains spaces).
79+
- `-m`, `--model`: Specify the Perplexity model (default: `sonar-pro`).
80+
- `-k`, `--api-key`: Provide the API key directly.
81+
- `-p`, `--prompt-file`: Path to a custom system prompt file.
82+
- `-j`, `--json`: Output the results in JSON format.
83+
84+
## Example Output (Human-Readable - *Note: Actual output depends heavily on the query and API results*)
85+
86+
```
87+
Initializing research assistant for query: "Recent studies on transformer models in NLP"...
88+
Researching in progress...
89+
90+
✅ Research Complete!
91+
92+
📝 SUMMARY:
93+
Recent studies on transformer models in Natural Language Processing (NLP) continue to explore architectural improvements, efficiency optimizations, and new applications. Key areas include modifications to the attention mechanism (e.g., sparse attention, linear attention) to handle longer sequences more efficiently, techniques for model compression and knowledge distillation, and applications beyond text, such as in computer vision and multimodal tasks. Research also focuses on understanding the internal workings and limitations of large transformer models.
94+
95+
🔗 SOURCES:
96+
1. Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I. (2017). Attention is all you need. Advances in neural information processing systems, 30. (arXiv:1706.03762)
97+
2. Tay, Y., Dehghani, M., Bahri, D., & Metzler, D. (2020). Efficient transformers: A survey. arXiv preprint arXiv:2009.06732.
98+
3. Beltagy, I., Peters, M. E., & Cohan, A. (2020). Longformer: The long-document transformer. arXiv preprint arXiv:2004.05150.
99+
4. Rogers, A., Kovaleva, O., & Rumshisky, A. (2020). A primer in bertology: What we know about how bert works. Transactions of the Association for Computational Linguistics, 8, 842-866. (arXiv:2002.12327)
100+
```
101+
102+
## Limitations
103+
104+
- The ability of the Sonar API to consistently prioritize and access specific academic databases or extract detailed citation information (like DOIs) may vary. The quality depends on the API's search capabilities and the structure of the source websites.
105+
- The script performs basic parsing to separate summary and sources; complex or unusual API responses might not be parsed perfectly. Check the raw response in case of issues.
106+
- Queries that are too broad or not well-suited for academic search might yield less relevant results.
107+
- Error handling for API rate limits or specific API errors could be more granular.

0 commit comments

Comments
 (0)