feat: solution for 'Повторный экзамен #2: Сравнительный обзор 3 сущностей (Tavily)'
This commit is contained in:
@@ -1,66 +1,89 @@
|
||||
# Tavily Comparison Project
|
||||
# Tavily Comparative Review Utility
|
||||
|
||||
This project demonstrates how to integrate the **Tavily API** to compare three entities. It performs a search query and summarizes the top results using the official Tavily SDK.
|
||||
This project provides a simple Node.js utility to fetch a comparative review of three entities using the [Tavily](https://tavily.com) API.
|
||||
|
||||
## Features
|
||||
|
||||
- **Compare three entities**: Generate a concise comparative review for any three items.
|
||||
- **Easy integration**: Exported function `compareEntities` can be used in any Node.js project.
|
||||
- **Environment‑based configuration**: API key is loaded from a `.env` file.
|
||||
- **Robust error handling**: Handles missing parameters, API errors, and network issues.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Node.js (v18 or newer)
|
||||
- A Tavily API key. Sign up at https://tavily.com and obtain your key.
|
||||
- Node.js v18 or newer
|
||||
- A Tavily API key. Sign up at https://tavily.com to obtain one.
|
||||
|
||||
## Installation
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-2-sravnitelnyy-obzor-3.git
|
||||
cd povtornyy-ekzamen-2-sravnitelnyy-obzor-3
|
||||
1. **Clone the repository**
|
||||
|
||||
# Install dependencies
|
||||
npm install
|
||||
```
|
||||
```bash
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-2-sravnitelnyy-obzor-3.git
|
||||
cd povtornyy-ekzamen-2-sravnitelnyy-obzor-3
|
||||
```
|
||||
|
||||
## Configuration
|
||||
2. **Install dependencies**
|
||||
|
||||
Create a `.env` file in the project root with your Tavily API key:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
```env
|
||||
TAVILY_API_KEY=your_api_key_here
|
||||
```
|
||||
3. **Configure environment variables**
|
||||
|
||||
Copy the example file and set your API key:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# Edit .env and replace YOUR_TAVILY_API_KEY_HERE with your actual key
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Run the application:
|
||||
```js
|
||||
const { compareEntities } = require('./src/index');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const result = await compareEntities('Apple', 'Samsung', 'Google');
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (err) {
|
||||
console.error('Error:', err.message);
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
Run the script:
|
||||
|
||||
```bash
|
||||
npm start
|
||||
node src/index.js
|
||||
```
|
||||
|
||||
You should see output similar to:
|
||||
## Testing
|
||||
|
||||
```
|
||||
[OtherService] Starting search for: Comparison of three entities
|
||||
[OtherService] Results:
|
||||
1. Title of first result
|
||||
Summary of the first result.
|
||||
The project uses Jest for unit tests.
|
||||
|
||||
2. Title of second result
|
||||
Summary of the second result.
|
||||
|
||||
3. Title of third result
|
||||
Summary of the third result.
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
- `src/index.js` – Entry point that starts the application.
|
||||
- `src/app.js` – Orchestrates the main flow.
|
||||
- `src/services/tavily.js` – Wrapper around the Tavily SDK.
|
||||
- `src/services/otherService.js` – Simple logging utility.
|
||||
- `package.json` – Project metadata and dependencies.
|
||||
```
|
||||
├── src
|
||||
│ └── index.js # Main utility
|
||||
├── tests
|
||||
│ └── compare.test.js # Unit tests
|
||||
├── .env.example # Environment variable template
|
||||
├── .gitignore
|
||||
├── package.json
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Notes
|
||||
## License
|
||||
|
||||
- The application uses the official `tavily-sdk` package.
|
||||
- No additional external services are used beyond Tavily.
|
||||
- The code is written in ES modules (`"type": "module"` in `package.json`).
|
||||
MIT © Your Name
|
||||
|
||||
Feel free to extend the project with more sophisticated logic or additional services as needed.
|
||||
---
|
||||
|
||||
Feel free to open issues or pull requests if you encounter any problems or have suggestions for improvement.
|
||||
Reference in New Issue
Block a user