Skip to content

Commit 7239d03

Browse files
committed
interpreter --codestral
1 parent f1c3c03 commit 7239d03

File tree

3 files changed

+187
-41
lines changed

3 files changed

+187
-41
lines changed

interpreter/core/llm/utils/convert_to_openai_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def convert_to_openai_messages(
4343
] # This should never be `computer`, right?
4444

4545
if message["role"] == "user" and (
46-
message == messages[-1]
46+
message == [m for m in messages if m["role"] == "user"][-1]
4747
or interpreter.always_apply_user_message_template
4848
):
4949
# Only add the template for the last message?

interpreter/terminal_interface/profiles/defaults/codestral.py

Lines changed: 185 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
from interpreter import interpreter
44

5+
try:
6+
# List out all downloaded ollama models. Will fail if ollama isn't installed
7+
result = subprocess.run(
8+
["ollama", "list"], capture_output=True, text=True, check=True
9+
)
10+
lines = result.stdout.split("\n")
11+
names = [
12+
line.split()[0].replace(":latest", "") for line in lines[1:] if line.strip()
13+
] # Extract names, trim out ":latest", skip header
14+
15+
if "codestral" not in names:
16+
interpreter.display_message(f"\nDownloading codestral...\n")
17+
subprocess.run(["ollama", "pull", "codestral"], check=True)
18+
19+
# Set the model to codestral
20+
interpreter.llm.model = f"ollama/codestral"
21+
interpreter.display_message(f"> Model set to `codestral`")
22+
except:
23+
interpreter.display_message(
24+
f"> Ollama not found\n\nPlease download Ollama from [ollama.com](https://ollama.com/) to use `codestral`.\n"
25+
)
26+
exit()
27+
28+
529
# Set the system message to a minimal version for all local models.
630
interpreter.system_message = """
731
You are Open Interpreter, a world-class programmer that can execute code on the user's machine.
@@ -69,8 +93,7 @@
6993
interpreter.offline = True
7094

7195

72-
interpreter.system_message = """You are an AI assistant that returns code snippets that, if run, would answer the user's query. You speak very concisely and quickly, you say nothing irrelevant to the user's request. YOU NEVER USE PLACEHOLDERS, and instead always write code that 'just works' — for example, instead of a <username> placeholder, you put code that determines the user's username."
73-
# specialized in coding and automation, providing concise code snippets and friendly responses to enhance the user's productivity."""
96+
interpreter.system_message = """You are an AI assistant that returns code snippets that, if run, would answer the user's query. You speak very concisely and quickly, you say nothing irrelevant to the user's request. YOU NEVER USE PLACEHOLDERS, and instead always write code that 'just works' — for example, instead of a <username> placeholder, you put code that determines the user's username."""
7497

