-
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.
* 1.0.38 * ui api update * ImageActor * text input
- Loading branch information
1 parent
c26ad26
commit d68f0ff
Showing
28 changed files
with
518 additions
and
200 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
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
52 changes: 52 additions & 0 deletions
52
core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ImageActor.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,52 @@ | ||
package com.simiacryptus.skyenet.core.actors | ||
|
||
import com.simiacryptus.jopenai.API | ||
import com.simiacryptus.jopenai.ApiModel | ||
import com.simiacryptus.jopenai.ApiModel.* | ||
import com.simiacryptus.jopenai.OpenAIClient | ||
import com.simiacryptus.jopenai.models.ChatModels | ||
import com.simiacryptus.jopenai.models.ImageModels | ||
import com.simiacryptus.jopenai.models.OpenAITextModel | ||
import com.simiacryptus.jopenai.proxy.ChatProxy | ||
import java.awt.image.BufferedImage | ||
import java.util.function.Function | ||
|
||
open class ImageActor( | ||
prompt: String = "Transform the user request into an image generation prompt that the user will like", | ||
val action: String? = null, | ||
textModel: ChatModels = ChatModels.GPT35Turbo, | ||
val imageModel: ImageModels = ImageModels.DallE2, | ||
temperature: Double = 0.3, | ||
val width: Int = 1024, | ||
val height: Int = 1024, | ||
) : BaseActor<ImageResponse>( | ||
prompt = prompt, | ||
name = action, | ||
model = textModel, | ||
temperature = temperature, | ||
) { | ||
private inner class ImageResponseImpl(vararg messages: ChatMessage, val api: API) : ImageResponse { | ||
|
||
private val _text: String by lazy { response(*messages, api = api).choices.first().message?.content ?: throw RuntimeException("No response") } | ||
override fun getText(): String = _text | ||
override fun getImage(): BufferedImage { | ||
val url = (api as OpenAIClient).createImage( | ||
ImageGenerationRequest( | ||
prompt = getText(), | ||
model = imageModel.modelName, | ||
size = "${width}x$height" | ||
) | ||
).data.first().url | ||
return javax.imageio.ImageIO.read(java.net.URL(url)) | ||
} | ||
} | ||
|
||
override fun answer(vararg messages: ChatMessage, api: API): ImageResponse { | ||
return ImageResponseImpl(*messages, api = api) | ||
} | ||
} | ||
|
||
interface ImageResponse { | ||
fun getText(): String | ||
fun getImage(): BufferedImage | ||
} |
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.