← 开源
dylanshine

openai-kit

A community Swift package used to interact with the OpenAI API

AI EngineeringAccess modelsSwift
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
728
Star
115
Fork
+0
本周
11
贡献者
创建于 2023-01-02 · 更新于 2026-09-30 · 今日第 14463 名
主要开发者
dylanshineronaldmannakJSky74

dylanshine/openai-kit 排名第 14,463,有 728 个星标。

同类别比较

dylanshine/openai-kit 排名第 14,463,此处有 8 个同类条目;kdcokenny/opencode-worktree 排名第 14,467。

同类别比较
名称排名指标
YonkoSam/whatsapp-python-chatbot14,436
语言:
Python
星标数:
730
分叉数:
218
简介:
WhatsApp Chatbot using Gemini + WasenderAPI
microsoft/teams-sdk14,441
语言:
TypeScript
星标数:
730
分叉数:
271
简介:
SDK focused on building AI based applications and extensions for Microsoft Teams and other Bot Framework channels
ankane/transformers-ruby14,448
语言:
Ruby
星标数:
729
分叉数:
12
简介:
State-of-the-art transformers for Ruby
ltjed/freephdlabor14,456
语言:
Python
星标数:
729
分叉数:
80
简介:
freephdlabor: customizing personalized multiagent systems that researchs 24/7 on your own scientific problem
kdcokenny/opencode-worktree14,467
语言:
TypeScript
星标数:
728
分叉数:
41
简介:
Zero-friction git worktrees for OpenCode. Auto-spawns terminals, syncs files, cleans up on exit.
liveloveapp/hashbrown14,469
语言:
TypeScript
星标数:
728
分叉数:
64
简介:
Hashbrown is a framework for building agents that run the browser. Built for Angular and React.
melMass/comfy_mtb14,470
语言:
Python
星标数:
728
分叉数:
87
简介:
Animation oriented nodes pack for ComfyUI
privacytrustlab/ml_privacy_meter14,473
语言:
Jupyter Notebook
星标数:
728
分叉数:
153
简介:
Privacy Meter: An open-source library to audit data privacy in statistical and machine learning algorithms.
关键参数与规格
关键参数与规格
参数值
语言Swift
类别AI Engineering
子类别Access models
星标数728
分叉数115
贡献者11
创建日期2023-01-02
更新日期2026-09-30
1 天星标数0
7 天星标数0
排名14,463
上次排名14,316
排名变化-147
7 天星标排名14,491
上次 7 天星标排名14,507
7 天星标排名变化16
总星标排名14,406
上次总星标排名14,379
总星标排名变化-27
国家USA
README 摘录

OpenAIKit OpenAIKit is a Swift package used to communicate with the OpenAI API. swift: ~ It is encouraged to use environment variables to inject the OpenAI API key, instead of hardcoding it in the source code. ~ ⚠️ OpenAI strongly recommends developers of client-side applications proxy requests through a separate backend service to keep their API key safe. API keys can access and manipulate customer billing, usage, and organizational data, so it's a significant risk to expose them. ~ If you don't want

to use SwiftNIO you can use URLSession. Client implements a handful of methods to interact with the OpenAI API: ~ What's Implemented [x] Chat [x] Models [x] Completions [x] Edits [x] Images [x] Embeddings [x] Files [x] Moderations [ ] Fine-tunes [x] Speech to text [ ] Function calling Error handling If the request to the API failed for any reason an is . Simply ensure you catch errors thrown like any other throwing function ~

常见问题

记录了多少星标和分叉?

dylanshine/openai-kit 有 728 个星标和 115 个分叉。

仓库排名是多少?

dylanshine/openai-kit 排名第 14,463。

记录的语言和类别是什么?

dylanshine/openai-kit 有 728 个星标,语言为 Swift,类别为 AI Engineering。

哪个仓库排名最接近?

dylanshine/openai-kit 与 kdcokenny/opencode-worktree 比较,后者排名第 14,467,有 728 个星标。

README

OpenAIKit

OpenAIKit is a Swift package used to communicate with the OpenAI API.

Setup

Add the dependency to Package.swift:

dependencies: [
    ...
    .package(url: "https://github.com/dylanshine/openai-kit.git", from: "1.0.0")
],
targets: [
    .target(name: "App", dependencies: [
        .product(name: "OpenAIKit", package: "openai-kit"),
    ]),

It is encouraged to use environment variables to inject the OpenAI API key, instead of hardcoding it in the source code.

# .env

OPENAI_API_KEY="YOUR-API-KEY"
OPENAI_ORGANIZATION="YOUR-ORGANIZATION"

⚠️ OpenAI strongly recommends developers of client-side applications proxy requests through a separate backend service to keep their API key safe. API keys can access and manipulate customer billing, usage, and organizational data, so it's a significant risk to expose them.

Create a OpenAIKit.Client by passing a configuration.


var apiKey: String {
    ProcessInfo.processInfo.environment["OPENAI_API_KEY"]!
}

var organization: String {
    ProcessInfo.processInfo.environment["OPENAI_ORGANIZATION"]!
}

...

// Generally we would advise on creating a single HTTPClient for the lifecycle of your application and recommend shutting it down on application close.

let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)

let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))

defer {
    // it's important to shutdown the httpClient after all requests are done, even if one failed. See: https://github.com/swift-server/async-http-client
    try? httpClient.syncShutdown()
}

let configuration = Configuration(apiKey: apiKey, organization: organization)

let openAIClient = OpenAIKit.Client(httpClient: httpClient, configuration: configuration)

If you don't want to use SwiftNIO you can use URLSession.

let urlSession = URLSession(configuration: .default)
let configuration = Configuration(apiKey: apiKey, organization: organization)
let openAIClient = OpenAIKit.Client(session: urlSession, configuration: configuration)

Using the API

The OpenAIKit.Client implements a handful of methods to interact with the OpenAI API:

import OpenAIKit

let completion = try await openAIClient.completions.create(
    model: Model.GPT3.davinci,
    prompts: ["Write a haiku"]
)

What's Implemented

Error handling

If the request to the API failed for any reason an OpenAIKit.APIErrorResponse is thrown. Simply ensure you catch errors thrown like any other throwing function

do {
   ...
} catch let error as APIErrorResponse {
    print(error)
}
排名相邻
同类项目