7598
interpreter.messages = [
7699
{
@@ -116,95 +139,218 @@
116139
]
117140

118141

142+
interpreter.messages = [
143+
{
144+
"role": "user",
145+
"type": "message",
146+
"content": "Hello! I'm trying to provide IT support to someone remotely. I can run code on their computer. Here's their first request: 'what's in my cwd?'",
147+
},
148+
{
149+
"role": "assistant",
150+
"type": "message",
151+
"content": "Absolutely, I can help with that. To get the contents of their current working directory (CWD), we'll use the `ls` command in a shell script like this:",
152+
},
153+
{"role": "assistant", "type": "code", "format": "shell", "content": "ls -la"},
154+
{
155+
"role": "computer",
156+
"type": "console",
157+
"format": "output",
158+
"content": "total 48\ndrwxr-xr-x 12 user staff 384 Jan 12 12:34 .\ndrwxr-xr-x 6 user staff 192 Jan 12 12:34 ..",
159+
},
160+
{
161+
"role": "assistant",
162+
"type": "message",
163+
"content": "Here's the directory listing:\n\ntotal 48\ndrwxr-xr-x 12 user staff 384 Jan 12 12:34 .\ndrwxr-xr-x 6 user staff 192 Jan 12 12:34 ..\n\nWhat's next on your agenda?",
164+
},
165+
{
166+
"role": "user",
167+
"type": "message",
168+
"content": "Can you multiply 2380 by 3875 for me?",
169+
},
170+
{"role": "assistant", "type": "code", "format": "python", "content": "2380*3875"},
171+
{"role": "computer", "type": "console", "format": "output", "content": "9222500"},
172+
{
173+
"role": "assistant",
174+
"type": "message",
175+
"content": "The multiplication of 2380 by 3875 gives you 9222500.",
176+
},
177+
{
178+
"role": "user",
179+
"type": "message",
180+
"content": """I just imported these functions: computer.view() — which will show me an image of what's on the user's screen (but only if it's ALONE in a codeblock, like the below)
181+
182+
```python
183+
computer.view()
184+
```
185+
186+
and I also imported computer.vision.query(path='path/to/image', query='describe this image.') which queries any image at path in natural language. Can you use these for requests in the future?""",
187+
},
188+
{
189+
"role": "assistant",
190+
"type": "message",
191+
"content": "Yes, I'll be sure to use the `computer.view` and `computer.vision.query` functions for any future requests you have that involve vision or viewing your screen.",
192+
},
193+
]
194+
195+
119196
interpreter.llm.supports_functions = False
120197

198+
interpreter.computer.import_computer_api = True
199+
interpreter.computer.system_message = ""
200+
121201
# interpreter.user_message_template = "{content} Please send me some code that would be able to answer my question, in the form of ```python\n... the code ...\n``` or ```shell\n... the code ...\n```"
122-
interpreter.code_output_template = '''I executed that code. This was the output: """{content}"""\n\nWhat does this output mean (I can't understand it, please help) / what code needs to be run next (if anything, or are we done)? I can't replace any placeholders.'''
202+
interpreter.code_output_template = '''I executed that code. This was the output: """{content}"""\n\nWhat does this output mean (I can't understand it, please help) / what code needs to be run next (if anything, or are we done)? I can't replace any placeholders— please send me code to determine usernames, paths, etc given the request. I'm lazy!'''
123203
interpreter.empty_code_output_template = "The code above was executed on my machine. It produced no text output. what's next (if anything, or are we done?)"
124204
interpreter.code_output_sender = "user"
125205
interpreter.max_output = 600
126206
interpreter.llm.context_window = 8000
127207
interpreter.force_task_completion = False
128-
interpreter.user_message_template = "{content}. If my question must be solved by running code on my computer, send me code to run enclosed in ```python (preferred) or ```shell (less preferred). Otherwise, don't send code. Be concise, don't include anything unnecessary. Don't use placeholders, I can't edit code."
208+
interpreter.user_message_template = "{content}. If my question must be solved by running code on my computer, send me code to run enclosed in ```python (preferred) or ```shell (less preferred). Otherwise, don't send code. Be concise, don't include anything unnecessary. Don't use placeholders, I can't edit code. Send code that will determine any placeholders (e.g. determine my username)."
129209
interpreter.user_message_template = "I'm trying to help someone use their computer. Here's the last thing they said: '{content}'. What is some code that might be able to answer that question / what should I say to them? DONT USE PLACEHOLDERS! It needs to just work."
130210
# interpreter.user_message_template = "{content}"
211+
interpreter.always_apply_user_message_template = False
131212
interpreter.llm.execution_instructions = False
132213
interpreter.auto_run = True
133214

134215
# Set offline for all local models
135216
interpreter.offline = True
136217

218+
import os
137219

138-
##### FOR LLAMA3
220+
# Get the current user's login name
221+
username = os.getlogin()
222+
# Determine the operating system
223+
operating_system = os.name
224+
# Find the current working directory
225+
cwd = os.getcwd()
139226

140-
interpreter.system_message = """You are an AI assistant specialized in coding and automation, providing concise code snippets and friendly responses to enhance the user's productivity."""
227+
228+
# OS MODE
141229

142230
interpreter.messages = [
143231
{
144232
"role": "user",
145233
"type": "message",
146-
"content": "Run a directory listing in the current folder.",
234+
"content": "I have someone remotely accessing my computer and they're asking to perform tasks. Can you help me provide support by writing some code?",
147235
},
148236
{
149237
"role": "assistant",
150238
"type": "message",
151-
"content": "Absolutely, fetching the directory listing now.",
239+
"content": "Absolutely, I can help with that.",
152240
},
153-
{"role": "assistant", "type": "code", "format": "shell", "content": "ls -la"},
154241
{
155-
"role": "computer",
156-
"type": "console",
157-
"format": "output",
158-
"content": "total 48\ndrwxr-xr-x 12 user staff 384 Jan 12 12:34 .\ndrwxr-xr-x 6 user staff 192 Jan 12 12:34 ..",
242+
"role": "user",
243+
"type": "message",
244+
"content": "Great, could you provide me with the code to find out the username, operating system, and current working directory on my computer?",
159245
},
160246
{
161247
"role": "assistant",
162248
"type": "message",
163-
"content": "Here's the directory listing:\n\ntotal 48\ndrwxr-xr-x 12 user staff 384 Jan 12 12:34 .\ndrwxr-xr-x 6 user staff 192 Jan 12 12:34 ..\n\nWhat's next on your agenda?",
249+
"content": "Sure, you can use the following Python script to retrieve the username, operating system, and current working directory of your computer:",
250+
},
251+
{
252+
"role": "assistant",
253+
"type": "code",
254+
"format": "python",
255+
"content": "import os\n# Get the current user's login name\nusername = os.getlogin()\n# Determine the operating system\noperating_system = os.name\n# Find the current working directory\ncwd = os.getcwd()\n# Print all the information\nprint(f'Username: {username}, OS: {operating_system}, Current Working Directory: {cwd}')",
164256
},
165257
{
166258
"role": "user",
167259
"type": "message",
168-
"content": "Can you multiply 2380 by 3875 for me?",
260+
"content": f"I've executed the script, and here's the output: 'Username: {username}, OS: {operating_system}, Current Working Directory: {cwd}'",
169261
},
170-
{"role": "assistant", "type": "code", "format": "python", "content": "2380*3875"},
171-
{"role": "computer", "type": "console", "format": "output", "content": "9222500"},
172262
{
173263
"role": "assistant",
174264
"type": "message",
175-
"content": "The multiplication of 2380 by 3875 gives you 9222500. Do you need this data for anything else?",
265+
"content": f"The output indicates that the username is '{username}', the operating system is {operating_system}, and the current working directory is '{cwd}'.",
266+
},
267+
{
268+
"role": "user",
269+
"type": "message",
270+
"content": "I just imported these functions: computer.view() — which will show me an image of what's on the user's screen when used alone in a code block, and computer.vision.query(path='path/to/image', query='describe this image.') which queries any image at path in natural language. Can you use these for requests in the future instead of like, pyautogui?",
271+
},
272+
{
273+
"role": "assistant",
274+
"type": "message",
275+
"content": "Yes, I can use those functions for future requests.",
276+
},
277+
{
278+
"role": "user",
279+
"type": "message",
280+
"content": "Okay, what's on my screen right now? I might ask this again later btw, and I'll need you to run it again if I do.",
281+
},
282+
{
283+
"role": "assistant",
284+
"type": "code",
285+
"format": "python",
286+
"content": "computer.view()",
176287
},
177288
{
178289
"role": "user",
179290
"type": "message",
180-
"content": "Great, I'll talk to you in an hour!",
291+
"content": "Okay, that returned this: 'There is a code editor on the screen, several open tabs, and a debugging console at the bottom.' What does this mean?",
181292
},
293+
{
294+
"role": "assistant",
295+
"type": "message",
296+
"content": "It looks like there's a code editor open on your screen with multiple tabs and a debugging console visible. This setup is typically used for software development or editing scripts. Can I help with anything else?",
297+
},
298+
{"role": "user", "type": "message", "content": "Nah. I'll talk to you in an hour!"},
182299
{
183300
"role": "assistant",
184301
"type": "message",
185302
"content": "Alright, I'll be here. Talk to you soon!",
186303
},
187304
]
188305

189-
try:
190-
# List out all downloaded ollama models. Will fail if ollama isn't installed
191-
result = subprocess.run(
192-
["ollama", "list"], capture_output=True, text=True, check=True
193-
)
194-
lines = result.stdout.split("\n")
195-
names = [
196-
line.split()[0].replace(":latest", "") for line in lines[1:] if line.strip()
197-
] # Extract names, trim out ":latest", skip header
306+
interpreter.system_message = "You are an AI assistant designed to help users with remote IT support tasks. If the user asks you to use functions, be biased towards using them if possible."
198307

199-
if "codestral" not in names:
200-
interpreter.display_message(f"\nDownloading codestral...\n")
201-
subprocess.run(["ollama", "pull", "codestral"], check=True)
202308

203-
# Set the model to codestral
204-
interpreter.llm.model = f"ollama/codestral"
205-
interpreter.display_message(f"> Model set to `codestral`")
206-
except:
207-
interpreter.display_message(
208-
f"> Ollama not found\n\nPlease download Ollama from [ollama.com](https://ollama.com/) to use `codestral`.\n"
209-
)
210-
exit()
309+
# STANDARD MODE
310+
311+
interpreter.messages = [
312+
{
313+
"role": "user",
314+
"type": "message",
315+
"content": "I have someone remotely accessing my computer and they're asking to perform tasks. Can you help me provide support by writing some code?",
316+
},
317+
{
318+
"role": "assistant",
319+
"type": "message",
320+
"content": "Absolutely, I can help with that.",
321+
},
322+
{
323+
"role": "user",
324+
"type": "message",
325+
"content": "Great, could you provide me with the code to find out the username, operating system, and current working directory on my computer?",
326+
},
327+
{
328+
"role": "assistant",
329+
"type": "message",
330+
"content": "Sure, you can use the following Python script to retrieve the username, operating system, and current working directory of your computer:",
331+
},
332+
{
333+
"role": "assistant",
334+
"type": "code",
335+
"format": "python",
336+
"content": "import os\n# Get the current user's login name\nusername = os.getlogin()\n# Determine the operating system\noperating_system = os.name\n# Find the current working directory\ncwd = os.getcwd()\n# Print all the information\nprint(f'Username: {username}, OS: {operating_system}, Current Working Directory: {cwd}')",
337+
},
338+
{
339+
"role": "user",
340+
"type": "message",
341+
"content": f"I've executed the script, and here's the output: 'Username: {username}, OS: {operating_system}, Current Working Directory: {cwd}'",
342+
},
343+
{
344+
"role": "assistant",
345+
"type": "message",
346+
"content": f"The output indicates that the username is '{username}', the operating system is {operating_system}, and the current working directory is '{cwd}'. Can I help with anything else?",
347+
},
348+
{"role": "user", "type": "message", "content": "Nah. I'll talk to you in an hour!"},
349+
{
350+
"role": "assistant",
351+
"type": "message",
352+
"content": "Alright, I'll be here. Talk to you soon!",
353+
},
354+
]
355+
356+
interpreter.system_message = """You are an AI assistant that writes working markdown code snippets to answer the user's request. You speak concisely and quickly. You say nothing irrelevant to the user's request. YOU NEVER USE PLACEHOLDERS, and instead always send code that 'just works' by figuring out placeholders dynamically. When you send code that fails, you identify the issue, then send new code that doesn't fail."""

interpreter/terminal_interface/start_terminal_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def main():
529529
print("Thank you for contributing!")
530530

531531
if (
532-
interpreter.contribute_conversation or interpreter.model == "i"
532+
interpreter.contribute_conversation or interpreter.llm.model == "i"
533533
) and interpreter.messages != []:
534534
conversation_id = (
535535
interpreter.conversation_id

0 commit comments

Comments
 (0)