openai_client 包是一个非官方的、跨平台的 Dart 客户端,用于与 OpenAI 的 AI 模型进行交互。它使开发者能够将生成式 AI 功能(如文本生成和聊天回复)集成到 Android、iOS、macOS、Windows 和 Linux 上的 Flutter 应用中。该客户端设计简洁灵活,支持多种 OpenAI 端点,无需编写特定于平台的代码。客户端抽象了 HTTP 交互,使得使用 API 密钥进行身份验证和发送请求变得简单。非常适合在跨平台应用中构建 AI 功能。
适合场景
将聊天机器人集成到移动和桌面应用程序中
使用GPT模型生成内容
使用自然语言处理构建人工智能助手
启用实时文本补全
创建多语言翻译工具
主要特点
跨平台兼容性
OpenAI 接口的简单 API
通过 API 密钥支持身份验证
异步请求处理
轻量且易于集成
适合对象
Flutter 开发人员构建人工智能驱动的应用程序
需要多平台人工智能集成的团队
需要生成文本功能的项目
快速原型化AI功能
同时面向移动和桌面用户的App
使用建议
非官方客户端——在 OpenAI API 更新后可能需要更新
需要对 API 密钥进行妥善管理
依赖稳定的互联网连接
仅限OpenAI的可用模型
不适用于高频或关键任务型人工智能工作负载
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
The OpenAI API can be applied to virtually any task that involves understanding or generating natural language or code. They offer a spectrum of models with different levels of power suitable for different tasks, as well as the ability to fine-tune your own custom models.
ℹ️ Info
This is an unofficial client, written purely in Dart that allows you to easily use the API in your Dart or Flutter projects.
You can install the package by adding it to your pubspec.yaml file.
dependencies:openai_client:last_version
After the installation you would just need to import the package in your project.
import'package:openai_client/openai_client.dart';
🚀 Getting Started
In order to use the API, you need to have an API key. You can get one here and once you have it, you can use it in the client passing the key itself in the OpenAIConfiguration constructor.
// Create the configurationfinal conf = OpenAIConfiguration(
apiKey: 'Your API key',
organizationId: 'Your organization ID', // Optional
);
// Create a new clientfinal client = OpenAIClient(configuration: conf);
🐛 Debugging
For testing and debugging purposes, you can use the built-in Logger to more easily check the status of requests and responses.
By default, the Logger is disabled. You can enable it by setting the enableLogging property to true.
// The instance of the client with the logger enabledfinal client = OpenAIClient(
...
enableLogging: true,
);
🎯 Examples
The provided example is a simple command line application that allows you to test the client. You can find it in the example folder.
📚 Documentation
The full documentation of the project is available here. All the methods are documented, and you can easily check the parameters that you can pass to them.
🤝 Contributing
If you want to contribute to openai_client, please make sure to review the contribution guidelines.
This project makes use of GitHub issues for
tracking requests and bugs only, so please don't use issues for general questions and discussion.