spezichat

Spezi Module to Handle and Display User Interfaces for Chat-based Interactions

https://github.com/stanfordspezi/spezichat

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.0%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Spezi Module to Handle and Display User Interfaces for Chat-based Interactions

Basic Info
Statistics
  • Stars: 9
  • Watchers: 10
  • Forks: 6
  • Open Issues: 5
  • Releases: 15
Created over 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

Spezi Chat

Build and Test codecov DOI

Provides UI components for building chat-based applications.

Overview

The SpeziChat module provides views that can be used to implement chat-based use cases, such as a message view or a voice input field.

|Screenshot displaying the regular chat view. Screenshot displaying the regular chat view.|Screenshot displaying the text input chat view. Screenshot displaying the text input chat view.|Screenshot displaying the voice input chat view. Screenshot displaying the voice input chat view. |:--:|:--:|:--:| |ChatView|ChatView|ChatView|

Setup

1. Add Spezi Chat as a Dependency

You need to add the Spezi Chat Swift package to your app in Xcode or Swift package.

[!IMPORTANT]
If your application is not yet configured to use Spezi, follow the Spezi setup article to setup the core Spezi infrastructure.

2. Configure target properties

As SpeziChat is utilizing the SpeziSpeech module under the hood for speech interaction capabilities, one needs to ensure that your application has the necessary permissions for microphone access and speech recognition. Follow the steps below to configure the target properties within your Xcode project:

  • Open your project settings in Xcode by selecting PROJECTNAME > TARGETNAME > Info tab.
  • You will need to add two entries to the Custom iOS Target Properties (so the Info.plist file) to provide descriptions for why your app requires these permissions:
    • Add a key named Privacy - Microphone Usage Description and provide a string value that describes why your application needs access to the microphone. This description will be displayed to the user when the app first requests microphone access.
    • Add another key named Privacy - Speech Recognition Usage Description with a string value that explains why your app requires the speech recognition capability. This will be presented to the user when the app first attempts to perform speech recognition.

These entries are mandatory for apps that utilize microphone and speech recognition features. Failing to provide them will result in your app being unable to access these features.

Usage

The underlying data model of SpeziChat is a Chat. It represents the content of a typical text-based chat between user and system(s). A Chat is nothing more than an ordered array of ChatEntitys which contain the content of the individual messages. A ChatEntity consists of a ChatEntity/Role, a unique identifier, a timestamp as well as an String-based content which can contain Markdown-formatted text. In addition, a flag indicates if the ChatEntity is complete and no further content will be added.

[!NOTE]
The ChatEntity is able to store Markdown-based content which in turn is rendered as styled text in the ChatView, MessagesView, and MessageView.

Chat View

The ChatView provides a basic reusable chat view which includes a message input field. The input can be either typed out via the iOS keyboard or provided as voice input and transcribed into written text. It accepts an additional messagePendingAnimation parameter to control whether a chat bubble animation is shown for a message that is currently being composed. By default, messagePendingAnimation has a value of nil and does not show. In addition, the ChatView provides functionality to export the visualized Chat as a PDF document, JSON representation, or textual UTF-8 file (see ChatView/ChatExportFormat) via a Share Sheet (or Activity View).

```swift struct ChatTestView: View { @State private var chat: Chat = [ ChatEntity(role: .assistant, content: "Assistant Message!") ]

var body: some View {
    ChatView($chat, exportFormat: .pdf)
        .navigationTitle("SpeziChat")
}

} ```

[!NOTE] The ChatView provides speech-to-text (recognition) as well as text-to-speech (synthesize) accessibility capabilities out-of-the-box via the SpeziSpeech module, facilitating seamless interaction with the content of the ChatView.

Messages View

The MessagesView displays a Chat containing multiple ChatEntitys with different ChatEntity/Roles in a typical chat-like fashion. The View automatically scrolls down to the newest message that is added to the passed Chat SwiftUI Binding. The typingIndicator parameter controls when a typing indicator is shown onscreen for incoming messages to Chat.

```swift struct MessagesViewTestView: View { @State private var chat: Chat = [ ChatEntity(role: .user, content: "User Message!"), ChatEntity(role: .assistant, content: "Assistant Message!") ]

var body: some View {
    MessagesView($chat)
}

} ```

