Skip to content

Commit

Permalink
fix: endpoint; fix: override context length
Browse files Browse the repository at this point in the history
  • Loading branch information
purr100 committed Nov 11, 2024
1 parent bd40a1c commit 6cfdd36
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 34 deletions.
8 changes: 4 additions & 4 deletions Chato.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
EB64221D2B6F7BB100119DE6 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EB64221C2B6F7BB100119DE6 /* Preview Assets.xcassets */; };
EB6422512B6F7C9300119DE6 /* ModelContainerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB6422262B6F7C9300119DE6 /* ModelContainerPreview.swift */; };
EB6422552B6F7C9400119DE6 /* TestButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB64222D2B6F7C9300119DE6 /* TestButton.swift */; };
EB6422562B6F7C9400119DE6 /* ProxyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB64222E2B6F7C9300119DE6 /* ProxyView.swift */; };
EB6422562B6F7C9400119DE6 /* EndpointView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB64222E2B6F7C9300119DE6 /* EndpointView.swift */; };
EB6422582B6F7C9400119DE6 /* Other.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB6422322B6F7C9300119DE6 /* Other.swift */; };
EB6422592B6F7C9400119DE6 /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB6422332B6F7C9300119DE6 /* SettingView.swift */; };
EB64225A2B6F7C9400119DE6 /* ChatListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB6422352B6F7C9300119DE6 /* ChatListView.swift */; };
Expand Down Expand Up @@ -148,7 +148,7 @@
EB6422232B6F7C0600119DE6 /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
EB6422262B6F7C9300119DE6 /* ModelContainerPreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelContainerPreview.swift; sourceTree = "<group>"; };
EB64222D2B6F7C9300119DE6 /* TestButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestButton.swift; sourceTree = "<group>"; };
EB64222E2B6F7C9300119DE6 /* ProxyView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxyView.swift; sourceTree = "<group>"; };
EB64222E2B6F7C9300119DE6 /* EndpointView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EndpointView.swift; sourceTree = "<group>"; };
EB6422322B6F7C9300119DE6 /* Other.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Other.swift; sourceTree = "<group>"; };
EB6422332B6F7C9300119DE6 /* SettingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = "<group>"; };
EB6422352B6F7C9300119DE6 /* ChatListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatListView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -410,7 +410,7 @@
isa = PBXGroup;
children = (
EB64222D2B6F7C9300119DE6 /* TestButton.swift */,
EB64222E2B6F7C9300119DE6 /* ProxyView.swift */,
EB64222E2B6F7C9300119DE6 /* EndpointView.swift */,
EB7906B92B979DEC00BB16D1 /* SelectTextView.swift */,
);
path = Whatever;
Expand Down Expand Up @@ -724,7 +724,7 @@
EB64225F2B6F7C9400119DE6 /* ChatDetailView.swift in Sources */,
EB58C3BF2B85D16000DF8DDB /* TutorialView.swift in Sources */,
EB6422592B6F7C9400119DE6 /* SettingView.swift in Sources */,
EB6422562B6F7C9400119DE6 /* ProxyView.swift in Sources */,
EB6422562B6F7C9400119DE6 /* EndpointView.swift in Sources */,
EB8089802CE12A910003BACD /* APIClientKey.swift in Sources */,
EB6E08E12B9BA0A800100DFE /* Cache.swift in Sources */,
EB0FC7DD2BEBF71F001BFD49 /* Icons.swift in Sources */,
Expand Down
16 changes: 4 additions & 12 deletions Chato/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@ struct ContentView: View {
@StateObject var storeVM = StoreVM()
@ObservedObject var pref = Pref.shared
@Environment(\.colorScheme) private var colorScheme
@StateObject private var openAIServiceProvider: OpenAIServiceProvider

init() {
if Pref.shared.gptEnableEndpoint {
_openAIServiceProvider = StateObject(wrappedValue: OpenAIServiceProvider(apiKey: Pref.shared.gptApiKey, baseUrl: Pref.shared.gptBaseURL))
} else {
_openAIServiceProvider = StateObject(wrappedValue: OpenAIServiceProvider(apiKey: Pref.shared.gptApiKey))
}
}


var body: some View {
let o = OpenAIServiceProvider(apiKey: pref.gptApiKey, baseUrl: pref.gptBaseURL)
let openai = pref.gptEnableEndpoint ? OpenAIServiceProvider(apiKey: pref.gptApiKey, baseUrl: pref.gptBaseURL) : OpenAIServiceProvider(apiKey: pref.gptApiKey)

HomePage()
.environmentObject(EM.shared)
.environmentObject(storeVM)
.environmentObject(pref)
.preferredColorScheme(pref.computedColorScheme)
.environment(\.openAIService, o.service)
.environment(\.openAIService, openai.service)
}
}

Expand Down
26 changes: 13 additions & 13 deletions Chato/Views/MessageList/InputAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,25 @@ struct InputAreaView: View {
}
.contextMenu {
let count = chat.messages.count
if count >= 20 {
Section("Send with context length") {
Section("Send with context length") {
if count >= 20 {
Menu {
if count >= 20 { Button("20") { send(20) }}
if count < 50 { Button("\(count) (max)") { send(count) }}
if count < 50 { Button("\(count) (all messages)") { send(count) }}
if count >= 50 { Button("50") { send(50) }}
if count > 50 { Button("\(count) (max)") { send(count) }}
if count > 50 { Button("\(count) (all messages)") { send(count) }}
} label: {
Button("More") {}
}
}
ForEach([0, 1, 2, 3, 4, 6, 8, 10].reversed(), id: \.self) { i in
Button("\(i)") { send(i) }
}
} else {
if count > 10 { Button("\(count) (max)") { send(count) }}
ForEach((0 ... 10).reversed(), id: \.self) { i in
if i < count { Button("\(i)") { send(i) }}
if i == count { Button("\(i) (max)") { send(i) }}
ForEach([0, 1, 2, 3, 4, 6, 8, 10].reversed(), id: \.self) { i in
Button("\(i)") { send(i) }
}
} else {
if count > 10 { Button("\(count) (all messages)") { send(count) }}
ForEach((0 ... 10).reversed(), id: \.self) { i in
if i < count { Button("\(i)") { send(i) }}
if i == count { Button("\(i) (all messages)") { send(i) }}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Chato/Views/Settings/ChatGPTSettingSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ struct ChatGPTSettingSection: View {
}
}
NavigationLink {
ProxyView($pref.gptEnableEndpoint, $pref.gptBaseURL)
.navigationTitle("Proxy")
EndpointView($pref.gptEnableEndpoint, $pref.gptBaseURL)
.navigationTitle("Endpoint")
.toolbarTitleDisplayMode(.inline)
} label: {
HStack {
Label {
Text("Proxy")
Text("Endpoint")
} icon: {
Image(systemName: "network")
.foregroundColor(.accentColor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

struct ProxyView: View {
struct EndpointView: View {
@Binding var useEndpoint: Bool
@Binding var baseURL: String

Expand Down Expand Up @@ -52,5 +52,5 @@ struct ProxyView: View {
#Preview {
@Previewable @State var useEndpoint = false
@Previewable @State var baseURL = "http://abc.com"
ProxyView($useEndpoint, $baseURL)
EndpointView($useEndpoint, $baseURL)
}

0 comments on commit 6cfdd36

Please sign in to comment.