-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp_me_cli.py
More file actions
49 lines (40 loc) · 1.39 KB
/
Copy pathhelp_me_cli.py
File metadata and controls
49 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import openai
import asyncio
import time
import sys
OPENAI_ENGINE = 'gpt-4o-mini'
# Editable prompt to fine-tune OpenAI's response
UNIX_HELP_PROMPT = """
You are an AI assistant that helps users with UNIX shell commands.
Given a human-written description of a UNIX terminal task, generate:
1. A brief, concise comment summarizing the task.
2. The corresponding shell command to accomplish the task.
Format your response strictly as:
# <brief comment>
<shell command>
Ensure the shell command is:
- Efficient and idiomatic
- Safe to run in a standard UNIX environment
- Uses commonly available UNIX tools
Do NOT provide explanations, just output the comment and command.
"""
async def get_unix_help(task_description: str):
command_history = ""
try:
client = openai.AsyncOpenAI()
response = await client.chat.completions.create(
model=OPENAI_ENGINE,
messages=[
{"role": "system", "content": UNIX_HELP_PROMPT},
{"role": "user", "content": task_description},
]
)
print(response.choices[0].message.content.strip())
except Exception as e:
print(f'error: {e}')
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python help_me_cli.py \"<description of UNIX task>\"")
sys.exit(1)
task_description = sys.argv[1]
asyncio.run(get_unix_help(task_description))