-
-
Notifications
You must be signed in to change notification settings - Fork 426
Expand file tree
/
Copy pathAutoManagedChatGPTMemoryGoogleAIStrategy.swift
More file actions
32 lines (27 loc) · 1.11 KB
/
AutoManagedChatGPTMemoryGoogleAIStrategy.swift
File metadata and controls
32 lines (27 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import ChatBasic
import Foundation
import GoogleGenerativeAI
import Logger
extension AutoManagedChatGPTMemory {
struct GoogleAIStrategy: AutoManagedChatGPTMemoryStrategy {
let configuration: ChatGPTConfiguration
func countToken(_ message: ChatMessage) async -> Int {
(await OpenAIStrategy().countToken(message)) + 20
// Using local tiktoken instead until I find a faster solution.
// The official solution requires sending a lot of requests when adjusting the prompt.
// adding 20 just incase.
// guard let model = configuration.model else {
// return 0
// }
// let aiModel = GenerativeModel(name: model.info.modelName, apiKey:
// configuration.apiKey)
// if message.isEmpty { return 0 }
// let modelMessage = ModelContent(message)
// return (try? await aiModel.countTokens([modelMessage]).totalTokens) ?? 0
}
func countToken<F>(_: F) async -> Int where F: ChatGPTFunction {
// function is not supported.
return 0
}
}
}