openai

開放AI的非官方Dart與Flutter SDK。完整的API覆蓋範圍,並支援OpenAI相容的提供者(Azure、DeepSeek、LM Studio、Ollama):回應、聊天、即時、V

openai 是什麼?

開放AI的非官方Dart與Flutter SDK。完整的API覆蓋範圍,並支援OpenAI相容的提供者(Azure、DeepSeek、LM Studio、Ollama):回應、聊天、即時、影片、批次、微調。

openai 概覽

這是什麼

dart_openai 是一個非官方的 Dart/Flutter SDK,用於 OpenAI API。它為每個主要的 API 表面提供型別化的客戶端,包括 Responses、Chat Completions、Realtime、Videos、Batch、Fine-tuning、Vector Stores、Evals、Administration 等。此 SDK 可在 Android、iOS、macOS、Linux、Windows、網頁和伺服器端 Dart 上編譯與執行。由 Anas Fikhi (@anasfik) 維護。

主要功能

  • 完整的 API 覆蓋:Responses、Chat、Audio、Images、Embeddings、Files、Batch、Vector Stores、Fine-tuning、Videos、Realtime 以及舊版的 Completions 和 Edits。
  • 支援 OpenAI 相容的提供者:Azure、DeepSeek、LM Studio、Ollama、Groq、Together 等。
  • 串流功能使用單一 SSE 引擎,在 [DONE] 時關閉,不會重複事件,並將錯誤以例外形式呈現。
  • 彈性:在暫時性失敗(連線錯誤、HTTP 408/429/5xx)時自動重試,採用指數退避與抖動;可設定重試策略。
  • 平台中立的檔案上傳,使用 OpenAIFile 型別,無需 dart:io 相依,可在網頁上運作。
  • 型別化的例外處理,可精確捕捉錯誤:RequestFailedException、MissingApiKeyException、OpenAIUnexpectedException。
  • 支援 Azure OpenAI,可對應部署名稱。

使用情境

  • 建立與 OpenAI API 互動的 Dart/Flutter 應用程式。
  • 使用 OpenAI 相容的提供者,如 Azure、DeepSeek、LM Studio 或 Ollama。
  • 串流回應聊天補全、圖片等端點。
  • 微調模型、管理向量儲存庫及批次處理。
  • 執行管理任務,如管理專案、使用者、邀請、稽核日誌和 API 金鑰。

快速開始

在 pubspec.yaml 中加入相依性: yaml dependencies: dart_openai: ^8.0.0 然後執行: bash dart pub get 快速入門範例: dart import 'package:dart_openai/dart_openai.dart'; Future main() async { final client = OpenAIClient(apiKey: Platform.environment['OPENAI_API_KEY']!); final completion = await client.chat.create( model: 'gpt-4o', messages: [ const OpenAIChatCompletionChoiceMessageModel( role: OpenAIChatMessageRole.user, content: 'Say hello in five words.', ), ], ); print(completion.choices.first.message.content); }

授權與價格

此 SDK 採用 MIT 授權,為開放原始碼。價格未說明;此套件可免費使用。

內容整理自該專案公開的 README 與儲存庫資訊。

將此徽章加入你的 README

Featured on YunoDB 徽章樣式與說明

你是這個專案的維護者嗎?展示它已收錄於 YunoDB。

Markdown[![Featured on YunoDB](https://yunodb.com/badge/anasfikopenai.svg)](https://yunodb.com/tools/anasfikopenai?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/anasfikopenai?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/anasfikopenai.svg" alt="Featured on YunoDB" height="20"></a>