Skip to content

Commit 983a5eb

Browse files
committed
fix style error
1 parent cccf633 commit 983a5eb

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

devchat/engine/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
from .namespace import Namespace
33
from .recursive_prompter import RecursivePrompter
44
from .router import run_command
5-
from .command_runner import CommandRunner
65

76
__all__ = [
87
'parse_command',
98
'Command',
109
'CommandParser',
1110
'Namespace',
1211
'RecursivePrompter',
13-
'run_command',
14-
'CommandRunner'
12+
'run_command'
1513
]

devchat/engine/command_runner.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import openai
1212

1313
from devchat.utils import get_logger
14-
from . import Command
14+
from .command_parser import Command
1515

1616

1717
logger = get_logger(__name__)
@@ -158,24 +158,25 @@ def run_command_with_parameters(self,
158158
del env['PYTHONPATH']
159159
# result = subprocess.run(command_run, shell=True, env=env)
160160
# return result
161-
process = subprocess.Popen(
162-
shlex.split(command_run),
163-
stdout=subprocess.PIPE,
164-
stderr=subprocess.STDOUT,
165-
text=True
166-
)
167-
168-
# 实时读取输出并打印
169-
stdout = ''
170-
while True:
171-
output = process.stdout.readline()
172-
if output == '' and process.poll() is not None:
173-
break
174-
if output:
175-
stdout += output
176-
print(output, end='\n')
177-
rc = process.poll()
178-
return (rc, stdout)
161+
with subprocess.Popen(
162+
shlex.split(command_run),
163+
stdin=subprocess.PIPE,
164+
stdout=subprocess.PIPE,
165+
stderr=subprocess.STDOUT,
166+
env=env,
167+
text=True
168+
) as process:
169+
stdout = ''
170+
while True:
171+
output = process.stdout.readline()
172+
if output == '' and process.poll() is not None:
173+
break
174+
if output:
175+
stdout += output
176+
print(output, end='\n')
177+
exit_code = process.poll()
178+
return (exit_code, stdout)
179+
return (-1, "")
179180
except Exception as err:
180181
print("Exception:", type(err), err, file=sys.stderr, flush=True)
181182
return (-1, "")

devchat/engine/router.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import json
3-
from typing import List
3+
from typing import List, Iterable
44
import openai
55
from devchat._cli.utils import init_dir
6-
from . import Namespace, CommandParser, Command
6+
from .namespace import Namespace
7+
from .command_parser import CommandParser, Command
78
from .command_runner import CommandRunner
89

910

@@ -95,15 +96,15 @@ def _call_gpt(messages: List[dict], # messages passed to GPT
9596

9697
for try_times in range(3):
9798
try:
98-
response = client.chat.completions.create(
99+
response: Iterable = client.chat.completions.create(
99100
messages=messages,
100101
model=model_name,
101102
stream=True,
102103
tools=tools
103104
)
104105

105106
response_result = {'content': None, 'function_name': None, 'parameters': ""}
106-
for chunk in response:
107+
for chunk in response: # pylint: disable=E1133
107108
chunk = chunk.dict()
108109
delta = chunk["choices"][0]["delta"]
109110
if 'tool_calls' in delta and delta['tool_calls']:
@@ -135,6 +136,7 @@ def _call_gpt(messages: List[dict], # messages passed to GPT
135136
except Exception as err:
136137
print("Exception Error:", err)
137138
return {'content': None, 'function_name': None, 'parameters': ""}
139+
return {'content': None, 'function_name': None, 'parameters': ""}
138140

139141

140142
def _create_messages():
@@ -193,7 +195,7 @@ def _auto_route(history_messages, model_name:str):
193195
response['function_name'],
194196
response['parameters'],
195197
model_name)
196-
elif not response['content']:
198+
if not response['content']:
197199
return (-1, "")
198200
return (-1, "")
199201

@@ -218,19 +220,18 @@ def run_command(
218220
# response = _auto_function_calling(history_messages, model_name)
219221
# return response['content']
220222
return _auto_route(history_messages, model_name)
221-
else:
222-
commands = input_text.split()
223-
command = commands[0][1:]
223+
commands = input_text.split()
224+
command = commands[0][1:]
224225

225-
command_obj = _load_command(command)
226-
if not command_obj or not command_obj.steps:
227-
return None
226+
command_obj = _load_command(command)
227+
if not command_obj or not command_obj.steps:
228+
return None
228229

229-
runner = CommandRunner(model_name)
230-
return runner.run_command(
231-
command,
232-
command_obj,
233-
history_messages,
234-
input_text,
235-
parent_hash,
236-
context_contents)
230+
runner = CommandRunner(model_name)
231+
return runner.run_command(
232+
command,
233+
command_obj,
234+
history_messages,
235+
input_text,
236+
parent_hash,
237+
context_contents)

0 commit comments

Comments
 (0)