Skip to content

Commit 0f6c550

Browse files
authored
Merge pull request #39 from phiHero/conversation
fix: type `conversationHistory` should be an array & integer parameters incorrectly converted to boolean
2 parents 67cc20a + f86f66f commit 0f6c550

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

Sources/Typesense/Models/SearchResultConversation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import Foundation
1212
public struct SearchResultConversation: Codable {
1313

1414
public var answer: String
15-
public var conversationHistory: [String: String]
15+
public var conversationHistory: [[String: String]]
1616
public var conversationId: String
1717
public var query: String
1818

19-
public init(answer: String, conversationHistory: [String: String], conversationId: String, query: String) {
19+
public init(answer: String, conversationHistory: [[String: String]], conversationId: String, query: String) {
2020
self.answer = answer
2121
self.conversationHistory = conversationHistory
2222
self.conversationId = conversationId

Sources/Typesense/utils/CreateURLQueryParams.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func createURLQuery<T: Codable>(forSchema: T?) throws -> [URLQueryItem]{
2121
var stringVal = ""
2222
if let str = val as? String {
2323
stringVal = str
24-
} else if let bool = val as? Bool {
24+
} else if type(of: val) == type(of: NSNumber(booleanLiteral: true)) || type(of: val) == type(of: NSNumber(booleanLiteral: false)), let bool = val as? Bool{
2525
stringVal = String(bool)
2626
} else if let int = val as? Int {
2727
stringVal = String(int)

Tests/TypesenseTests/ConversationModelTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,38 @@ final class ConversationModelTests: XCTestCase {
7878
}
7979
}
8080

81+
func testConversationSearch() async {
82+
do {
83+
let string = """
84+
{
85+
"conversation": {
86+
"answer": " context information, I' unable to suggest an is information given about specific context action as,, specific titles If a preference for particular genre length of, please that information and I' try my best to suggestions.",
87+
"conversation_history": [
88+
{
89+
"user": "can you suggest an action series"
90+
},
91+
{
92+
"assistant": " context information, I' unable to suggest an is information given about specific context action as,, specific titles If a preference for particular genre length of, please that information and I' try my best to suggestions."
93+
}
94+
],
95+
"conversation_id": "123",
96+
"query": "can you suggest an action series"
97+
},
98+
"results": [
99+
{
100+
"code": 404,
101+
"error": "Not found."
102+
}
103+
]
104+
}
105+
"""
106+
let data = string.data(using: .utf8)!
107+
let _ = try decoder.decode(MultiSearchResult<Never>.self, from: data)
108+
XCTAssertTrue(true)
109+
}catch (let error) {
110+
print(error)
111+
XCTAssertTrue(false)
112+
}
113+
}
114+
81115
}

Tests/TypesenseTests/CreateURLQueryParamsTests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,41 @@ final class CreateURLQueryParamsTests: XCTestCase {
66
var name = "Fast"
77
var age: Int = 20
88
var price: Int64 = 2000
9+
var page: Int? = 1
10+
var groupLimit: Int64? = 0
911
var speed: Double = 120.555
1012
var mileage: Float = 120.5
1113
var isElectric = true
14+
var inStock: Bool = false
1215
var empty: String? = nil
1316

1417
enum CodingKeys: String, CodingKey {
1518
case name
1619
case age
1720
case price
21+
case page
22+
case groupLimit = "group_limit"
1823
case speed
1924
case mileage
2025
case isElectric = "is_electric"
26+
case inStock = "in_stock"
2127
case empty
2228
}
2329
}
2430
func testCreateURLQueryParams() {
2531
do {
2632
let queryParams = try createURLQuery(forSchema: Car())
2733
print(queryParams)
28-
XCTAssertEqual(queryParams.count, 6)
34+
XCTAssertEqual(queryParams.count, 9)
2935
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "name", value: "Fast")))
3036
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "age", value: "20")))
3137
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "price", value: "2000")))
38+
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "page", value: "1")))
39+
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "group_limit", value: "0")))
3240
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "speed", value: "120.555")))
3341
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "mileage", value: "120.5")))
3442
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "is_electric", value: "true")))
43+
XCTAssertTrue(queryParams.contains(URLQueryItem(name: "in_stock", value: "false")))
3544
XCTAssertFalse(queryParams.contains(URLQueryItem(name: "empty", value: "null")))
3645
} catch (let error) {
3746
print(error)

Tests/TypesenseTests/DocumentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ final class DocumentTests: XCTestCase {
172172
}
173173

174174
func testDocumentSearch() async {
175-
let searchParams = SearchParameters(q: "stark", queryBy: "company_name", filterBy: "num_employees:>100", sortBy: "num_employees:desc")
175+
let searchParams = SearchParameters(q: "*", queryBy: "company_name", page: 0, groupBy: "country", groupLimit: 1)
176176

177177
do {
178178
try await createDocument()

0 commit comments

Comments
 (0)