change signature
This commit is contained in:
21
nanocode.py
21
nanocode.py
@@ -163,6 +163,7 @@ def run_bash(cmd: str) -> str:
|
||||
output_lines.append("\n(timed out after 30s)")
|
||||
return "".join(output_lines).strip() or "(empty output)"
|
||||
|
||||
|
||||
class CodingAssistant(dspy.Signature):
|
||||
"""You are a concise coding assistant with access to sub agents."""
|
||||
|
||||
@@ -171,6 +172,7 @@ class CodingAssistant(dspy.Signature):
|
||||
desc="Your response to the user after completing the task"
|
||||
)
|
||||
|
||||
|
||||
class RLMCodingConfig(PrecompiledConfig):
|
||||
max_iters: int = 50
|
||||
lm: str = "openrouter/openai/gpt-5.2-codex"
|
||||
@@ -197,6 +199,7 @@ class RLMCodingProgram(PrecompiledProgram):
|
||||
"grep_files": grep_files,
|
||||
"run_bash": run_bash,
|
||||
}
|
||||
print("Config: ", self.config)
|
||||
|
||||
self.lm = dspy.LM(
|
||||
model=self.config.lm,
|
||||
@@ -204,13 +207,15 @@ class RLMCodingProgram(PrecompiledProgram):
|
||||
max_tokens=self.config.max_tokens,
|
||||
track_usage=self.config.track_usage,
|
||||
)
|
||||
print(f"{BLUE}NEW LM: {self.lm.model}{RESET}")
|
||||
self.sub_lm = dspy.LM(
|
||||
model=self.config.sub_lm,
|
||||
api_base=self.config.api_base,
|
||||
max_tokens=self.config.max_tokens,
|
||||
track_usage=self.config.track_usage,
|
||||
)
|
||||
agent = dspy.RLM(
|
||||
print(f"{BLUE}NEW SUB LM: {self.sub_lm.model}{RESET}")
|
||||
self.agent = dspy.RLM(
|
||||
CodingAssistant,
|
||||
sub_lm=self.sub_lm,
|
||||
tools=self.tools,
|
||||
@@ -218,12 +223,12 @@ class RLMCodingProgram(PrecompiledProgram):
|
||||
max_iterations=self.config.max_iters,
|
||||
verbose=self.config.verbose,
|
||||
)
|
||||
|
||||
agent.set_lm(self.lm)
|
||||
self.agent = agent
|
||||
self.agent.set_lm(self.lm)
|
||||
|
||||
def forward(self, task: str) -> str:
|
||||
assert task, "Task cannot be empty"
|
||||
if not task:
|
||||
return dspy.Prediction(answer="No Task Given.")
|
||||
|
||||
return self.agent(task=task)
|
||||
|
||||
def get_tools(self):
|
||||
@@ -231,14 +236,14 @@ class RLMCodingProgram(PrecompiledProgram):
|
||||
|
||||
def set_tool(self, name: str, tool: callable):
|
||||
self.tools[name] = tool
|
||||
self.reload_repl_tools()
|
||||
self.reload_repl()
|
||||
|
||||
def remove_tool(self, name: str):
|
||||
if name in self.tools:
|
||||
del self.tools[name]
|
||||
self.reload_repl_tools()
|
||||
self.reload_repl()
|
||||
|
||||
def reload_repl_tools(
|
||||
def reload_repl(
|
||||
self,
|
||||
): # we need to create a new instance for tool mutations to be passed back into the REPL
|
||||
new_instance = dspy.RLM(
|
||||
|
||||
Reference in New Issue
Block a user