Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

446 add chatgpt integration #447

Merged
merged 9 commits into from
Feb 5, 2024
Merged

Conversation

jottinger
Copy link
Collaborator

  • Adding chatgpt library and access command
  • Removing extraneous debug messages
  • Adding rate limiting into the chatgpt operation

@jottinger jottinger linked an issue Feb 5, 2024 that may be closed by this pull request
@jottinger jottinger requested a review from evanchooly February 5, 2024 16:52
@Inject
constructor(val javabotConfig: JavabotConfig) {
companion object {
private var limiter: BotRateLimiter? = null
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just initialize here?

}

fun sendPromptToChatGPT(prompt: String): String? {
return if (javabotConfig.chatGptKey().isNotEmpty() && acquire(javabotConfig)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the key check to the limiter. no key? no acquire. over the limit? no acquire. maybe make the limiter a singleton injection at that point.

constructor(bot: Javabot, adminDao: AdminDao, var chatGPTDao: ChatGPTDao) :
BotOperation(bot, adminDao) {
override fun handleMessage(event: Message): List<Message> {
val responses = arrayListOf<Message>()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutableListOf() is more idiomatic, fwiw

val message = event.value
if (message.lowercase(Locale.getDefault()).startsWith("gpt ")) {
val uuid= UUID.randomUUID()
val query = message.substring("gpt ".length).trim()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.substringAfter("gpt ")

protected lateinit var config: JavabotConfig

@Test
fun testSwallow() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had to read the body of this message to reframe this method name in my head. :)

Copy link
Owner

@evanchooly evanchooly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is failing on formatting checks

@evanchooly evanchooly merged commit f5ab700 into master Feb 5, 2024
3 of 6 checks passed
evanchooly pushed a commit that referenced this pull request Dec 1, 2024
* Adding chatgpt library and access command

* Removing extraneous debug messages

* Adding rate limiting into the chatgpt operation

* Adding more explicit logging for chatgpt tests so they don't fail if the key isn't populated

* Fixing PR comments

* Changing ChatGPTDao to a singleton so the configuration and usage is cleaner

* Applying IDEA formatting for chatgpt operation

* spotless apply, such win

* I don't know what kotlin version isn't being used properly here but screw it, add is enough
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add chatgpt integration
2 participants