-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathCompletionProvider.swift
58 lines (50 loc) · 1.52 KB
/
CompletionProvider.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public struct CompletionProvider {
private let requestHandler: RequestHandler
init(requestHandler: RequestHandler) {
self.requestHandler = requestHandler
}
/**
Create completion
POST
https://api.openai.com/chat/completions
Creates a completion for the provided prompt and parameters
*/
public func create(
model: ModelID,
prompts: [String] = [],
suffix: String? = nil,
maxTokens: Int = 16,
temperature: Double = 1.0,
topP: Double = 1.0,
n: Int = 1,
stream: Bool = false,
logprobs: Int? = nil,
echo: Bool = false,
stops: [String] = [],
presencePenalty: Double = 0.0,
frequencyPenalty: Double = 0.0,
bestOf: Int = 1,
logitBias: [String : Int] = [:],
user: String? = nil
) async throws -> Completion {
let request = try CreateCompletionRequest(
model: model.id,
prompts: prompts,
suffix: suffix,
maxTokens: maxTokens,
temperature: temperature,
topP: topP,
n: n,
stream: stream,
logprobs: logprobs,
echo: echo,
stops: stops,
presencePenalty: presencePenalty,
frequencyPenalty: frequencyPenalty,
bestOf: bestOf,
logitBias: logitBias,
user: user
)
return try await requestHandler.perform(request: request)
}
}