|
1 | 1 | import Foundation |
| 2 | +import Logger |
2 | 3 |
|
3 | 4 | public struct EmbeddingResponse: Decodable { |
4 | 5 | public struct Object: Decodable { |
@@ -74,9 +75,19 @@ public struct EmbeddingService { |
74 | 75 | .otherError(String(data: result, encoding: .utf8) ?? "Unknown Error") |
75 | 76 | } |
76 | 77 |
|
77 | | - return try JSONDecoder().decode(EmbeddingResponse.self, from: result) |
| 78 | + let embeddingResponse = try JSONDecoder().decode(EmbeddingResponse.self, from: result) |
| 79 | + #if DEBUG |
| 80 | + Logger.service.info(""" |
| 81 | + Embedding usage |
| 82 | + - number of strings: \(text.count) |
| 83 | + - prompt tokens: \(embeddingResponse.usage.prompt_tokens) |
| 84 | + - total tokens: \(embeddingResponse.usage.total_tokens) |
| 85 | +
|
| 86 | + """) |
| 87 | + #endif |
| 88 | + return embeddingResponse |
78 | 89 | } |
79 | | - |
| 90 | + |
80 | 91 | public func embed(tokens: [[Int]]) async throws -> EmbeddingResponse { |
81 | 92 | guard let url = URL(string: configuration.endpoint) else { |
82 | 93 | throw ChatGPTServiceError.endpointIncorrect |
@@ -112,7 +123,17 @@ public struct EmbeddingService { |
112 | 123 | .otherError(String(data: result, encoding: .utf8) ?? "Unknown Error") |
113 | 124 | } |
114 | 125 |
|
115 | | - return try JSONDecoder().decode(EmbeddingResponse.self, from: result) |
| 126 | + let embeddingResponse = try JSONDecoder().decode(EmbeddingResponse.self, from: result) |
| 127 | + #if DEBUG |
| 128 | + Logger.service.info(""" |
| 129 | + Embedding usage |
| 130 | + - number of strings: \(tokens.count) |
| 131 | + - prompt tokens: \(embeddingResponse.usage.prompt_tokens) |
| 132 | + - total tokens: \(embeddingResponse.usage.total_tokens) |
| 133 | +
|
| 134 | + """) |
| 135 | + #endif |
| 136 | + return embeddingResponse |
116 | 137 | } |
117 | 138 | } |
118 | 139 |
|
0 commit comments