Skip to content

Commit

Permalink
fix pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon Nissen committed Dec 11, 2024
1 parent 35a0c05 commit 432e74b
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Sources/SpeziChat/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public struct MessageView: View {
private var isToolInteraction: Bool {
switch chat.role {
case .assistantToolCall, .assistantToolResponse:
return true
true
default:
return false
false
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/SpeziChat/MessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public struct MessagesView: View {
[
ChatEntity(role: .user, content: "User Message!"),
ChatEntity(role: .hidden(type: .unknown), content: "Hidden Message (but still visible)!"),
ChatEntity(role: .assistantToolCall, content: "Assistant Message!"),
ChatEntity(role: .assistantToolResponse, content: "Assistant Message!f jiodsjfiods \n fudshfdusi"),
ChatEntity(role: .assistant, content: "Assistant Message!")
],
hideMessages: .custom(hiddenMessageTypes: [])
Expand Down
8 changes: 4 additions & 4 deletions Sources/SpeziChat/Models/ChatEntity+Alignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ extension ChatEntity {
var alignment: Alignment {
switch self.role {
case .user:
return .trailing
.trailing
default:
return .leading
.leading
}
}

var horziontalAlignment: HorizontalAlignment {
switch self.alignment {
case .leading:
return .leading
.leading
case .trailing:
return .trailing
.trailing
}
}
}
100 changes: 94 additions & 6 deletions Sources/SpeziChat/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,71 @@
}
}
},
"Equal sign" : {

"EQUAL_SIGN" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Gleichzeichen"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Equal Sign"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Signo igual"
}
}
}
},
"EXPORT_CHAT_BUTTON" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Chat exportieren"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Export the Chat"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Exportar el chat"
}
}
}
},
"Function F of X" : {

"FUNCTION_F_OF_X" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Funktion F von X"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Function F of X"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Función F de X"
}
}
}
},
"MESSAGE_INPUT_TEXTFIELD" : {
"localizations" : {
Expand Down Expand Up @@ -126,18 +176,56 @@
}
},
"Text to speech is disabled, press to enable text to speech." : {

"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Die Spracheingabe ist deaktiviert, tippe um die Eingabe zu aktivieren."
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "La función de texto a voz está desactivada, pulse para activarla."
}
}
}
},
"Text to speech is enabled, press to disable text to speech." : {

"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Die Spracheingabe is aktiviert, tippe um die Eingabe zu dekativieren"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "La función de texto a voz está activada, pulse para desactivarla."
}
}
}
},
"TYPING_INDICATOR" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Schreibanzeige"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Typing Indicator"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Indicador de mecanografía"
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SpeziChat/ToolInteractionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ToolInteractionView: View {
private func toolCallView(content: String) -> some View {
HStack {
Image(systemName: "function")
.accessibilityLabel("Function F of X")
.accessibilityLabel("FUNCTION_F_OF_X")
.frame(width: 20)
Text(content)
.foregroundStyle(.secondary)
Expand All @@ -46,7 +46,7 @@ struct ToolInteractionView: View {
private func toolResponseView(content: String) -> some View {
HStack {
Image(systemName: "equal")
.accessibilityLabel("Equal sign")
.accessibilityLabel("EQUAL_SIGN")
.frame(width: 20)

Group {
Expand Down
12 changes: 11 additions & 1 deletion Tests/UITests/TestApp/ChatTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ struct ChatTestView: View {
// Append a new assistant message to the chat after sleeping for 5 seconds.
if newValue.last?.role == .user {
Task {
try await Task.sleep(for: .seconds(5))
try await Task.sleep(for: .seconds(3))

await MainActor.run {
chat.append(.init(role: .assistantToolCall, content: "call_test_func({ test: true })"))
}
try await Task.sleep(for: .seconds(1))

await MainActor.run {
chat.append(.init(role: .assistantToolResponse, content: "{ some: response }"))
}
try await Task.sleep(for: .seconds(1))

await MainActor.run {
chat.append(.init(role: .assistant, content: "**Assistant** Message Response!"))
Expand Down
17 changes: 17 additions & 0 deletions Tests/UITests/TestAppUITests/TestAppUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,21 @@ class TestAppUITests: XCTestCase {
XCTAssert(!app.buttons["Speaker strikethrough"].waitForExistence(timeout: 2))
XCTAssert(app.buttons["Speaker"].waitForExistence(timeout: 2))
}

func testFunctionCallAndResponse() throws {
let app = XCUIApplication()

XCTAssert(app.staticTexts["SpeziChat"].waitForExistence(timeout: 1))
XCTAssert(app.staticTexts["Assistant Message!"].waitForExistence(timeout: 1))

try app.textFields["Message Input Textfield"].enter(value: "Call some function", dismissKeyboard: false)
XCTAssert(app.buttons["Send Message"].waitForExistence(timeout: 5))
app.buttons["Send Message"].tap()

sleep(5)

XCTAssert(app.staticTexts["call_test_func({ test: true })"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["{ some: response }"].waitForExistence(timeout: 2))
XCTAssert(app.staticTexts["Assistant Message Response!"].waitForExistence(timeout: 2))
}
}

0 comments on commit 432e74b

Please sign in to comment.