Skip to content

Commit

Permalink
multyline input style
Browse files Browse the repository at this point in the history
gpt2 metal temporary disabled
  • Loading branch information
guinmoon committed Dec 5, 2023
1 parent 2ffe083 commit 207ea99
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 64 deletions.
8 changes: 6 additions & 2 deletions LLMFarm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
1509BA602B1E6FD400703BC0 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1509BA5F2B1E6FD400703BC0 /* Extensions.swift */; };
1509BA622B1F1D7000703BC0 /* LLMTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1509BA612B1F1D7000703BC0 /* LLMTextView.swift */; };
15141E5C2A651F8C0060E767 /* model_setting_templates in Resources */ = {isa = PBXBuildFile; fileRef = 15141E5B2A651F8C0060E767 /* model_setting_templates */; };
15141E712A65799D0060E767 /* ModelSettingsTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15141E702A65799D0060E767 /* ModelSettingsTemplate.swift */; };
1532BF7A2A9FA885006DC514 /* GetDeviceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1532BF792A9FA885006DC514 /* GetDeviceInfo.swift */; };
Expand Down Expand Up @@ -97,6 +98,7 @@

/* Begin PBXFileReference section */
1509BA5F2B1E6FD400703BC0 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
1509BA612B1F1D7000703BC0 /* LLMTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LLMTextView.swift; sourceTree = "<group>"; };
15141E362A6488A60060E767 /* Replit 3B.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Replit 3B.json"; sourceTree = "<group>"; };
15141E372A6488A60060E767 /* dolly v2 3b.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "dolly v2 3b.json"; sourceTree = "<group>"; };
15141E382A6488A60060E767 /* orca mini 3b.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "orca mini 3b.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -263,6 +265,7 @@
15A3EDC62A2121D90030AF5A /* OnlineUserView.swift */,
15A3EDC72A2121D90030AF5A /* ChatItem.swift */,
156A48CF2A52B55B007DF519 /* SplitViews.swift */,
1509BA612B1F1D7000703BC0 /* LLMTextView.swift */,
);
path = Chats;
sourceTree = "<group>";
Expand Down Expand Up @@ -535,6 +538,7 @@
15B7BE9D2A968399006624BD /* MacEditorTextView.swift in Sources */,
15F210AA2A1A659B0021F414 /* FileHelper.swift in Sources */,
15F210932A1920AA0021F414 /* MessageView.swift in Sources */,
1509BA622B1F1D7000703BC0 /* LLMTextView.swift in Sources */,
15A3EDD12A21266E0030AF5A /* SearchView.swift in Sources */,
15F210942A1920AA0021F414 /* Message.swift in Sources */,
15F2108E2A191EE60021F414 /* ChatView.swift in Sources */,
Expand Down Expand Up @@ -634,7 +638,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEVELOPMENT_ASSET_PATHS = "\"LLMFarm/Preview Content\"";
DEVELOPMENT_TEAM = C66ZA422A7;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -683,7 +687,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEVELOPMENT_ASSET_PATHS = "\"LLMFarm/Preview Content\"";
DEVELOPMENT_TEAM = C66ZA422A7;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down
90 changes: 30 additions & 60 deletions LLMFarm/Chats/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ struct ChatView: View {

@EnvironmentObject var aiChatModel: AIChatModel
@EnvironmentObject var orientationInfo: OrientationInfo
#if os(iOS)
var placeholderString: String = "Type your message..."

//#if os(iOS)
@State var placeholderString: String = "Type your message..."
@State private var inputText: String = "Type your message..."
#else
var placeholderString: String = ""
@State private var inputText: String = ""
#endif
//#else
// var placeholderString: String = ""
// @State private var inputText: String = ""
//#endif


@Binding var model_name: String
Expand All @@ -40,18 +40,30 @@ struct ChatView: View {
private var isInputFieldFocused: Bool

func scrollToBottom(with_animation:Bool = false) {
var scroll_bug = true
#if os(macOS)
scroll_bug = false
#else
if #available(iOS 16.4, *){
scroll_bug = false
}
#endif
if scroll_bug {
return
}
let last_msg = aiChatModel.messages.last // try to fixscrolling and specialized Array._checkSubscript(_:wasNativeTypeChecked:)
if last_msg != nil && last_msg?.id != nil && scrollProxy != nil{
if with_animation{
withAnimation {
// scrollProxy?.scrollTo(last_msg?.id, anchor: .bottom)
scrollProxy?.scrollTo("latest")
scrollProxy?.scrollTo(last_msg?.id, anchor: .bottom)
// scrollProxy?.scrollTo("latest")
}
}else{
// scrollProxy?.scrollTo(last_msg?.id, anchor: .bottom)
scrollProxy?.scrollTo("latest")
scrollProxy?.scrollTo(last_msg?.id, anchor: .bottom)
// scrollProxy?.scrollTo("latest")
}
}

}

func reload() async{
Expand Down Expand Up @@ -86,35 +98,15 @@ struct ChatView: View {
MessageView(message: message).id(message.id)
}
.listRowSeparator(.hidden)
Text("").id("latest")
// Text("").id("latest")
}
.listStyle(PlainListStyle())

HStack{
//#if os(macOS)
// DidEndEditingTextField(text: $inputText, didEndEditing: { input in})
// .frame( alignment: .leading)
////#else
// TextField(placeholderString, text: $inputText, axis: .vertical)
// .textFieldStyle(RoundedBorderTextFieldStyle())
// .lineLimit(1...10)
TextEditor(text: $inputText)
.padding(.vertical, 6)
.padding(.leading, 5)
.lineSpacing(1)
.font(.system(.body))
.foregroundColor(inputText == placeholderString ? .gray : .primary)
.onTapGesture {
if inputText == placeholderString {
inputText = ""
}
}

//#endif
LLMTextView(placeholder:$placeholderString, text: $inputText)
Button {
Task {
let text = inputText
inputText = placeholderString
// inputText = placeholderString
if (aiChatModel.predicting){
aiChatModel.stop_predict()
}else
Expand All @@ -138,29 +130,11 @@ struct ChatView: View {
.padding(.leading, 10)
.padding(.trailing, 5)
.padding(.bottom, 5)
.frame(height:67)
.background(.regularMaterial)
.onChange(of: aiChatModel.AI_typing){ ai_typing in
// .onChange(of: aiChatModel.messages.count){ count in
// Fix for theese https://developer.apple.com/forums/thread/712510
#if os(macOS)
if (aiChatModel.predicting){
scrollToBottom(with_animation: true)
}else{
scrollToBottom(with_animation: false)
}
#endif
if #available(iOS 16.4, *){
if (aiChatModel.predicting){
scrollToBottom(with_animation: true)
}else{
scrollToBottom(with_animation: false)
}
}
scrollToBottom(with_animation: false)
}
.frame(height:47)
.background(.regularMaterial)
// .padding(.bottom)
// .padding(.leading)
// .padding(.trailing)
}
.navigationTitle($title)
.toolbar {
Expand Down Expand Up @@ -190,12 +164,7 @@ struct ChatView: View {
.disabled(chat_selection == nil)
.onAppear(){
scrollProxy = scrollView
#if os(macOS)
scrollToBottom(with_animation: false)
#endif
if #available(iOS 16.4, *) {
scrollToBottom(with_animation: false)
}
}
}
.frame(maxHeight: .infinity)
Expand All @@ -211,6 +180,7 @@ struct ChatView: View {
}
}
}

}
}
}
Expand Down
62 changes: 62 additions & 0 deletions LLMFarm/Chats/LLMTextView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// LLMTextView.swift
// LLMFarm
//
// Created by guinmoon on 05.12.2023.
//