Message View

The MessageView is a reusable SwiftUI View to display the contents of a ChatEntity within a typical chat message bubble. This bubble is properly aligned according to the associated ChatEntity/Role.

swift struct MessageViewTestView: View { var body: some View { VStack { MessageView(ChatEntity(role: .user, content: "User Message!")) MessageView(ChatEntity(role: .assistant, content: "Assistant Message!")) MessageView(ChatEntity(role: .hidden(type: .unknown), content: "System Message (hidden)!")) } .padding() } }

MessageInput View

The MessageInputView is a reusable SwiftUI View to handle text-based or speech-based user input. The provided message is attached to the passed Chat via a SwiftUI Binding.

```swift struct MessageInputTestView: View { @State private var chat: Chat = [] @State private var disableInput = false

var body: some View {
    VStack {
        Spacer()
        MessageInputView($chat, messagePlaceholder: "TestMessage")
            .disabled(disableInput)
            /// Get the height of the `MessageInputView` via a SwiftUI `PreferenceKey`
            .onPreferenceChange(MessageInputViewHeightKey.self) { newValue in
                let messageInputHeight: CGFloat = newValue
                // ...
            }
    }
}

} ```

For more information, please refer to the API documentation.

Applications using Spezi Chat

HealthGPT and LLMonFHIR provide a great starting points and examples using the SpeziChat module.

Contributing

Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.

License

This project is licensed under the MIT License. See Licenses for more information.

Spezi Footer Spezi Footer

Owner

  • Name: Stanford Spezi
  • Login: StanfordSpezi
  • Kind: organization

Citation (CITATION.cff)

#
# This source file is part of the Stanford Spezi open source project
#
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
#
# SPDX-License-Identifier: MIT
# 

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Schmiedmayer"
  given-names: "Paul"
  orcid: "https://orcid.org/0000-0002-8607-9148"
- family-names: "Philipp"
  given-names: "Zagar"
  orcid: "https://orcid.org/0009-0001-5934-2078"
- family-names: "Adrit"
  given-names: "Rao"
  orcid: "https://orcid.org/0000-0002-0780-033X"
title: "SpeziChat"
doi: 10.5281/zenodo.10161087
url: "https://github.com/StanfordSpezi/SpeziChat"

GitHub Events

Total
  • Create event: 8
  • Release event: 3
  • Issues event: 5
  • Watch event: 3
  • Delete event: 4
  • Member event: 1
  • Issue comment event: 12
  • Push event: 18
  • Pull request review comment event: 25
  • Pull request review event: 26
  • Pull request event: 11
  • Fork event: 5
Last Year
  • Create event: 8
  • Release event: 3
  • Issues event: 5
  • Watch event: 3
  • Delete event: 4
  • Member event: 1
  • Issue comment event: 12
  • Push event: 18
  • Pull request review comment event: 25
  • Pull request review event: 26
  • Pull request event: 11
  • Fork event: 5

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 2
  • Total pull requests: 19
  • Average time to close issues: 10 months
  • Average time to close pull requests: 18 days
  • Total issue authors: 2
  • Total pull request authors: 4
  • Average comments per issue: 0.5
  • Average comments per pull request: 2.47
  • Merged pull requests: 17
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Issue authors: 1
  • Pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 1.33
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • PSchmiedmayer (1)
  • philippzagar (1)
  • jdisho (1)
Pull Request Authors
  • philippzagar (23)
  • PSchmiedmayer (3)
  • MatthewTurk247 (2)
  • LeonNissen (2)
  • vishnuravi (2)
Top Labels
Issue Labels
enhancement (3) help wanted (1)
Pull Request Labels
enhancement (27) bug (2) documentation (1)

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 15
swiftpackageindex.com: github.com/StanfordSpezi/SpeziChat

Spezi Module to Handle and Display User Interfaces for Chat-based Interactions

  • Versions: 15
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 16.6%
Average: 25.8%
Dependent repos count: 34.9%
Last synced: 11 months ago

Dependencies

.github/workflows/build-and-test.yml actions
.github/workflows/pull_request.yml actions
Package.swift swiftpm
.github/workflows/monthly-markdown-link-check.yml actions