-
Notifications
You must be signed in to change notification settings - Fork 99
Implementing cross-platform support by supporting Linux-friendly HTTP clients #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
a896e09
9ca94c4
fdf93d9
c9798d7
195dd42
6d068cd
3467e61
0274d45
6a94d26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
// | ||
// Created by Lou Zell on 3/27/24. | ||
// | ||
|
||
#if !os(Linux) | ||
import Foundation | ||
|
||
private let aiproxySecureDelegate = AIProxyCertificatePinningDelegate() | ||
|
@@ -44,8 +44,10 @@ struct AIProxyService: OpenAIService { | |
self.organizationID = organizationID | ||
self.debugEnabled = debugEnabled | ||
openAIEnvironment = .init(baseURL: serviceURL ?? "https://api.aiproxy.pro", proxyPath: nil, version: "v1") | ||
self.httpClient = NoOpClient() | ||
} | ||
|
||
let httpClient: HTTPClient | ||
let session: URLSession | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super familiar with the code, but it seems weird to see both HTTPClient and URLSession properties here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not remove the self.httpClient = URLSessionHTTPClientAdapter(urlSession: URLSession(
configuration: .default,
delegate: aiproxySecureDelegate,
delegateQueue: nil)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a good idea, removed the |
||
let decoder: JSONDecoder | ||
let openAIEnvironment: OpenAIEnvironment | ||
|
@@ -1314,3 +1316,26 @@ struct AIProxyService: OpenAIService { | |
private let organizationID: String? | ||
|
||
} | ||
|
||
// MARK: - NoOpClient | ||
|
||
// An HTTPClient created specifically for AIProxyService, since it will only be used on iOS/macOS | ||
// and we will not be supporting it on Linux. | ||
private struct NoOpClient: HTTPClient { | ||
func data(for request: HTTPRequest) async throws -> (Data, HTTPResponse) { | ||
( | ||
Data(), | ||
HTTPResponse(statusCode: 500, headers: [:]) | ||
) | ||
} | ||
|
||
func bytes(for request: HTTPRequest) async throws -> (HTTPByteStream, HTTPResponse) { | ||
( | ||
HTTPByteStream.bytes( | ||
.init(unfolding: { nil }) | ||
), | ||
HTTPResponse(statusCode: 500, headers: [:]) | ||
) | ||
} | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is possible, but can we scope this to only linux for now? ie wrap in
#if os(Linux)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made this change by using
condition: .when(platforms: [.linux])
, since#if os(Linux)
doesn't work in Package.swift.