Skip to content

Commit aa67929

Browse files
committed
add docs and license
1 parent 6492b4a commit aa67929

File tree

3 files changed

+95
-58
lines changed

3 files changed

+95
-58
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) 2024 Bittu Kumar
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: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,108 @@
1-
# gemini_flash
21

3-
**gemini_flash:** Client for Google's Gemini-1.5-Flash Generative AI Model
42

5-
This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon).
3+
# GeminiFlash
64

7-
## Building gemini_flash
5+
GeminiFlash is a Node.js library that leverages a Rust backend for generating content using Google's Gemini-1.5-Flash Generative AI Model. This library is designed to be efficient and easy to use, thanks to the power of Rust and the simplicity of JavaScript.
86

9-
Building gemini_flash requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support).
7+
## Installation
108

11-
To run the build, run:
9+
To install the GeminiFlash library, you can use npm:
1210

13-
```sh
14-
$ npm run build
11+
```bash
12+
npm install gemini_flash
1513
```
1614

17-
This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`.
15+
## Usage
1816

19-
## Exploring gemini_flash
17+
Here's a basic example of how to use the GeminiFlash library:
2018

21-
After building gemini_flash, you can explore its exports at the Node console:
19+
```javascript
20+
const GeminiFlash = require('gemini_flash');
2221

23-
```sh
24-
$ npm i
25-
$ npm run build
26-
$ node
27-
> require('.').hello()
28-
'hello node'
22+
const gemini_flash = new GeminiFlash('api-key-here');
23+
24+
(async () => {
25+
try {
26+
const prompt = "what is a computer?";
27+
const content = await gemini_flash.generate_content(prompt);
28+
console.log("Generated Content:", content.text);
29+
} catch (error) {
30+
console.error("Error:", error);
31+
}
32+
})();
2933
```
3034

31-
## Available Scripts
35+
### API
3236

33-
In the project directory, you can run:
37+
#### `GeminiFlash`
3438

35-
#### `npm install`
39+
##### `constructor(api_key)`
3640

37-
Installs the project, including running `npm run build`.
41+
Creates a new instance of the `GeminiFlash` class.
3842

39-
#### `npm run build`
43+
- `api_key`: Your API key for the Gemini API.
4044

41-
Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`.
45+
##### `generate_content(prompt)`
4246

43-
Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm run build` and similar commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html):
47+
Generates content based on the given prompt.
4448

45-
```
46-
npm run build -- --feature=beetle
47-
```
49+
- `prompt`: The prompt string to generate content for.
4850

49-
#### `npm run debug`
51+
**Returns**: A Promise that resolves to an object containing the generated content.
5052

51-
Similar to `npm run build` but generates a debug build with `cargo`.
53+
### Example
5254

53-
#### `npm run cross`
55+
```javascript
56+
const GeminiFlash = require('gemini_flash');
57+
58+
const gemini_flash = new GeminiFlash('your-api-key');
59+
60+
(async () => {
61+
try {
62+
const prompt = "Explain the concept of artificial intelligence.";
63+
const content = await gemini_flash.generate_content(prompt);
64+
console.log("Generated Content:", content.text);
65+
} catch (error) {
66+
console.error("Error:", error);
67+
}
68+
})();
69+
```
5470

55-
Similar to `npm run build` but uses [cross-rs](https://github.com/cross-rs/cross) to cross-compile for another platform. Use the [`CARGO_BUILD_TARGET`](https://doc.rust-lang.org/cargo/reference/config.html#buildtarget) environment variable to select the build target.
71+
## Development
5672

57-
#### `npm test`
73+
### Prerequisites
5874

59-
Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/).
75+
- [Node.js](https://nodejs.org/) (v18.20.3 or later)
76+
- [npm](https://www.npmjs.com/) (v10.7.0 or later)
77+
- [Rust](https://www.rust-lang.org/)
78+
- [Neon](https://neon-rs.dev/)
6079

61-
## Project Layout
80+
### Building the Project
6281

63-
The directory structure of this project is:
82+
To build the project, run:
6483

84+
```bash
85+
npm run build
6586
```
66-
gemini_flash/
67-
├── Cargo.toml
68-
├── README.md
69-
├── src/
70-
| └── lib.rs
71-
├── index.node
72-
├── package.json
73-
└── target/
87+
88+
### Running Tests
89+
90+
To run the tests, use:
91+
92+
```bash
93+
npm test
7494
```
7595

76-
| Entry | Purpose |
77-
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|
78-
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
79-
| `README.md` | This file. |
80-
| `src/` | The directory tree containing the Rust source code for the project. |
81-
| `lib.rs` | Entry point for the Rust source code. |
82-
| `index.node` | The main module, a [Node addon](https://nodejs.org/api/addons.html) generated by the build and pointed to by `"main"` in `package.json`. |
83-
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
84-
| `target/` | Binary artifacts generated by the Rust build. |
96+
### Additional Build Scripts
97+
98+
- **Debug build**: `npm run debug`
99+
- **Release build**: `npm run build`
100+
- **Cross build**: `npm run cross`
101+
102+
## Contributing
85103

86-
## Learn More
104+
Contributions are welcome! Please feel free to submit a pull request or open an issue if you find a bug or have a feature request.
87105

88-
Learn more about:
106+
## License
89107

90-
- [Neon](https://neon-bindings.com).
91-
- [Rust](https://www.rust-lang.org).
92-
- [Node](https://nodejs.org).
108+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"cross": "npm run cross-build -- --release"
1515
},
1616
"author": "Bittu Kumar",
17-
"license": "ISC",
17+
"license": "MIT",
1818
"devDependencies": {
1919
"@neon-rs/cli": "0.1.73"
2020
},

0 commit comments

Comments
 (0)