Skip to content

Commit

Permalink
Merge pull request #142 from allenai/sharing-as-text
Browse files Browse the repository at this point in the history
Sharing as text
  • Loading branch information
Stanley-Jovel authored Feb 3, 2025
2 parents 16b6e9a + 3ff3d7b commit 4363a27
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
10 changes: 8 additions & 2 deletions OLMoE.swift/Constants/InfoText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum InfoText {
text: """
Please do not include PII (personally identifiable information) in model prompts or elsewhere in this app.
"""),

HeaderTextPair(
header: "Open Source Licenses",
text: """
Expand All @@ -52,12 +52,18 @@ enum InfoText {
Licensed under the MIT License.
You may obtain a copy of the license at:
[LlamaCPP Repository](https://github.com/ggerganov/llama.cpp)
ggml
Copyright (c) 2023-2024 The ggml authors
Licensed under the MIT License.
You may obtain a copy of the license at:
[ggml Repository](https://github.com/ggerganov/ggml)
MarkdownUI
Copyright (c) 2020 Guillermo Gonzalez
Licensed under the MIT License.
You may obtain a copy of the license at:
[MarkdownUI Repository](https://github.com/gonzalezreal/swift-markdown-ui)
""")
]
}
53 changes: 41 additions & 12 deletions OLMoE.swift/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct BotView: View {
@FocusState private var isTextEditorFocused: Bool
let disclaimerHandlers: DisclaimerHandlers

// Add new state for text sharing
@State private var showTextShareSheet = false

private var hasValidInput: Bool {
!input.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
Expand Down Expand Up @@ -106,6 +109,33 @@ struct BotView: View {
}
}

private func formatConversationForSharing() -> String {
let deviceName = UIDevice.current.model
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM d, yyyy 'at' h:mm a"
let timestamp = dateFormatter.string(from: Date())

let header = """
Conversation with OLMoE (Open Language Mixture of Expert)
----------------------------------------
"""

let conversation = bot.history.map { chat in
let role = chat.role == .user ? "User" : "OLMoE"
return "\(role): \(chat.content)"
}.joined(separator: "\n\n")

let footer = """
----------------------------------------
Shared from OLMoE - AI2's Open Language Model
https://github.com/allenai/OLMoE
"""

return header + conversation + footer
}

func shareConversation() {
isSharing = true
disclaimerHandlers.setShowDisclaimerPage(false)
Expand Down Expand Up @@ -189,11 +219,12 @@ struct BotView: View {
func shareButton() -> some View {
Button(action: {
isTextEditorFocused = false
disclaimerHandlers.setActiveDisclaimer(Disclaimers.ShareDisclaimer())
disclaimerHandlers.setCancelAction({ disclaimerHandlers.setShowDisclaimerPage(false) })
disclaimerHandlers.setAllowOutsideTapDismiss(true)
disclaimerHandlers.setConfirmAction({ shareConversation() })
disclaimerHandlers.setShowDisclaimerPage(true)
// disclaimerHandlers.setActiveDisclaimer(Disclaimers.ShareDisclaimer())
// disclaimerHandlers.setCancelAction({ disclaimerHandlers.setShowDisclaimerPage(false) })
// disclaimerHandlers.setAllowOutsideTapDismiss(true)
// disclaimerHandlers.setConfirmAction({ shareConversation() })
// disclaimerHandlers.setShowDisclaimerPage(true)
showTextShareSheet = true
}) {
HStack {
if isSharing {
Expand Down Expand Up @@ -257,11 +288,6 @@ struct BotView: View {
GeometryReader { geometry in
contentView(in: geometry)
}
.sheet(isPresented: $showShareSheet, content: {
if let url = shareURL {
ActivityViewController(activityItems: [url])
}
})
}

private func contentView(in geometry: GeometryProxy) -> some View {
Expand Down Expand Up @@ -328,11 +354,14 @@ struct BotView: View {
}
.padding(12)
}
.sheet(isPresented: $showShareSheet, content: {
.sheet(isPresented: $showShareSheet) {
if let url = shareURL {
ActivityViewController(activityItems: [url])
}
})
}
.sheet(isPresented: $showTextShareSheet) {
ActivityViewController(activityItems: [formatConversationForSharing()])
}
.gesture(TapGesture().onEnded({
isTextEditorFocused = false
}))
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ See [LICENSE](LICENSE) for more information.
You may obtain a copy of the license at:
<https://github.com/ggerganov/ggml>

- [MarkdownUI](https://github.com/gonzalezreal/swift-markdown-ui)

Copyright (c) 2020 Guillermo Gonzalez

Licensed under the MIT License.

You may obtain a copy of the license at:
<https://github.com/gonzalezreal/swift-markdown-ui>

0 comments on commit 4363a27

Please sign in to comment.