11package com.simiacryptus.skyenet.core.platform.hsql
22
3- import com.google.common.util.concurrent.AtomicDouble
43import com.simiacryptus.jopenai.models.ApiModel
54import com.simiacryptus.jopenai.models.ChatModel
65import com.simiacryptus.jopenai.models.OpenAIModel
@@ -12,7 +11,6 @@ import java.sql.Connection
1211import java.sql.DriverManager
1312import java.sql.ResultSet
1413import java.sql.Timestamp
15- import java.util.concurrent.atomic.AtomicLong
1614
1715class HSQLUsageManager (private val dbFile : File ) : UsageInterface {
1816
@@ -44,17 +42,6 @@ class HSQLUsageManager(private val dbFile: File) : UsageInterface {
4442 }
4543
4644
47- private fun updateSchema () {
48- log.info(" Updating database schema if needed" )
49- // Add schema update logic here if needed
50- }
51-
52- private fun deleteSchema () {
53- log.info(" Deleting database schema if exists" )
54- connection.createStatement().executeUpdate(" DROP TABLE IF EXISTS usage" )
55- log.debug(" Schema deleted" )
56- }
57-
5845 override fun incrementUsage (session : Session , apiKey : String? , model : OpenAIModel , tokens : ApiModel .Usage ) {
5946 try {
6047 log.debug(" Incrementing usage for session: ${session.sessionId} , apiKey: $apiKey , model: ${model.modelName} " )
@@ -103,27 +90,6 @@ class HSQLUsageManager(private val dbFile: File) : UsageInterface {
10390 connection.createStatement().executeUpdate(" DELETE FROM usage" )
10491 }
10592
106- private fun getUsageValues (usageKey : UsageInterface .UsageKey ): UsageInterface .UsageValues {
107- log.debug(" Getting usage values for session: ${usageKey.session.sessionId} , apiKey: ${usageKey.apiKey} , model: ${usageKey.model.modelName} " )
108- val statement = connection.prepareStatement(
109- """
110- SELECT COALESCE(SUM(prompt_tokens), 0), COALESCE(SUM(completion_tokens), 0), COALESCE(SUM(cost), 0)
111- FROM usage
112- WHERE session_id = ? AND api_key = ? AND model = ?
113- """
114- )
115- statement.setString(1 , usageKey.session.sessionId)
116- statement.setString(2 , usageKey.apiKey ? : " " )
117- statement.setString(3 , usageKey.model.toString())
118- val resultSet = statement.executeQuery()
119- resultSet.next()
120- return UsageInterface .UsageValues (
121- AtomicLong (resultSet.getLong(1 )),
122- AtomicLong (resultSet.getLong(2 )),
123- AtomicDouble (resultSet.getDouble(3 ))
124- )
125- }
126-
12793 private fun saveUsageValues (usageKey : UsageInterface .UsageKey , usageValues : UsageInterface .UsageValues ) {
12894 log.debug(" Saving usage values for session: ${usageKey.session.sessionId} , apiKey: ${usageKey.apiKey} , model: ${usageKey.model.modelName} " )
12995 val statement = connection.prepareStatement(
0 commit comments