Fix EmbeddingService
This commit is contained in:
@@ -75,6 +75,16 @@ final class EmbeddingService {
|
||||
|
||||
private let settings = SettingsService.shared
|
||||
|
||||
/// Dedicated session for embedding requests — keeps embedding traffic isolated
|
||||
/// from the chat API sessions and self-limits concurrent connections.
|
||||
private let session: URLSession = {
|
||||
let config = URLSessionConfiguration.default
|
||||
config.httpMaximumConnectionsPerHost = 2 // max 2 concurrent embedding requests
|
||||
config.timeoutIntervalForRequest = 60
|
||||
config.timeoutIntervalForResource = 120
|
||||
return URLSession(configuration: config)
|
||||
}()
|
||||
|
||||
private init() {}
|
||||
|
||||
// MARK: - Provider Detection
|
||||
@@ -164,7 +174,7 @@ final class EmbeddingService {
|
||||
]
|
||||
request.httpBody = try JSONSerialization.data(withJSONObject: body)
|
||||
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
let (data, response) = try await session.data(for: request)
|
||||
|
||||
guard let httpResponse = response as? HTTPURLResponse else {
|
||||
throw EmbeddingError.invalidResponse
|
||||
@@ -205,7 +215,7 @@ final class EmbeddingService {
|
||||
]
|
||||
request.httpBody = try JSONSerialization.data(withJSONObject: body)
|
||||
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
let (data, response) = try await session.data(for: request)
|
||||
|
||||
guard let httpResponse = response as? HTTPURLResponse else {
|
||||
throw EmbeddingError.invalidResponse
|
||||
@@ -247,7 +257,7 @@ final class EmbeddingService {
|
||||
]
|
||||
request.httpBody = try JSONSerialization.data(withJSONObject: body)
|
||||
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
let (data, response) = try await session.data(for: request)
|
||||
|
||||
guard let httpResponse = response as? HTTPURLResponse else {
|
||||
throw EmbeddingError.invalidResponse
|
||||
|
||||
Reference in New Issue
Block a user