Skip to content

Commit

Permalink
Initial stuff
Browse files Browse the repository at this point in the history
Signed-off-by: JonahSussman <sussmanjonah@gmail.com>
  • Loading branch information
JonahSussman committed Feb 12, 2025
1 parent 41b33f2 commit 5878296
Show file tree
Hide file tree
Showing 15 changed files with 424 additions and 117 deletions.
85 changes: 65 additions & 20 deletions .trunk/configs/custom-words.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,78 @@
abcdf
analyzerfix
apiextensions
apimachinery
ASGI
bombsimon
caikit
cbroglie
celerybeat
cenkalti
codeplan
codeplanner
codesnip
condctx
conds
Connor
contextvar
coolstore
coolstuff
customise
customresourcedefinitions
Cython
databind
deepseek
diffable
djzager
dmypy
dotenv
emptypb
entitymanager
fabianvf
fasterxml
felixge
filebool
filecontent
fileglob
flywaydb
frobinate
genai
genproto
gomod
gopls
gpgsign
htmlcov
httpserver
httpsnoop
Idxs
imgui
initialcontextfactory
ipath
ipynb
ipython
jakartaee
javaee
javaoperatorsdk
javax
jaxrs
jdbc
jdtls
jndi
jsonschema
kantra
konv
konveyor
langchain
levelname
libgrpc
llm
llms
logback
LOGLEVEL
logr
logrus
logrusr
lowerbound
microprofile
mistralai
mixtral
Expand All @@ -46,19 +82,32 @@ mypy
mypyc
nbdev
nosetests
notadded
OBJC
ojdbc
Ollama
ordermanagement
otelhttp
otelslog
otlptrace
otlptracehttp
pgaikwad
picketlink
pipenv
Pipfile
pomxml
prio
protoc
protoimpl
protoreflect
provs
pybuilder
pycache
pydantic
pyenv
pyflow
pyinstaller
pylsp
pylspclient
pypa
pypackages
Expand All @@ -70,35 +119,31 @@ resteasy
ropeproject
Scrapy
sdist
semconv
sessionbean
shurley
sirupsen
smallrye
springboot
springframework
Spyder
spyderproject
spyproject
Startable
stdoutlog
stdoutmetric
stdouttrace
structpb
supertypes
sussman
swaggest
templ
testnested
textmap
tgis
tiiuae
tracesdk
upperbound
venv
webassets
webmvc
prio
analyzerfix
fabianvf
genproto
otlptrace
otlptracehttp
logr
condctx
shurley
semconv
textmap
otelslog
otlptracehttp
otelhttp
stdoutlog
stdoutmetric
stdouttrace
httpsnoop
felixge
cenkalti
4 changes: 3 additions & 1 deletion kai/jsonrpc/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def __call__(

log.log(TRACE, f"Calling function: {self.func.__name__}")
self.func(app, server, request.id, validated_params)
except Exception:
except Exception as e:
log.error(f"Error calling {self.func.__name__}: {e}")

server.send_response(
id=request.id,
error=JsonRpcError(
Expand Down
5 changes: 5 additions & 0 deletions kai/jsonrpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class JsonRpcApplication:
Taking a page out of the ASGI standards, JsonRpcApplication is a collection
of JsonRpcCallbacks that can be used to handle incoming requests and
notifications.
Exceptions raised within a call back are handled in JsonRpcCallback.
NOTE(JonahSussman): We should investigate potentially moving the handling
here to make it more clear.
"""

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion kai/llm_interfacing/model_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def challenge(k: str) -> BaseMessage:
return self.invoke("", cpr, configurable_fields={k: 1})

if isinstance(self.llm, ChatOllama):
challenge("max_tokens")
challenge("num_predict")
elif isinstance(self.llm, ChatOpenAI):
challenge("max_tokens")
elif isinstance(self.llm, ChatBedrock):
Expand Down
12 changes: 12 additions & 0 deletions kai/reactive_codeplanner/agent/analyzer_fix/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
AnalyzerFixResponse,
)
from kai.reactive_codeplanner.agent.api import Agent, AgentRequest
from kai.rpc_server.chat import get_chatter_contextvar

logger = get_logger(__name__)
chatter = get_chatter_contextvar()


@dataclass
Expand Down Expand Up @@ -103,6 +105,7 @@ def __init__(
self._retries = retries

def execute(self, ask: AgentRequest) -> AnalyzerFixResponse:
chatter.get().chat_simple("AnalyzerAgent executing...")

if not isinstance(ask, AnalyzerFixRequest):
return AnalyzerFixResponse(
Expand Down Expand Up @@ -139,12 +142,21 @@ def execute(self, ask: AgentRequest) -> AnalyzerFixResponse:
incidents=ask.incidents,
)

chatter.get().chat_simple("Waiting for response from LLM...")

ai_message = self._model_provider.invoke(
[system_message, HumanMessage(content=content)],
ask.cache_path_resolver,
)

resp = self.parse_llm_response(ai_message)

msg = "Received response from LLM\n"
msg += f"File to modify: {ask.file_path}\n"
msg += f"<details><summary>Reasoning</summary>\n{resp.reasoning}\n</details>\n"
msg += f"<details><summary>Additional Information</summary>\n{resp.additional_information}\n</details>\n"
chatter.get().chat_markdown(msg)

return AnalyzerFixResponse(
encountered_errors=[],
file_to_modify=Path(os.path.abspath(ask.file_path)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
find_in_pom,
search_fqdn,
)
from kai.rpc_server.chat import get_chatter_contextvar

logger = get_logger(__name__)
chatter = get_chatter_contextvar()


@dataclass
Expand Down Expand Up @@ -183,6 +185,8 @@ def __init__(
self.agent_methods.update({"find_in_pom._run": find_in_pom(project_base)})

def execute(self, ask: AgentRequest) -> AgentResult:
chatter.get().chat_simple("MavenDependencyAgent executing...")

if not isinstance(ask, MavenDependencyRequest):
return AgentResult()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
get_maven_query_from_code,
search_fqdn_query,
)
from kai.rpc_server.chat import get_chatter_contextvar

logger = get_logger(__name__)
chatter = get_chatter_contextvar()


@dataclass
Expand Down Expand Up @@ -66,6 +68,8 @@ def __init__(self, model_provider: ModelProvider) -> None:
)

def execute(self, ask: AgentRequest) -> FQDNDependencySelectorResult:
chatter.get().chat_simple("FQDNDependencySelectorAgent executing...")

if not isinstance(ask, FQDNDependencySelectorRequest):
return FQDNDependencySelectorResult(
encountered_errors=None, file_to_modify=None, response=None
Expand Down
12 changes: 12 additions & 0 deletions kai/reactive_codeplanner/agent/maven_compiler_fix/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
MavenCompilerAgentRequest,
MavenCompilerAgentResult,
)
from kai.rpc_server.chat import get_chatter_contextvar

logger = get_logger(__name__)
chatter = get_chatter_contextvar()


class MavenCompilerAgent(Agent):
Expand Down Expand Up @@ -55,6 +57,7 @@ def __init__(self, model_provider: ModelProvider):
self.model_provider = model_provider

def execute(self, ask: AgentRequest) -> AgentResult:
chatter.get().chat_simple("MavenCompilerAgent executing...")

if not isinstance(ask, MavenCompilerAgentRequest):
return AgentResult()
Expand All @@ -76,6 +79,8 @@ def execute(self, ask: AgentRequest) -> AgentResult:
src_file_contents=ask.file_contents, compile_errors=compile_errors
)

chatter.get().chat_simple("Waiting for response from LLM...")

ai_message = self.model_provider.invoke(
[system_message, HumanMessage(content=content)],
ask.cache_path_resolver,
Expand All @@ -86,6 +91,13 @@ def execute(self, ask: AgentRequest) -> AgentResult:
resp.file_to_modify = ask.file_path
resp.message = ask.message
resp.original_file = ask.file_contents

msg = "Received response from LLM\n"
msg += f"File to modify: {ask.file_path}\n"
msg += f"<details><summary>Reasoning</summary>\n{resp.reasoning}\n</details>\n"
msg += f"<details><summary>Additional Information</summary>\n{resp.additional_information}\n</details>\n"
chatter.get().chat_markdown(msg)

return resp

def parse_llm_response(self, message: BaseMessage) -> MavenCompilerAgentResult:
Expand Down
6 changes: 6 additions & 0 deletions kai/reactive_codeplanner/agent/reflection_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
from kai.logging.logging import TRACE, get_logger
from kai.reactive_codeplanner.agent.api import Agent, AgentRequest, AgentResult
from kai.reactive_codeplanner.agent.ast_diff.parser import Language, extract_ast_info
from kai.rpc_server.chat import get_chatter_contextvar

logger = get_logger(__name__)
chatter = get_chatter_contextvar()


@dataclass
Expand Down Expand Up @@ -306,6 +308,8 @@ def __init__(
self._retries = retries

def execute(self, task: AgentRequest) -> AgentResult:
chatter.get().chat_simple("ReflectionAgent executing...")

if not isinstance(task, ReflectionTask):
return AgentResult()

Expand Down Expand Up @@ -381,6 +385,8 @@ def execute(self, task: AgentRequest) -> AgentResult:
while curr_iter < self._iterations:
curr_iter += 1
try:
chatter.get().chat_simple(f"Reflection iteration {curr_iter}")

reflection_response = self._model_provider.invoke(
chat_reflect,
task.cache_path_resolver,
Expand Down
Loading

0 comments on commit 5878296

Please sign in to comment.