Skip to content

Commit

Permalink
chore: Fix some code quality warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fmueller committed Nov 20, 2024
1 parent 37f93ee commit bf2c674
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/com/github/fmueller/jarvis/ai/OllamaService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ object OllamaService {
// TODO add something about selected code has higher priority than the open files or references
private val systemPrompt = """
You are Jarvis, an intelligent and helpful coding assistant on the level of an expert software developer. You assist users by providing code completions, debugging tips, explanations, and suggestions in various programming languages. Your responses are clear, concise, and directly address the user's needs.
All your responses should be formatted in Markdown. To improve readability, use paragraphs, lists, and headlines where appropriate.
- Follow coding best practices for readability, efficiency, and security.
- Use appropriate code blocks with syntax highlighting.
- Include comments and brief explanations where necessary.
Expand Down Expand Up @@ -134,7 +134,7 @@ object OllamaService {
// TODO check if model is available
// TODO if not, download model

var nextMessagePrompt =
val nextMessagePrompt =
if (conversation.getLastUserMessage() != null) {
val lastUserMessage = conversation.getLastUserMessage()!!
"""
Expand All @@ -144,7 +144,7 @@ object OllamaService {
|
|[Code Context]:
|
|${getCodeContextPrompt(lastUserMessage.codeContext, useCodeContext)}
|${getCodeContextPrompt(lastUserMessage.codeContext, !lastUserMessage.isHelpMessage() && useCodeContext)}
|
|[Assistant]: """.trimMargin()
} else {
Expand All @@ -153,7 +153,7 @@ object OllamaService {

val responseInFlight = StringBuilder()
try {
suspendCancellableCoroutine<String> { continuation ->
suspendCancellableCoroutine { continuation ->
assistant
.chat(nextMessagePrompt)
.onNext { update ->
Expand Down
14 changes: 13 additions & 1 deletion src/main/kotlin/com/github/fmueller/jarvis/ai/SimpleTokenizer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.github.fmueller.jarvis.ai

import dev.langchain4j.agent.tool.ToolExecutionRequest
import dev.langchain4j.agent.tool.ToolSpecification
import dev.langchain4j.data.message.AiMessage
import dev.langchain4j.data.message.ChatMessage
import dev.langchain4j.data.message.SystemMessage
import dev.langchain4j.data.message.UserMessage
import dev.langchain4j.model.Tokenizer
import kotlin.math.roundToInt

Expand All @@ -16,7 +19,16 @@ class SimpleTokenizer : Tokenizer {
}

override fun estimateTokenCountInMessage(message: ChatMessage?): Int {
return estimateTokenCountInText(message?.text() ?: "") + 2
return estimateTokenCountInText(getText(message)) + 2
}

private fun getText(message: ChatMessage?): String {
return when (message) {
is AiMessage -> message.text()

Check failure on line 27 in src/main/kotlin/com/github/fmueller/jarvis/ai/SimpleTokenizer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'text()' is deprecated and marked for removal
is SystemMessage -> message.text()

Check failure on line 28 in src/main/kotlin/com/github/fmueller/jarvis/ai/SimpleTokenizer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'text()' is deprecated and marked for removal
is UserMessage -> if (message.hasSingleText()) message.singleText() else ""
else -> ""
}
}

override fun estimateTokenCountInMessages(messages: Iterable<ChatMessage?>?): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.intellij.psi.PsiManager

object CodeContextHelper {

fun getCodeContext(project: Project): CodeContext? {
fun getCodeContext(project: Project): CodeContext {
val editor = FileEditorManager.getInstance(project).selectedTextEditor
if (editor != null) {
val selection = editor.selectionModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.fmueller.jarvis.conversation;
package com.github.fmueller.jarvis.conversation

import com.github.fmueller.jarvis.ui.SyntaxHighlightedCodeHelper
import com.intellij.openapi.Disposable
Expand Down

0 comments on commit bf2c674

Please sign in to comment.