-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
914bee6
commit 7de3a5f
Showing
14 changed files
with
353 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,3 @@ public struct BatchParameter { | |
self.toolChoice = toolChoice | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Tests/AnthropicSwiftSDKTests/Network/Request/CancelMessageBatchRequestTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// CancelMessageBatchRequestTests.swift | ||
// AnthropicSwiftSDK | ||
// | ||
// Created by 伊藤史 on 2024/10/23. | ||
// | ||
|
||
import XCTest | ||
@testable import AnthropicSwiftSDK | ||
|
||
final class CancelMessageBatchRequestTests: XCTestCase { | ||
|
||
func testCancelMessageBatchRequest() { | ||
let testBatchId = "test_batch_123" | ||
|
||
let request = CancelMessageBatchRequest(batchId: testBatchId) | ||
|
||
XCTAssertEqual(request.method, .post) | ||
XCTAssertEqual(request.path, "\(RequestType.batches.basePath)/\(testBatchId)/cancel") | ||
XCTAssertNil(request.queries) | ||
XCTAssertNil(request.body) | ||
XCTAssertEqual(request.batchId, testBatchId) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Tests/AnthropicSwiftSDKTests/Network/Request/ListMessageBatchesRequestTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// ListMessageBatchesRequestTests.swift | ||
// AnthropicSwiftSDK | ||
// | ||
// Created by 伊藤史 on 2024/10/23. | ||
// | ||
|
||
import XCTest | ||
@testable import AnthropicSwiftSDK | ||
|
||
final class ListMessageBatchesRequestTests: XCTestCase { | ||
|
||
func testListMessageBatchesRequestProperties() { | ||
let queries: [String: CustomStringConvertible] = [ | ||
"before_id": "batch123", | ||
"after_id": "batch456", | ||
"limit": 10 | ||
] | ||
let request = ListMessageBatchesRequest(queries: queries) | ||
|
||
XCTAssertEqual(request.method, .get) | ||
XCTAssertEqual(request.path, RequestType.batches.basePath) | ||
XCTAssertEqual(request.queries?["before_id"] as? String, "batch123") | ||
XCTAssertEqual(request.queries?["after_id"] as? String, "batch456") | ||
XCTAssertEqual(request.queries?["limit"] as? Int, 10) | ||
XCTAssertNil(request.body) | ||
} | ||
|
||
func testParameterRawValues() { | ||
XCTAssertEqual(ListMessageBatchesRequest.Parameter.beforeId.rawValue, "before_id") | ||
XCTAssertEqual(ListMessageBatchesRequest.Parameter.afterId.rawValue, "after_id") | ||
XCTAssertEqual(ListMessageBatchesRequest.Parameter.limit.rawValue, "limit") | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
Tests/AnthropicSwiftSDKTests/Network/Request/MessageBatchesRequestTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// MessageBatchesRequestTests.swift | ||
// AnthropicSwiftSDK | ||
// | ||
// Created by 伊藤史 on 2024/10/22. | ||
// | ||
|
||
import XCTest | ||
@testable import AnthropicSwiftSDK | ||
|
||
final class MessageBatchesRequestTests: XCTestCase { | ||
|
||
func testMessageBatchesRequest() throws { | ||
let batchParameter1 = BatchParameter( | ||
messages: [Message(role: .user, content: [.text("こんにちは")])], | ||
model: .claude_3_Opus, | ||
maxTokens: 100 | ||
) | ||
let batchParameter2 = BatchParameter( | ||
messages: [Message(role: .user, content: [.text("お元気ですか?")])], | ||
model: .claude_3_Sonnet, | ||
maxTokens: 200 | ||
) | ||
|
||
let messageBatch1 = MessageBatch(customId: "test1", parameter: batchParameter1) | ||
let messageBatch2 = MessageBatch(customId: "test2", parameter: batchParameter2) | ||
|
||
let request = MessageBatchesRequest(body: .init(from: [messageBatch1, messageBatch2])) | ||
|
||
XCTAssertEqual(request.method, .post) | ||
XCTAssertEqual(request.path, RequestType.batches.basePath) | ||
XCTAssertNil(request.queries) | ||
XCTAssertNotNil(request.body) | ||
|
||
XCTAssertEqual(request.body?.requests.count, 2) | ||
|
||
XCTAssertEqual(request.body?.requests[0].customId, "test1") | ||
XCTAssertEqual(request.body?.requests[0].params.model.stringfy, Model.claude_3_Opus.stringfy) | ||
XCTAssertEqual(request.body?.requests[0].params.maxTokens, 100) | ||
XCTAssertEqual(request.body?.requests[0].params.messages.count, 1) | ||
XCTAssertEqual(request.body?.requests[0].params.messages[0].role.rawValue, "user") | ||
let content1 = try XCTUnwrap(request.body?.requests[0].params.messages[0].content) | ||
guard case let .text(text1) = content1[0] else { | ||
XCTFail("content1[0] is not .text") | ||
return | ||
} | ||
XCTAssertEqual(text1, "こんにちは") | ||
|
||
XCTAssertEqual(request.body?.requests[1].customId, "test2") | ||
XCTAssertEqual(request.body?.requests[1].params.model.stringfy, Model.claude_3_Sonnet.stringfy) | ||
XCTAssertEqual(request.body?.requests[1].params.maxTokens, 200) | ||
XCTAssertEqual(request.body?.requests[1].params.messages.count, 1) | ||
XCTAssertEqual(request.body?.requests[1].params.messages[0].role.rawValue, "user") | ||
let content2 = try XCTUnwrap(request.body?.requests[1].params.messages[0].content) | ||
guard case let .text(text2) = content2[0] else { | ||
XCTFail("content2[0] is not .text") | ||
return | ||
} | ||
XCTAssertEqual(text2, "お元気ですか?") | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
Tests/AnthropicSwiftSDKTests/Network/Request/MessagesRequestTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// MessagesRequestTests.swift | ||
// AnthropicSwiftSDK | ||
// | ||
// Created by 伊藤史 on 2024/10/22. | ||
// | ||
|
||
import XCTest | ||
@testable import AnthropicSwiftSDK | ||
|
||
final class MessagesRequestTests: XCTestCase { | ||
func testMessagesRequest() throws { | ||
let messages = [Message(role: .user, content: [.text("こんにちは")])] | ||
let systemPrompt: [SystemPrompt] = [.text("あなたは親切なアシスタントです。", .ephemeral)] | ||
|
||
let requestBody = MessagesRequestBody( | ||
model: .claude_3_Opus, | ||
messages: messages, | ||
system: systemPrompt, | ||
maxTokens: 100, | ||
metaData: MetaData(userId: "test-user"), | ||
stopSequences: ["END"], | ||
stream: false, | ||
temperature: 0.7, | ||
topP: 0.9, | ||
topK: 10, | ||
tools: nil, | ||
toolChoice: .auto | ||
) | ||
|
||
let request = MessagesRequest(body: requestBody) | ||
|
||
XCTAssertEqual(request.method, .post) | ||
XCTAssertEqual(request.path, RequestType.messages.basePath) | ||
XCTAssertNil(request.queries) | ||
|
||
XCTAssertEqual(request.body?.model.stringfy, Model.claude_3_Opus.stringfy) | ||
XCTAssertEqual(request.body?.messages.count, 1) | ||
XCTAssertEqual(request.body?.messages[0].role.rawValue, "user") | ||
let content1 = try XCTUnwrap(request.body?.messages[0].content) | ||
guard case let .text(text1) = content1[0] else { | ||
XCTFail("content1[0] is not .text") | ||
return | ||
} | ||
XCTAssertEqual(text1, "こんにちは") | ||
let system1 = try XCTUnwrap(request.body?.system) | ||
guard case let .text(text1, _) = system1[0] else { | ||
XCTFail("system1[0] is not .text") | ||
return | ||
} | ||
XCTAssertEqual(text1, "あなたは親切なアシスタントです。") | ||
XCTAssertEqual(request.body?.maxTokens, 100) | ||
XCTAssertEqual(request.body?.metaData?.userId, "test-user") | ||
XCTAssertEqual(request.body?.stopSequences, ["END"]) | ||
XCTAssertFalse(request.body?.stream ?? true) | ||
XCTAssertEqual(request.body?.temperature, 0.7) | ||
XCTAssertEqual(request.body?.topP, 0.9) | ||
XCTAssertEqual(request.body?.topK, 10) | ||
XCTAssertNil(request.body?.tools) | ||
XCTAssertNil(request.body?.toolChoice) | ||
} | ||
|
||
func testMessagesRequestWithBatchParameter() throws { | ||
let messages = [Message(role: .user, content: [.text("こんにちは")])] | ||
let systemPrompt: [SystemPrompt] = [.text("あなたは親切なアシスタントです。", .ephemeral)] | ||
|
||
let batchParameter = BatchParameter( | ||
messages: messages, | ||
model: .claude_3_Opus, | ||
system: systemPrompt, | ||
maxTokens: 100, | ||
metaData: MetaData(userId: "test-user"), | ||
stopSequence: ["END"], | ||
temperature: 0.7, | ||
topP: 0.9, | ||
topK: 10, | ||
toolContainer: nil, | ||
toolChoice: .auto | ||
) | ||
|
||
let requestBody = MessagesRequestBody(from: batchParameter) | ||
let request = MessagesRequest(body: requestBody) | ||
|
||
XCTAssertEqual(request.body?.model.stringfy, Model.claude_3_Opus.stringfy) | ||
XCTAssertEqual(request.body?.messages.count, 1) | ||
XCTAssertEqual(request.body?.messages[0].role.rawValue, "user") | ||
let content1 = try XCTUnwrap(request.body?.messages[0].content) | ||
guard case let .text(text1) = content1[0] else { | ||
XCTFail("content1[0] is not .text") | ||
return | ||
} | ||
XCTAssertEqual(text1, "こんにちは") | ||
let system1 = try XCTUnwrap(request.body?.system) | ||
guard case let .text(text1, _) = system1[0] else { | ||
XCTFail("system1[0] is not .text") | ||
return | ||
} | ||
XCTAssertEqual(text1, "あなたは親切なアシスタントです。") | ||
XCTAssertEqual(request.body?.maxTokens, 100) | ||
XCTAssertEqual(request.body?.metaData?.userId, "test-user") | ||
XCTAssertEqual(request.body?.stopSequences, ["END"]) | ||
XCTAssertFalse(request.body?.stream ?? true) | ||
XCTAssertEqual(request.body?.temperature, 0.7) | ||
XCTAssertEqual(request.body?.topP, 0.9) | ||
XCTAssertEqual(request.body?.topK, 10) | ||
XCTAssertNil(request.body?.tools) | ||
XCTAssertNil(request.body?.toolChoice) | ||
} | ||
} |
Oops, something went wrong.