-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
282e116
commit 52019b2
Showing
25 changed files
with
134 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.simiacryptus.skyenet.platform | ||
|
||
import com.simiacryptus.openai.OpenAIClient | ||
import com.simiacryptus.openai.OpenAIClientBase | ||
import com.simiacryptus.openai.models.OpenAIModel | ||
import org.slf4j.event.Level | ||
import java.io.File | ||
|
||
open class ClientManager { | ||
|
||
open fun createClient( | ||
session: Session, | ||
user: User?, | ||
dataStorage: DataStorage, | ||
): OpenAIClient { | ||
if (user != null) { | ||
val userSettings = ApplicationServices.userSettingsManager.getUserSettings(user) | ||
val logfile = dataStorage.getSessionDir(user, session).resolve(".sys/openai.log") | ||
logfile.parentFile?.mkdirs() | ||
val userApi = createClient(session, user, logfile, userSettings.apiKey) | ||
if (userApi != null) return userApi | ||
} | ||
val canUseGlobalKey = ApplicationServices.authorizationManager.isAuthorized(null, user, | ||
AuthorizationManager.OperationType.GlobalKey | ||
) | ||
if (!canUseGlobalKey) throw RuntimeException("No API key") | ||
val logfile = dataStorage.getSessionDir(user, session).resolve(".sys/openai.log") | ||
logfile.parentFile?.mkdirs() | ||
return createClient(session, user, logfile)!! | ||
} | ||
|
||
open protected fun createClient( | ||
session: Session, | ||
user: User?, | ||
logfile: File, | ||
key: String? = OpenAIClientBase.keyTxt | ||
): OpenAIClient? = if (key.isNullOrBlank()) null else object : OpenAIClient( | ||
key = key, | ||
logLevel = Level.DEBUG, | ||
logStreams = mutableListOf( | ||
logfile?.outputStream()?.buffered() | ||
).filterNotNull().toMutableList(), | ||
) { | ||
override fun incrementTokens(model: OpenAIModel?, tokens: Usage) { | ||
ApplicationServices.usageManager.incrementUsage(session, user, model!!, tokens) | ||
super.incrementTokens(model, tokens) | ||
} | ||
} | ||
|
||
private val log = org.slf4j.LoggerFactory.getLogger(ClientManager::class.java) | ||
} |
3 changes: 2 additions & 1 deletion
3
...iacryptus/skyenet/ApplicationDirectory.kt → ...yenet/application/ApplicationDirectory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...s/skyenet/session/ApplicationInterface.kt → ...yenet/application/ApplicationInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionListServlet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.