-
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
3ec61dc
commit 0a30f7c
Showing
24 changed files
with
219 additions
and
244 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
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
25 changes: 6 additions & 19 deletions
25
core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/BaseActor.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 |
---|---|---|
@@ -1,41 +1,28 @@ | ||
package com.simiacryptus.skyenet.core.actors | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore | ||
import com.simiacryptus.jopenai.API | ||
import com.simiacryptus.jopenai.ApiModel | ||
import com.simiacryptus.jopenai.ClientUtil.toContentList | ||
import com.simiacryptus.jopenai.OpenAIClient | ||
import com.simiacryptus.jopenai.models.ChatModels | ||
import com.simiacryptus.jopenai.models.OpenAIModel | ||
import com.simiacryptus.jopenai.models.OpenAITextModel | ||
|
||
abstract class BaseActor<T>( | ||
abstract class BaseActor<I,R>( | ||
open val prompt: String, | ||
val name: String? = null, | ||
val model: ChatModels = ChatModels.GPT35Turbo, | ||
val temperature: Double = 0.3, | ||
) { | ||
abstract fun answer(vararg messages: ApiModel.ChatMessage, api: API): T | ||
open fun response(vararg messages: ApiModel.ChatMessage, model: OpenAIModel = this.model, api: API) = (api as OpenAIClient).chat( | ||
abstract fun answer(vararg messages: ApiModel.ChatMessage, input: I, api: API): R | ||
open fun response(vararg input: ApiModel.ChatMessage, model: OpenAIModel = this.model, api: API) = (api as OpenAIClient).chat( | ||
ApiModel.ChatRequest( | ||
messages = ArrayList(messages.toList()), | ||
messages = ArrayList(input.toList()), | ||
temperature = temperature, | ||
model = this.model.modelName, | ||
), | ||
model = this.model | ||
) | ||
open fun answer(vararg questions: String, api: API): T = answer(*chatMessages(*questions), api = api) | ||
open fun answer(input: I, api: API): R = answer(*chatMessages(input), input=input, api = api) | ||
|
||
fun chatMessages(vararg questions: String) = arrayOf( | ||
ApiModel.ChatMessage( | ||
role = com.simiacryptus.jopenai.ApiModel.Role.system, | ||
content = prompt.toContentList() | ||
), | ||
) + questions.map { | ||
ApiModel.ChatMessage( | ||
role = com.simiacryptus.jopenai.ApiModel.Role.user, | ||
content = it.toContentList() | ||
) | ||
} | ||
abstract fun chatMessages(questions: I): Array<ApiModel.ChatMessage> | ||
|
||
} |
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
Oops, something went wrong.