Skip to content

Commit 03aa619

Browse files
committed
fix(server): fix setting initial working directory from workspace
- Change condition from "no user messages" to "one or fewer user messages" to be more precise about when workspace directory change is needed - Update debug message to reflect the new condition This ensures conversations start in the proper workspace directory.
1 parent c6cbc27 commit 03aa619

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

gptme/server/api_v2_sessions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ def step(
206206
config.chat = chat_config
207207
set_config(config)
208208

209-
# Initialize tools in this thread
210-
init_tools(chat_config.tools)
211-
212209
# Load .env file if present
213210
load_dotenv(dotenv_path=workspace / ".env")
214211

212+
# Initialize tools in this thread
213+
init_tools(chat_config.tools)
214+
215215
# Load conversation
216216
manager = LogManager.load(
217217
conversation_id,
@@ -222,13 +222,13 @@ def step(
222222
# TODO: This is not the best way to manage the chdir state, since it's
223223
# essentially a shared global across chats (bad), but the fix at least
224224
# addresses the issue where chats don't start in the directory they should.
225-
# If we are attempting to make a step in a conversation without any user
225+
# If we are attempting to make a step in a conversation with only one or fewer user
226226
# messages, make sure we first chdir to the workspace directory (so that
227227
# the conversation starts in the right folder).
228228
user_messages = [msg for msg in manager.log.messages if msg.role == "user"]
229-
if not user_messages:
229+
if len(user_messages) <= 1:
230230
logger.debug(
231-
f"No user messages found, changing directory to workspace: {workspace}"
231+
f"One or fewer user messages found, changing directory to workspace: {workspace}"
232232
)
233233
os.chdir(workspace)
234234

0 commit comments

Comments
 (0)