搜索插件、代码仓与 APP 分类

GitHub 代码仓joegakah/pdf_gemini

pdf_gemini

该包提供了一种简单的方法,通过 Google Gemini 与 PDF 文件进行交互和聊天。

pdf_gemini 项目封面
星标
3
复刻
3
最近推送(UTC)
2025年5月28日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

Pdf Gemini Package

This package provides a simple way to interact, chat with pdf files using google gemini and managing uploaded files.

Features

  • Upload PDF to gemini
  • Prompt PDF ang get generated response with Google Gemini Api
  • Lightweight and easy to integrate into any Flutter app.

Installation

Run the command on your command prompt

flutter pub add pdf_gemini

Usage

Step 1: Import the Package

In your Dart file, import the package:

import 'package:pdf_gemini/pdf_gemini.dart';

Step 2: Provide Your API Key

When using the API service, instantiate the service class and pass your API key to it. Here's an example of how to fetch data from an API endpoint:

void main() async {
  const geminiApiKey = 'your_api_key_here';
  final genaiService = GenaiClient(geminiApiKey: geminiApiKey);

  try {
    final testFile = File('');
    final data = await genaiService.promptDocument(
      'file_name', 
      'pdf', 
      testFile.readAsBytesSync(), 
      'Your prompt',
    );
    print(data.text);
  } catch (e) {
    print('Error: $e');
  }
}
Example Explained:
  • Replace 'your_api_key_here' with your actual API key provided by the service you're integrating.
  • The promptDocument() method accepts the document and prompt input and returns the generated response as a model (text: text, citations: sources) if successful.
  • Make sure to handle exceptions in case of a failed request.

Testing

To ensure your package works as expected, you can write tests to mock API responses. Here's a simple test example:

import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:pdf_gemini/pdf_gemini.dart';

void main() {
  group('PDFChatClient', () {
    const geminiApiKey = '';
    final genaiService = GenaiClient(geminiApiKey: geminiApiKey);

    test('Prompt PDF Test', () async {
      // Create a temporary test file
      final testFile = File('your_file_path').readAsBytesSync();

      try {
        await genaiService.promptDocument(
          fileName: 'Your file name',
          fileType: 'pdf',
          fileData: testFile,
          prompt: 'your prompt',
          model: 'gemini-1.5-flash',
        );
      } catch (e) {
        fail('Failed: $e');
      }
    });
  });
}

Contributing

Contributions are welcome! If you'd like to improve this package, feel free to fork the repository and submit a pull request. Make sure to write tests for any new features.

License

This project is licensed under the BSD 3-clause license - see the LICENSE file for details.

Joseph Gakah GitHub avatar
GitHub 作者

Joseph Gakah ↗

@Neurollect

语言Dart

分类

使用的依赖

依赖清单 4 项

  • flutter{"sdk":"flutter"}
  • dio^5.7.0
  • flutter_test开发依赖{"sdk":"flutter"}
  • flutter_lints开发依赖^5.0.0

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