Skip to content

Commit

Permalink
use union
Browse files Browse the repository at this point in the history
  • Loading branch information
mbektas committed Jan 5, 2025
1 parent 8ea2c16 commit d8457b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions notebook_intelligence/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from os import path
import os
import sys
from typing import Callable, Dict
from typing import Callable, Dict, Union
from dataclasses import dataclass
from enum import Enum

Expand Down Expand Up @@ -239,7 +239,7 @@ def description(self) -> str:
def schema(self) -> dict:
raise NotImplemented

def pre_invoke(self, request: ChatRequest, tool_args: dict) -> ToolPreInvokeResponse | None:
def pre_invoke(self, request: ChatRequest, tool_args: dict) -> Union[ToolPreInvokeResponse, None]:
return None

async def handle_tool_call(self, request: ChatRequest, response: ChatResponse, tool_context: dict, tool_args: dict) -> dict:
Expand Down
3 changes: 2 additions & 1 deletion notebook_intelligence/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from os import path
import os
import sys
from typing import Union
import uuid

from jupyter_server.base.handlers import APIHandler
Expand Down Expand Up @@ -125,7 +126,7 @@ def chat_id(self) -> str:
def message_id(self) -> str:
return self.messageId

def stream(self, data: ResponseStreamData | dict):
def stream(self, data: Union[ResponseStreamData | dict]):
data_type = ResponseStreamDataType.LLMRaw if type(data) is dict else data.data_type

if data_type == ResponseStreamDataType.Markdown:
Expand Down
5 changes: 3 additions & 2 deletions notebook_intelligence/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from time import sleep
from typing import Union

from .extension import AnchorData, ButtonData, ChatCommand, CompletionContext, CompletionContextProvider, ContextItem, HTMLData, MarkdownData, NotebookIntelligenceExtension, Host, ChatParticipant, ChatRequest, ChatResponse, ProgressData, ResponseStreamDataType, Tool, ToolPreInvokeResponse, ContextRequest

Expand Down Expand Up @@ -89,7 +90,7 @@ def schema(self) -> dict:
},
}

def pre_invoke(self, request: ChatRequest, tool_args: dict) -> ToolPreInvokeResponse | None:
def pre_invoke(self, request: ChatRequest, tool_args: dict) -> Union[ToolPreInvokeResponse, None]:
return ToolPreInvokeResponse(
message="Converting fahrenheit to celcius",
confirmationTitle="Confirm conversion",
Expand Down Expand Up @@ -138,7 +139,7 @@ def schema(self) -> dict:
},
}

def pre_invoke(self, request: ChatRequest, tool_args: dict) -> ToolPreInvokeResponse | None:
def pre_invoke(self, request: ChatRequest, tool_args: dict) -> Union[ToolPreInvokeResponse, None]:
return ToolPreInvokeResponse(
message="Converting celcius to kelvin",
# confirmationTitle="Confirm",
Expand Down

0 comments on commit d8457b5

Please sign in to comment.