8000 Apply minor cleanups mainly to verify that API key change is not brou… · codeface-io/SwiftAI@d444db9 · GitHub
[go: up one dir, main page]

Skip to content

Commit d444db9

Browse files
Apply minor cleanups mainly to verify that API key change is not brought up by git
1 parent a1d16d3 commit d444db9

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Sources/SwiftAI/XAI.ChatCompletion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extension XAI {
55
/// Create a language model response for a given chat conversation. This endpoint is compatible with the OpenAI API.
66
struct Request: Encodable {
77
init(messages: [Message],
8-
model: String,
8+
model: String = "grok-beta",
99
frequency_penalty: Double? = nil,
1010
logit_bias: [String : Int]? = nil,
1111
logprobs: Bool? = nil,

Sources/SwiftAI/XAI.Completion.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import FoundationToolz
22

33
extension XAI {
44
public enum Completion {
5-
public static func complete(prompt: String,
6-
authenticationKey: AuthenticationKey) async throws(HTTP.RequestError) -> String {
5+
public static func complete(
6+
prompt: String,
7+
authenticationKey: AuthenticationKey
8+
) async throws(HTTP.RequestError) -> String {
79
let response: Response = try await HTTP.sendRequest(
810
to: baseURL + "v1/completions",
911
using: .POST,
10-
content: Request(model: "grok-beta", prompt: prompt),
12+
content: Request(prompt: prompt),
1113
authorizationValue: "Bearer " + authenticationKey.value
1214
)
1315

@@ -16,8 +18,8 @@ extension XAI {
1618

1719
/// Create a language model response for a given prompt. This endpoint is compatible with the OpenAI API.
1820
struct Request: Encodable {
19-
init(model: String,
20-
prompt: String,
21+
init(prompt: String,
22+
model: String = "grok-beta",
2123
best_of: Int? = nil,
2224
echo: Bool? = nil,
2325
frequency_penalty: Double? = nil,

Sources/SwiftAIExample/SwiftAIExample.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import FoundationToolz
44
@main
55
struct ExampleApp {
66
static func main() async {
7+
let prompt = "What is the meaning of life, the universe, and everything?"
8+
79
do {
8-
let answer = try await XAI.Completion.complete(prompt: "What is the meaning of life, the universe, and everything?",
9-
authenticationKey: .xAI)
10+
let answer = try await XAI.Completion.complete(
11+
prompt: prompt,
12+
authenticationKey: .xAI
13+
)
1014

1115
print(answer)
1216
} catch {
1317
print(error)
1418
}
1519
}
1620
}
17-

0 commit comments

Comments
 (0)
0