generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SpeziLLM Remote OpenAI integration (#41)
# SpeziLLM Remote OpenAI integration ## ♻️ Current situation & Problem Currently, the module provides basic OpenAI integration, however, not in the SpeziLLM ecosystem. ## ⚙️ Release Notes - Add the `SpeziLLMOpenAI` target that provides an OpenAI integration on the basis of the SpeziLLM ecosystem. ## 📚 Documentation Added in-line docs + DocC articles + README ## ✅ Testing Wrote basic UI test cases, manual testing ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [X] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
1 parent
3dd6610
commit c3b31a3
Showing
62 changed files
with
1,835 additions
and
787 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SpeziChat | ||
|
||
|
||
extension Chat { | ||
/// Append an `ChatEntity/Role/assistant` output to the `Chat`. | ||
/// Automatically overwrites the last `ChatEntity/Role/assistant` message if there is one, otherwise create a new one. | ||
/// | ||
/// - Parameters: | ||
/// - output: The `ChatEntity/Role/assistant` output `String` (part) that should be appended. | ||
@MainActor | ||
public mutating func append(assistantOutput output: String) { | ||
if self.last?.role == .assistant { | ||
self[self.count - 1] = .init( | ||
role: self.last?.role ?? .assistant, | ||
content: (self.last?.content ?? "") + output | ||
) | ||
} else { | ||
self.append(.init(role: .assistant, content: output)) | ||
} | ||
} | ||
|
||
/// Append an `ChatEntity/Role/user` input to the `Chat`. | ||
/// | ||
/// - Parameters: | ||
/// - input: The `ChatEntity/Role/user` input that should be appended. | ||
@MainActor | ||
public mutating func append(userInput input: String) { | ||
self.append(.init(role: .user, content: input)) | ||
} | ||
|
||
/// Append an `ChatEntity/Role/system` prompt to the `Chat` at the first position. | ||
/// | ||
/// - Parameters: | ||
/// - systemPrompt: The `ChatEntity/Role/system` prompt of the `Chat`, inserted at the very beginning. | ||
@MainActor | ||
public mutating func append(systemMessage systemPrompt: String) { | ||
self.insert(.init(role: .system, content: systemPrompt), at: 0) | ||
} | ||
} |
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
Oops, something went wrong.