import SwiftUI



struct LLMTextView: View {
@Binding var placeholder: String
@Binding var text: String
var body: some View {
TextEditor(text: self.$text)
// make the color of the placeholder gray
#if os(macOS)
.padding(.vertical, 5)
#else
.padding(.top, 10)
.listRowBackground(Color(uiColor: .systemGroupedBackground))
#endif
.padding(.leading, 5)
.lineSpacing(1)
.font(.system(.body))
.background {
RoundedRectangle(cornerRadius: 8)
#if os(macOS)
.fill(Color(NSColor.textBackgroundColor))
#else
.fill(Color(UIColor.systemBackground))
#endif
.padding(.top,8)
}
#if os(iOS)
.onAppear {
// remove the placeholder text when keyboard appears
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { (noti) in
withAnimation {
if self.text == placeholder {
self.text = ""
}
}
}

// put back the placeholder text if the user dismisses the keyboard without adding any text
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { (noti) in
withAnimation {
if self.text == "" {
self.text = placeholder
}
}
}
}
#endif
}
}

#Preview {
LLMTextView(placeholder: .constant("type here"),text: .constant(""))
}
4 changes: 2 additions & 2 deletions LLMFarm/Lib/Orientation_helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ final class OrientationInfo: ObservableObject {
}

// unowned self because we unregister before self becomes invalid
_observer = NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: nil) { [unowned self] note in
guard let device = note.object as? UIDevice else {
_observer = NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: nil) { [unowned self] text in
guard let device = text.object as? UIDevice else {
return
}
if device.orientation.isPortrait {
Expand Down

0 comments on commit 207ea99

Please sign in to comment.