-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from SunburstEnzo/demoapp-listmodels
Add models example to Demo app
- Loading branch information
Showing
9 changed files
with
116 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Store.swift | ||
// ChatStore.swift | ||
// DemoChat | ||
// | ||
// Created by Sihao Lu on 3/25/23. | ||
|
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,32 @@ | ||
// | ||
// MiscStore.swift | ||
// DemoChat | ||
// | ||
// Created by Aled Samuel on 22/04/2023. | ||
// | ||
|
||
import Foundation | ||
import OpenAI | ||
|
||
public final class MiscStore: ObservableObject { | ||
public var openAIClient: OpenAIProtocol | ||
|
||
@Published var availableModels: [ModelResult] = [] | ||
|
||
public init( | ||
openAIClient: OpenAIProtocol | ||
) { | ||
self.openAIClient = openAIClient | ||
} | ||
|
||
@MainActor | ||
func getModels() async { | ||
do { | ||
let response = try await openAIClient.models() | ||
availableModels = response.data | ||
} catch { | ||
// TODO: Better error handling | ||
print(error.localizedDescription) | ||
} | ||
} | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// | ||
// IDProvider.swift | ||
// | ||
// DemoChat | ||
// | ||
// Created by Sihao Lu on 4/6/23. | ||
// | ||
|
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,27 @@ | ||
// | ||
// ListModelsView.swift | ||
// DemoChat | ||
// | ||
// Created by Aled Samuel on 22/04/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct ListModelsView: View { | ||
@ObservedObject var store: MiscStore | ||
|
||
public var body: some View { | ||
NavigationStack { | ||
List($store.availableModels) { row in | ||
Text(row.id) | ||
} | ||
.listStyle(.insetGrouped) | ||
.navigationTitle("Models") | ||
} | ||
.onAppear { | ||
Task { | ||
await store.getModels() | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
// | ||
// MiscView.swift | ||
// DemoChat | ||
// | ||
// Created by Aled Samuel on 22/04/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct MiscView: View { | ||
@ObservedObject var store: MiscStore | ||
|
||
public init(store: MiscStore) { | ||
self.store = store | ||
} | ||
|
||
public var body: some View { | ||
NavigationStack { | ||
List { | ||
Section(header: Text("Models")) { | ||
NavigationLink("List Models", destination: ListModelsView(store: store)) | ||
NavigationLink("Retrieve Model", destination: RetrieveModelView()) | ||
} | ||
} | ||
.listStyle(.insetGrouped) | ||
.navigationTitle("Misc") | ||
} | ||
} | ||
} | ||
|
||
struct RetrieveModelView: View { | ||
var body: some View { | ||
Text("Retrieve Model: TBD") | ||
.font(.largeTitle) | ||
} | ||
} |
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