-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace [String: String] with struct ChatMessage
- Loading branch information
Showing
9 changed files
with
387 additions
and
341 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
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,49 @@ | ||
// | ||
// ChatMessage.swift | ||
// Easydict | ||
// | ||
// Created by tisfeng on 2024/11/3. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
func systemMessage(queryType: EZQueryTextType) -> ChatMessage { | ||
switch queryType { | ||
case .dictionary: | ||
.init(role: .system, content: LLMStreamService.dictSystemPrompt) | ||
default: | ||
.init(role: .system, content: LLMStreamService.translationSystemPrompt) | ||
} | ||
} | ||
|
||
func chatMessagePair(userContent: String, assistantContent: String) -> [ChatMessage] { | ||
[ | ||
.init(role: .user, content: userContent), | ||
.init(role: .assistant, content: assistantContent), | ||
] | ||
} | ||
|
||
// MARK: - ChatMessage | ||
|
||
struct ChatMessage { | ||
// MARK: - ChatRole | ||
|
||
enum ChatRole: String, Codable, Equatable, CaseIterable { | ||
case system | ||
case user | ||
case assistant | ||
case tool | ||
case model // Gemini role, equal to OpenAI assistant role. | ||
} | ||
|
||
let role: ChatRole | ||
let content: String | ||
} | ||
|
||
// MARK: - AIToolType | ||
|
||
enum AIToolType { | ||
case polishing | ||
case summary | ||
} |
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.