Skip to content

Commit 6f1a8dd

Browse files
Merge pull request #110 from jamesrochabrun/jroch-removing-static
Removing Static properties from OpenAI API
2 parents 8cfa454 + edd3f4e commit 6f1a8dd

File tree

13 files changed

+337
-231
lines changed

13 files changed

+337
-231
lines changed

Examples/SwiftOpenAIExample/SwiftOpenAIExample/LocalChatDemo/LocalChatDemoView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ struct LocalChatDemoView: View {
9999
messages: [.init(
100100
role: .user,
101101
content: content)],
102-
// Make sure you run `ollama pull llama3` in your terminal to download this model.
103-
model: .custom("llama3"))
102+
// Make sure you run `ollama pull llama3.1` in your terminal to download this model.
103+
model: .custom("llama3.1"))
104104
switch selectedSegment {
105105
case .chatCompletion:
106106
try await chatProvider.startChat(parameters: parameters)

Examples/SwiftOpenAIExample/SwiftOpenAIExample/LocalHostEntryView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct LocalHostEntryView: View {
1919
TextField("Enter URL", text: $url)
2020
.padding()
2121
.textFieldStyle(.roundedBorder)
22-
NavigationLink(destination: OptionsListView(openAIService: OpenAIServiceFactory.service(baseURL: url), options: [.localChat])) {
22+
NavigationLink(destination: OptionsListView(openAIService: OpenAIServiceFactory.service(baseURL: url, debugEnabled: true), options: [.localChat])) {
2323
Text("Continue")
2424
.padding()
2525
.padding(.horizontal, 48)

Sources/OpenAI/AIProxy/AIProxyService.swift

+83-71
Large diffs are not rendered by default.

Sources/OpenAI/AIProxy/Endpoint+AIProxy.swift

+9-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ private let deviceCheckWarning = """
3535
extension Endpoint {
3636

3737
private func urlComponents(
38-
serviceURL: String?,
38+
serviceURL: String,
39+
path: String,
3940
queryItems: [URLQueryItem])
4041
-> URLComponents
4142
{
42-
var components = URLComponents(string: serviceURL ?? "https://api.aiproxy.pro")!
43+
var components = URLComponents(string: serviceURL)!
4344
components.path = components.path.appending(path)
4445
if !queryItems.isEmpty {
4546
components.queryItems = queryItems
@@ -49,16 +50,17 @@ extension Endpoint {
4950

5051
func request(
5152
aiproxyPartialKey: String,
52-
serviceURL: String?,
5353
clientID: String?,
5454
organizationID: String?,
55+
openAIEnvironment: OpenAIEnvironment,
5556
method: HTTPMethod,
5657
params: Encodable? = nil,
5758
queryItems: [URLQueryItem] = [],
5859
betaHeaderField: String? = nil)
5960
async throws -> URLRequest
6061
{
61-
var request = URLRequest(url: urlComponents(serviceURL: serviceURL, queryItems: queryItems).url!)
62+
let finalPath = path(in: openAIEnvironment)
63+
var request = URLRequest(url: urlComponents(serviceURL: openAIEnvironment.baseURL, path: finalPath, queryItems: queryItems).url!)
6264
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
6365
request.addValue(aiproxyPartialKey, forHTTPHeaderField: "aiproxy-partial-key")
6466
if let organizationID {
@@ -87,7 +89,7 @@ extension Endpoint {
8789

8890
func multiPartRequest(
8991
aiproxyPartialKey: String,
90-
serviceURL: String?,
92+
openAIEnvironment: OpenAIEnvironment,
9193
clientID: String?,
9294
organizationID: String?,
9395
method: HTTPMethod,
@@ -96,7 +98,8 @@ extension Endpoint {
9698
)
9799
async throws -> URLRequest
98100
{
99-
var request = URLRequest(url: urlComponents(serviceURL: serviceURL, queryItems: queryItems).url!)
101+
let finalPath = path(in: openAIEnvironment)
102+
var request = URLRequest(url: urlComponents(serviceURL: openAIEnvironment.baseURL, path: finalPath, queryItems: queryItems).url!)
100103
request.httpMethod = method.rawValue
101104
request.addValue(aiproxyPartialKey, forHTTPHeaderField: "aiproxy-partial-key")
102105
if let organizationID {

Sources/OpenAI/Azure/AzureOpenAIAPI.swift

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import Foundation
1010
// MARK: - AzureOpenAIAPI
1111

1212
enum AzureOpenAIAPI {
13-
14-
static var azureOpenAIResource: String = ""
15-
13+
1614
/// https://learn.microsoft.com/en-us/azure/ai-services/openai/assistants-reference?tabs=python
1715
/// https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/assistant
1816
case assistant(AssistantCategory)
@@ -90,11 +88,7 @@ enum AzureOpenAIAPI {
9088

9189
extension AzureOpenAIAPI: Endpoint {
9290

93-
var base: String {
94-
"https://\(Self.azureOpenAIResource)/openai.azure.com"
95-
}
96-
97-
var path: String {
91+
func path(in env: OpenAIEnvironment) -> String {
9892
switch self {
9993
case .chat(let deploymentID): return "/openai/deployments/\(deploymentID)/chat/completions"
10094
case .assistant(let category):

0 commit comments

Comments
 (0)