|
1 | | -# gemini_flash |
2 | 1 |
|
3 | | -**gemini_flash:** Client for Google's Gemini-1.5-Flash Generative AI Model |
4 | 2 |
|
5 | | -This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon). |
| 3 | +# GeminiFlash |
6 | 4 |
|
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. |
8 | 6 |
|
9 | | -Building gemini_flash requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support). |
| 7 | +## Installation |
10 | 8 |
|
11 | | -To run the build, run: |
| 9 | +To install the GeminiFlash library, you can use npm: |
12 | 10 |
|
13 | | -```sh |
14 | | -$ npm run build |
| 11 | +```bash |
| 12 | +npm install gemini_flash |
15 | 13 | ``` |
16 | 14 |
|
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 |
18 | 16 |
|
19 | | -## Exploring gemini_flash |
| 17 | +Here's a basic example of how to use the GeminiFlash library: |
20 | 18 |
|
21 | | -After building gemini_flash, you can explore its exports at the Node console: |
| 19 | +```javascript |
| 20 | +const GeminiFlash = require('gemini_flash'); |
22 | 21 |
|
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 | +})(); |
29 | 33 | ``` |
30 | 34 |
|
31 | | -## Available Scripts |
| 35 | +### API |
32 | 36 |
|
33 | | -In the project directory, you can run: |
| 37 | +#### `GeminiFlash` |
34 | 38 |
|
35 | | -#### `npm install` |
| 39 | +##### `constructor(api_key)` |
36 | 40 |
|
37 | | -Installs the project, including running `npm run build`. |
| 41 | +Creates a new instance of the `GeminiFlash` class. |
38 | 42 |
|
39 | | -#### `npm run build` |
| 43 | +- `api_key`: Your API key for the Gemini API. |
40 | 44 |
|
41 | | -Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`. |
| 45 | +##### `generate_content(prompt)` |
42 | 46 |
|
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. |
44 | 48 |
|
45 | | -``` |
46 | | -npm run build -- --feature=beetle |
47 | | -``` |
| 49 | +- `prompt`: The prompt string to generate content for. |
48 | 50 |
|
49 | | -#### `npm run debug` |
| 51 | +**Returns**: A Promise that resolves to an object containing the generated content. |
50 | 52 |
|
51 | | -Similar to `npm run build` but generates a debug build with `cargo`. |
| 53 | +### Example |
52 | 54 |
|
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 | +``` |
54 | 70 |
|
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 |
56 | 72 |
|
57 | | -#### `npm test` |
| 73 | +### Prerequisites |
58 | 74 |
|
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/) |
60 | 79 |
|
61 | | -## Project Layout |
| 80 | +### Building the Project |
62 | 81 |
|
63 | | -The directory structure of this project is: |
| 82 | +To build the project, run: |
64 | 83 |
|
| 84 | +```bash |
| 85 | +npm run build |
65 | 86 | ``` |
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 |
74 | 94 | ``` |
75 | 95 |
|
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 |
85 | 103 |
|
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. |
87 | 105 |
|
88 | | -Learn more about: |
| 106 | +## License |
89 | 107 |
|
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. |
0 commit comments