Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove obsolete, inactive 'edits' endpoint #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ This repository contains Swift community-maintained implementation over [OpenAI]
- [Audio Create Speech](#audio-create-speech)
- [Audio Transcriptions](#audio-transcriptions)
- [Audio Translations](#audio-translations)
- [Edits](#edits)
- [Embeddings](#embeddings)
- [Models](#models)
- [List Models](#list-models)
Expand Down Expand Up @@ -649,71 +648,6 @@ let result = try await openAI.audioTranslations(query: query)

Review [Audio Documentation](https://platform.openai.com/docs/api-reference/audio) for more info.

### Edits

Creates a new edit for the provided input, instruction, and parameters.

**Request**

```swift
struct EditsQuery: Codable {
/// ID of the model to use.
public let model: Model
/// Input text to get embeddings for.
public let input: String?
/// The instruction that tells the model how to edit the prompt.
public let instruction: String
/// The number of images to generate. Must be between 1 and 10.
public let n: Int?
/// What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.
public let temperature: Double?
/// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
public let topP: Double?
}
```

**Response**

```swift
struct EditsResult: Codable, Equatable {

public struct Choice: Codable, Equatable {
public let text: String
public let index: Int
}

public struct Usage: Codable, Equatable {
public let promptTokens: Int
public let completionTokens: Int
public let totalTokens: Int

enum CodingKeys: String, CodingKey {
case promptTokens = "prompt_tokens"
case completionTokens = "completion_tokens"
case totalTokens = "total_tokens"
}
}

public let object: String
public let created: TimeInterval
public let choices: [Choice]
public let usage: Usage
}
```

**Example**

```swift
let query = EditsQuery(model: .gpt4, input: "What day of the wek is it?", instruction: "Fix the spelling mistakes")
openAI.edits(query: query) { result in
//Handle response here
}
//or
let result = try await openAI.edits(query: query)
```

Review [Edits Documentation](https://platform.openai.com/docs/api-reference/edits) for more info.

### Embeddings

Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
Expand Down Expand Up @@ -1003,7 +937,6 @@ func completions(query: CompletionsQuery) -> AnyPublisher<CompletionsResult, Err
func images(query: ImagesQuery) -> AnyPublisher<ImagesResult, Error>
func embeddings(query: EmbeddingsQuery) -> AnyPublisher<EmbeddingsResult, Error>
func chats(query: ChatQuery) -> AnyPublisher<ChatResult, Error>
func edits(query: EditsQuery) -> AnyPublisher<EditsResult, Error>
func model(query: ModelQuery) -> AnyPublisher<ModelResult, Error>
func models() -> AnyPublisher<ModelsResult, Error>
func moderations(query: ModerationsQuery) -> AnyPublisher<ModerationsResult, Error>
Expand Down
5 changes: 0 additions & 5 deletions Sources/OpenAI/OpenAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ final public class OpenAI: OpenAIProtocol {
performStreamingRequest(request: JSONRequest<ChatStreamResult>(body: query.makeStreamable(), url: buildURL(path: .chats)), onResult: onResult, completion: completion)
}

public func edits(query: EditsQuery, completion: @escaping (Result<EditsResult, Error>) -> Void) {
performRequest(request: JSONRequest<EditsResult>(body: query, url: buildURL(path: .edits)), completion: completion)
}

public func model(query: ModelQuery, completion: @escaping (Result<ModelResult, Error>) -> Void) {
performRequest(request: JSONRequest<ModelResult>(url: buildURL(path: .models.withPath(query.model)), method: "GET"), completion: completion)
}
Expand Down Expand Up @@ -208,7 +204,6 @@ extension APIPath {
static let completions = "/v1/completions"
static let embeddings = "/v1/embeddings"
static let chats = "/v1/chat/completions"
static let edits = "/v1/edits"
static let models = "/v1/models"
static let moderations = "/v1/moderations"

Expand Down
32 changes: 0 additions & 32 deletions Sources/OpenAI/Public/Models/EditsQuery.swift

This file was deleted.

33 changes: 0 additions & 33 deletions Sources/OpenAI/Public/Models/EditsResult.swift

This file was deleted.

5 changes: 0 additions & 5 deletions Sources/OpenAI/Public/Models/Models/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ public extension Model {
/// Capable of very simple tasks, usually the fastest model in the GPT-3 series, and lowest cost.
static let textAda = "text-ada-001"

// Edits

static let textDavinci_001 = "text-davinci-001"
static let codeDavinciEdit_001 = "code-davinci-edit-001"

// Speech

/// The latest text to speech model, optimized for speed.
Expand Down
15 changes: 0 additions & 15 deletions Sources/OpenAI/Public/Protocols/OpenAIProtocol+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,6 @@ public extension OpenAIProtocol {
}
}

func edits(
query: EditsQuery
) async throws -> EditsResult {
try await withCheckedThrowingContinuation { continuation in
edits(query: query) { result in
switch result {
case let .success(success):
return continuation.resume(returning: success)
case let .failure(failure):
return continuation.resume(throwing: failure)
}
}
}
}

func model(
query: ModelQuery
) async throws -> ModelResult {
Expand Down
7 changes: 0 additions & 7 deletions Sources/OpenAI/Public/Protocols/OpenAIProtocol+Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ public extension OpenAIProtocol {
return progress.eraseToAnyPublisher()
}

func edits(query: EditsQuery) -> AnyPublisher<EditsResult, Error> {
Future<EditsResult, Error> {
edits(query: query, completion: $0)
}
.eraseToAnyPublisher()
}

func model(query: ModelQuery) -> AnyPublisher<ModelResult, Error> {
Future<ModelResult, Error> {
model(query: query, completion: $0)
Expand Down
17 changes: 0 additions & 17 deletions Sources/OpenAI/Public/Protocols/OpenAIProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,6 @@ public protocol OpenAIProtocol {
**/
func chatsStream(query: ChatQuery, onResult: @escaping (Result<ChatStreamResult, Error>) -> Void, completion: ((Error?) -> Void)?)

/**
This function sends an edits query to the OpenAI API and retrieves an edited version of the prompt based on the instruction given.

Example:
```
let query = EditsQuery(model: .gpt4, input: "What day of the wek is it?", instruction: "Fix the spelling mistakes")
openAI.edits(query: query) { result in
//Handle response here
}
```

- Parameters:
- query: An `EditsQuery` object containing the input parameters for the API request. This includes the input to be edited, the instruction specifying how it should be edited, and other settings.
- completion: A closure which receives the result when the API request finishes. The closure's parameter, `Result<EditsResult, Error>`, will contain either the `EditsResult` object with the model's response to the queried edit, or an error if the request failed.
**/
func edits(query: EditsQuery, completion: @escaping (Result<EditsResult, Error>) -> Void)

/**
This function sends a model query to the OpenAI API and retrieves a model instance, providing owner information. The Models API in this usage enables you to gather detailed information on the model in question, like GPT-3.

Expand Down
20 changes: 0 additions & 20 deletions Tests/OpenAITests/OpenAITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,6 @@ class OpenAITests: XCTestCase {
XCTAssertEqual(inError, apiError)
}

func testEdits() async throws {
let query = EditsQuery(model: .gpt4, input: "What day of the wek is it?", instruction: "Fix the spelling mistakes")
let editsResult = EditsResult(object: "edit", created: 1589478378, choices: [
.init(text: "What day of the week is it?", index: 0)
], usage: .init(promptTokens: 25, completionTokens: 32, totalTokens: 57))
try self.stub(result: editsResult)

let result = try await openAI.edits(query: query)
XCTAssertEqual(result, editsResult)
}

func testEditsError() async throws {
let query = EditsQuery(model: .gpt4, input: "What day of the wek is it?", instruction: "Fix the spelling mistakes")
let inError = APIError(message: "foo", type: "bar", param: "baz", code: "100")
self.stub(error: inError)

let apiError: APIError = try await XCTExpectError { try await openAI.edits(query: query) }
XCTAssertEqual(inError, apiError)
}

func testEmbeddings() async throws {
let query = EmbeddingsQuery(
input: .string("The food was delicious and the waiter..."),
Expand Down
10 changes: 0 additions & 10 deletions Tests/OpenAITests/OpenAITestsCombine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ final class OpenAITestsCombine: XCTestCase {
XCTAssertEqual(result, chatResult)
}

func testEdits() throws {
let query = EditsQuery(model: .gpt4, input: "What day of the wek is it?", instruction: "Fix the spelling mistakes")
let editsResult = EditsResult(object: "edit", created: 1589478378, choices: [
.init(text: "What day of the week is it?", index: 0)
], usage: .init(promptTokens: 25, completionTokens: 32, totalTokens: 57))
try self.stub(result: editsResult)
let result = try awaitPublisher(openAI.edits(query: query))
XCTAssertEqual(result, editsResult)
}

func testEmbeddings() throws {
let query = EmbeddingsQuery(input: .string("The food was delicious and the waiter..."), model: .textEmbeddingAda)
let embeddingsResult = EmbeddingsResult(data: [
Expand Down
25 changes: 0 additions & 25 deletions Tests/OpenAITests/OpenAITestsDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,31 +252,6 @@ class OpenAITestsDecoder: XCTestCase {
systemFingerprint: nil)
try decode(data, expectedValue)
}

func testEdits() async throws {
let data = """
{
"object": "edit",
"created": 1589478378,
"choices": [
{
"text": "What day of the week is it?",
"index": 0,
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 32,
"total_tokens": 57
}
}
"""

let expectedValue = EditsResult(object: "edit", created: 1589478378, choices: [
.init(text: "What day of the week is it?", index: 0)
], usage: .init(promptTokens: 25, completionTokens: 32, totalTokens: 57))
try decode(data, expectedValue)
}

func testEmbeddings() async throws {
let data = """
Expand Down
Loading