Skip to content

Commit 29974aa

Browse files
committed
Fix creating new kernels
1 parent c663051 commit 29974aa

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

js/src/code-interpreter.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ export class JupyterExtension {
145145
cwd: string = '/home/user',
146146
kernelName?: string
147147
): Promise<string> {
148-
const data = { path: cwd, kernel: {name: "python3"}, type: "notebook", name: id(16) }
149-
if (kernelName) {
150-
data.kernel.name = kernelName
151-
}
148+
kernelName = kernelName || 'python3'
149+
150+
151+
const data = { path: id(16), kernel: {name: kernelName}, type: "notebook", name: id(16) }
152152

153153
const response = await fetch(
154154
`${this.sandbox.getProtocol()}://${this.sandbox.getHostname(
@@ -164,9 +164,27 @@ export class JupyterExtension {
164164
throw new Error(`Failed to create kernel: ${response.statusText}`)
165165
}
166166

167+
167168
const sessionInfo = await response.json()
168169
const kernelID = sessionInfo.kernel.id
169-
await this.connectToKernelWS(kernelID, sessionInfo.id)
170+
const sessionID = sessionInfo.id
171+
172+
const patchResponse = await fetch(
173+
`${this.sandbox.getProtocol()}://${this.sandbox.getHostname(
174+
8888
175+
)}/api/sessions/${sessionID}`,
176+
{
177+
method: 'PATCH',
178+
body: JSON.stringify({path: cwd})
179+
}
180+
)
181+
182+
if (!patchResponse.ok) {
183+
throw new Error(`Failed to create kernel: ${response.statusText}`)
184+
}
185+
186+
187+
await this.connectToKernelWS(kernelID, sessionID)
170188

171189
return kernelID
172190
}

python/e2b_code_interpreter/main.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,8 @@ def create_kernel(
142142
:return: Kernel id of the created kernel
143143
"""
144144
kernel_name = kernel_name or "python3"
145-
response = requests.post(
146-
f"{self._sandbox.get_protocol()}://{self._sandbox.get_hostname(8888)}/api/kernels",
147-
json={"name": kernel_name, "path": cwd},
148-
timeout=timeout,
149-
)
150-
if not response.ok:
151-
raise KernelException(f"Failed to create kernel: {response.text}")
152145

153-
kernel_data = response.json()
154-
kernel_id = kernel_data["id"]
155-
data = {"path": str(uuid.uuid4()), "kernel": {"name": kernel_name, "id": kernel_id}, "type": "notebook", "name": str(uuid.uuid4())}
146+
data = {"path": str(uuid.uuid4()), "kernel": {"name": kernel_name}, "type": "notebook", "name": str(uuid.uuid4())}
156147
logger.debug(f"Creating kernel with data: {data}")
157148

158149
response = requests.post(

0 commit comments

Comments
 (0)