Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-balfe committed Jul 6, 2024
0 parents commit 3dd6719
Show file tree
Hide file tree
Showing 9 changed files with 2,002 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to npm

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Brave Search API Library

A TypeScript library for interacting with the Brave Search API, providing easy
access to web search, local POI search, and automatic summarization features.

## Installation

Install the package using npm:

```shell
npm install brave-search
```

## Getting Started

1. Obtain a Brave Search API key from
[Brave Search API Dashboard](https://api.search.brave.com/app/keys).

2. Install the package:
```bash
npm install brave-search
```

3. Import and initialize the `BraveSearch` class:
```typescript
import { BraveSearch } from "brave-search";

const BRAVE_API_KEY = "your-api-key-here";
const braveSearch = new BraveSearch(BRAVE_API_KEY);
```

## Usage

### Web Search

Perform a web search:

```typescript
const webSearchResults = await braveSearch.webSearch("TypeScript tutorial", {
count: 5,
safesearch: "off",
search_lang: "en",
country: "US",
text_decorations: false,
});
console.log(webSearchResults);
```

### Summarized Search

Get a summarized answer for a query (requires "Data for AI pro" plan):

```typescript
const { summary, webSearchResponse } = await braveSearch.getSummarizedAnswer(
"What is TypeScript?",
{
count: 5,
safesearch: "off",
search_lang: "en",
country: "US",
text_decorations: false,
freshness: "pw",
spellcheck: false,
extra_snippets: true,
summary: true,
},
);
console.log(summary);
console.log(webSearchResponse);
```

### Local POI Search

Search for local points of interest:

```typescript
const poiResults = await braveSearch.localPoiSearch("poi_id1", "poi_id2");
console.log(poiResults);
```

### Local Descriptions Search

Get descriptions for local points of interest:

```typescript
const descriptionResults = await braveSearch.localDescriptionsSearch(
"poi_id1",
"poi_id2",
);
console.log(descriptionResults);
```

### Search Options

The library supports various search options as defined in the Brave Search API
documentation. Here are some of the available options:

```typescript
interface BraveSearchOptions {
country?: string;
search_lang?: string;
ui_lang?: string;
safesearch?: "off" | "moderate" | "strict";
freshness?: "pd" | "pw" | "pm" | "py" | string;
text_decorations?: boolean;
spellcheck?: boolean;
goggles_id?: string;
units?: "metric" | "imperial";
extra_snippets?: boolean;
count?: number;
result_filter?: ResultFilterType;
summary?: boolean;
}
```

For a complete list of options and their descriptions, please refer to the
[Brave Search API Documentation](https://api.search.brave.com/app/documentation/web-search/).

## Important Notes

- The `summary` option and `getSummarizedAnswer` method are only available with
the Brave "Data for AI pro" plan.
- For detailed information about API usage, rate limits, and pricing, please
visit the [Brave Search API Terms](https://brave.com/search/api/).

## API Reference

For detailed API reference, please refer to the
[Brave Search API Documentation](https://api.search.brave.com/app/documentation/web-search/).

## Features

- Web search
- Automatic summarization with polling
- Local POI search
- Local descriptions search
- Error handling for API requests

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the GNU General Public License v3.0 - see the
[LICENSE](LICENSE) file for details.

## Disclaimer

This library is not officially associated with Brave Software. It is a
third-party implementation of the Brave Search API.
137 changes: 137 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "brave-search",
"version": "0.5.0",
"description": "A TypeScript library for interacting with the Brave Search API, including web search, local POI search, and automatic summarization features.",
"scripts": {
"build": "tsc",
"prepare": "npm run build"
},
"main": "dist/braveSearch.js",
"types": "dist/braveSearch.d.ts",
"files": [
"dist",
"LICENSE",
"README.md"
],
"author": "[email protected]",
"license": "GPL-3.0-or-later",
"devDependencies": {
"@types/node": "^20.14.10",
"typescript": "^5.5.3"
},
"dependencies": {
"axios": "^1.7.2"
}
}
Loading

0 comments on commit 3dd6719

Please sign in to comment.