Skip to content

Commit 194772a

Browse files
committed
Max turns
1 parent 6a7ee0c commit 194772a

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

interpreter_1/cli.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ def _profile_to_arg_params(profile: Profile) -> Dict[str, Dict[str, Any]]:
8989
"default": profile.instructions,
9090
"help": "Appended to default system message",
9191
},
92-
"max_budget": {
93-
"flags": ["--max-budget"],
94-
"type": float,
95-
"default": profile.max_budget,
96-
"help": f"Set maximum budget, defaults to -1 (unlimited)",
92+
"input": {
93+
"flags": ["--input"],
94+
"default": profile.input,
95+
"help": "Set initial input message",
9796
},
9897
"max_turns": {
9998
"flags": ["--max-turns"],
@@ -126,7 +125,6 @@ def parse_args():
126125

127126
# Hidden arguments
128127
parser.add_argument("--help", "-h", action="store_true", help=argparse.SUPPRESS)
129-
parser.add_argument("--input-message", help=argparse.SUPPRESS)
130128

131129
# Add arguments programmatically from config
132130
arg_params = _profile_to_arg_params(profile)
@@ -198,7 +196,7 @@ async def async_load():
198196
sys.stdout.write("\r\033[K") # Clear entire line
199197
sys.stdout.flush()
200198

201-
if args["input_message"] is None and sys.stdin.isatty():
199+
if args["input"] is None and sys.stdin.isatty():
202200
from .misc.welcome import welcome_message
203201

204202
welcome_message(args)
@@ -210,8 +208,8 @@ async def async_load():
210208
spinner.start()
211209
load_interpreter()
212210
spinner.stop()
213-
if args["input_message"]:
214-
message = args["input_message"]
211+
if args["input"]:
212+
message = args["input"]
215213
else:
216214
message = sys.stdin.read().strip()
217215
# print("---")

interpreter_1/interpreter.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ class Interpreter:
129129
API key being used
130130
api_version : str or None
131131
API version being used
132-
max_budget : float
133-
Maximum budget in USD (-1 for unlimited)
134132
max_turns : int
135133
Maximum conversation turns (-1 for unlimited)
136134
"""
@@ -207,6 +205,7 @@ async def async_respond(self):
207205
model_info = litellm.get_model_info(self.model)
208206
if self.provider == None:
209207
self.provider = model_info["litellm_provider"]
208+
210209
max_tokens = model_info["max_tokens"]
211210

212211
system_message = self.system_message + "\n\n" + self.instructions
@@ -217,7 +216,15 @@ async def async_respond(self):
217216
text=system_message,
218217
)
219218

219+
# Count turns
220+
turn_count = 0
221+
220222
while True:
223+
turn_count += 1
224+
if turn_count > self.max_turns and self.max_turns != -1:
225+
print("\nMax turns reached, exiting\n")
226+
break
227+
221228
self._spinner.start()
222229

223230
enable_prompt_caching = False
@@ -469,10 +476,10 @@ async def async_respond(self):
469476
}
470477
)
471478
if "editor" in self.tools:
472-
# print("Editor is not supported for non-Anthropic models.")
479+
print("\nEditor is not supported for non-Anthropic models yet.\n")
473480
pass
474481
if "gui" in self.tools:
475-
# print("GUI is not supported for non-Anthropic models.")
482+
print("\nGUI is not supported for non-Anthropic models yet.\n")
476483
pass
477484

478485
if self.model.startswith("ollama/"):
@@ -629,7 +636,6 @@ def _handle_command(self, cmd: str, parts: list[str]) -> bool:
629636
"api_key": (str, "API key"),
630637
"api_version": (str, "API version"),
631638
"temperature": (float, "Sampling temperature (0-1)"),
632-
"max_budget": (float, "Maximum budget in USD (-1 for unlimited)"),
633639
"max_turns": (int, "Maximum conversation turns (-1 for unlimited)"),
634640
}
635641

@@ -799,29 +805,32 @@ def chat(self):
799805
placeholder = HTML(
800806
f"<{placeholder_color}>{placeholder_text}</{placeholder_color}>"
801807
)
802-
if self._prompt_session is None:
803-
self._prompt_session = PromptSession()
804-
user_input = self._prompt_session.prompt(
805-
"> ", placeholder=placeholder
806-
).strip()
807-
print()
808-
809-
# Handle multi-line input
810-
if user_input == '"""':
811-
user_input = ""
812-
print('> """')
813-
while True:
814-
placeholder = HTML(
815-
f'<{placeholder_color}>Use """ again to finish</{placeholder_color}>'
816-
)
817-
line = self._prompt_session.prompt(
818-
"", placeholder=placeholder
819-
).strip()
820-
if line == '"""':
821-
break
822-
user_input += line + "\n"
808+
if self.input:
809+
user_input = self.input
810+
else:
811+
if self._prompt_session is None:
812+
self._prompt_session = PromptSession()
813+
user_input = self._prompt_session.prompt(
814+
"> ", placeholder=placeholder
815+
).strip()
823816
print()
824817

818+
# Handle multi-line input
819+
if user_input == '"""':
820+
user_input = ""
821+
print('> """')
822+
while True:
823+
placeholder = HTML(
824+
f'<{placeholder_color}>Use """ again to finish</{placeholder_color}>'
825+
)
826+
line = self._prompt_session.prompt(
827+
"", placeholder=placeholder
828+
).strip()
829+
if line == '"""':
830+
break
831+
user_input += line + "\n"
832+
print()
833+
825834
message_count += 1 # Increment counter after each message
826835

827836
if user_input.startswith("/"):

interpreter_1/profiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ def __init__(self):
5757
self.api_version = None # API version to use
5858

5959
# Runtime limits
60-
self.max_budget = -1 # Maximum budget in USD (-1 for unlimited)
6160
self.max_turns = -1 # Maximum conversation turns (-1 for unlimited)
6261

6362
# Conversation state
6463
self.messages = [] # List of conversation messages
6564
self.system_message = SYSTEM_PROMPT # System prompt override
6665
self.instructions = "" # Additional model instructions
66+
self.input = None # Input message override
6767

6868
# Available tools and settings
6969
self.tools = ["interpreter", "editor"] # Enabled tool modules

0 commit comments

Comments
 (0)