Skip to content

Commit

Permalink
System Prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
imkylecat committed May 12, 2024
1 parent ae2442e commit cbaca34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions DesktopAI/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftData

struct GeneralSettingsView: View {
@AppStorage("isModelResponseStreamingEnabled") private var isModelResponseStreamingEnabled: Bool = false
@AppStorage("modelSystemPrompt") private var modelSystemPrompt: String = ""

var body: some View {
Form {
Expand All @@ -21,6 +22,9 @@ struct GeneralSettingsView: View {
.font(.caption)
.foregroundColor(.secondary)
}
Section(header: Text("System Prompts")) {
TextField("System Prompt", text: $modelSystemPrompt)
}
}
.padding()
}
Expand Down
10 changes: 9 additions & 1 deletion DesktopAI/Providers/GroqProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class GroqProvider: BaseProvider {

override func userSentChatMessage(item: Item) -> Void {
@AppStorage("apiKeyGrok") var apiKeyGrok: String = ""
@AppStorage("modelSystemPrompt") var modelSystemPrompt: String = ""

guard !apiKeyGrok.isEmpty else {
return
Expand All @@ -88,9 +89,16 @@ class GroqProvider: BaseProvider {
request.addValue("Bearer " + apiKeyGrok, forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

var messages = item.chatHistory.sorted { $0.timestamp < $1.timestamp }.map { ["role": $0.isFromAI ? "system" : "user", "content": $0.content] }
if !modelSystemPrompt.isEmpty {
let systemPrompt = ["role": "system", "content": modelSystemPrompt]
messages.insert(systemPrompt, at: 0)
}


let requestBody: [String: Any] = [
"max_tokens": 1024,
"messages": item.chatHistory.sorted { $0.timestamp < $1.timestamp }.map { ["role": $0.isFromAI ? "system" : "user", "content": $0.content] },
"messages": messages,
"model": item.model,
"stop": NSNull(),
"stream": false,
Expand Down

0 comments on commit cbaca34

Please sign in to comment.