Skip to content

Commit

Permalink
change interface to approve multiple messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fumito-ito committed Mar 19, 2024
1 parent 23a012c commit 4395de5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions Sources/AnthropicSwiftSDK/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct Messages {
}

public func createMessage(
_ message: Message,
_ messages: [Message],
model: Model = .claude_3_Opus,
system: String? = nil,
maxTokens: Int,
Expand All @@ -30,7 +30,7 @@ public struct Messages {
topK: Int? = nil
) async throws -> MessagesResponse {
try await createMessage(
message,
messages,
model: model,
system: system,
maxTokens: maxTokens,
Expand All @@ -45,7 +45,7 @@ public struct Messages {
}

public func createMessage(
_ message: Message,
_ messages: [Message],
model: Model = .claude_3_Opus,
system: String? = nil,
maxTokens: Int,
Expand All @@ -65,7 +65,7 @@ public struct Messages {

let requestBody = MessagesRequest(
model: model,
messages: [message],
messages: messages,
system: system,
maxTokens: maxTokens,
metaData: metaData,
Expand All @@ -90,7 +90,7 @@ public struct Messages {
}

public func streamMessage(
_ message: Message,
_ messages: [Message],
model: Model = .claude_3_Opus,
system: String? = nil,
maxTokens: Int,
Expand All @@ -101,7 +101,7 @@ public struct Messages {
topK: Int? = nil
) async throws -> AsyncThrowingStream<StreamingResponse, Error> {
try await streamMessage(
message,
messages,
model: model,
system: system,
maxTokens: maxTokens,
Expand All @@ -116,7 +116,7 @@ public struct Messages {
}

public func streamMessage(
_ message: Message,
_ messages: [Message],
model: Model = .claude_3_Opus,
system: String? = nil,
maxTokens: Int,
Expand All @@ -136,7 +136,7 @@ public struct Messages {

let requestBody = MessagesRequest(
model: model,
messages: [message],
messages: messages,
system: system,
maxTokens: maxTokens,
metaData: metaData,
Expand Down
6 changes: 3 additions & 3 deletions Tests/AnthropicSwiftSDK/MessagesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class MessagesTests: XCTestCase {
})

let message = Message(role: .user, content: [.text("This is test text")])
let _ = try await messages.createMessage(message, maxTokens: 1024)
let _ = try await messages.createMessage([message], maxTokens: 1024)

await fulfillment(of: [expectation], timeout: 1.0)
}
Expand Down Expand Up @@ -57,7 +57,7 @@ final class MessagesTests: XCTestCase {
""")

let message = Message(role: .user, content: [.text("This is test text")])
let response = try await messages.createMessage(message, maxTokens: 1024)
let response = try await messages.createMessage([message], maxTokens: 1024)

XCTAssertEqual(response.id, "msg_01XFDUDYJgAACzvnptvVoYEL")
XCTAssertEqual(response.type, .message)
Expand All @@ -84,7 +84,7 @@ final class MessagesTests: XCTestCase {
""")

let message = Message(role: .user, content: [.text("This is test text")])
let stream = try await messages.streamMessage(message, maxTokens: 1024)
let stream = try await messages.streamMessage([message], maxTokens: 1024)

for try await chunk in stream {
let response = try XCTUnwrap(chunk as? StreamingMessageStartResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ final class StreamingDataLineParserTests: XCTestCase {
XCTAssertEqual(result.type, .messageDelta)
XCTAssertEqual(result.delta.stopReason, .endTurn)
XCTAssertNil(result.delta.stopSequence)
XCTAssertEqual(result.delta.usage.outputTokens, 15)
XCTAssertNil(result.delta.usage.inputTokens)
XCTAssertEqual(result.delta.usage?.outputTokens, 15)
XCTAssertNil(result.delta.usage?.inputTokens)
}

func testParseMessageStopDataLine() throws {
Expand Down

0 comments on commit 4395de5

Please sign in to comment.