Skip to content

Commit

Permalink
Update ChatSocket.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Nov 21, 2023
1 parent 9fe433b commit 1d37142
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class ChatSocket(
private val user: User?,
) : WebSocketAdapter() {

private val logfile = ".sys/openai.log"
val logfile by lazy {
val file = dataStorage?.getSessionDir(user, session)?.resolve(".sys/openai.log")
file?.parentFile?.mkdirs()
file
}

val api: OpenAIClient
get() {
Expand All @@ -29,7 +33,7 @@ class ChatSocket(
return object : OpenAIClient(
logLevel = Level.DEBUG,
logStreams = mutableListOf(
dataStorage?.getSessionDir(user, session)?.resolve(logfile)?.outputStream()?.buffered()
logfile?.outputStream()?.buffered()
).filterNotNull().toMutableList()
) {
override fun incrementTokens(model: OpenAIModel?, tokens: Usage) {
Expand All @@ -48,7 +52,7 @@ class ChatSocket(
key = userSettings.apiKey,
logLevel = Level.DEBUG,
logStreams = mutableListOf(
dataStorage?.getSessionDir(user, session)?.resolve(logfile)?.outputStream()?.buffered()
logfile?.outputStream()?.buffered()
).filterNotNull().toMutableList(),
) {
override fun incrementTokens(model: OpenAIModel?, tokens: Usage) {
Expand Down

0 comments on commit 1d37142

Please sign in to comment.