Skip to content

Commit

Permalink
Format all code using ruff.
Browse files Browse the repository at this point in the history
  • Loading branch information
dokterbob committed Nov 19, 2024
1 parent 59ca064 commit 205a950
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 26 deletions.
5 changes: 2 additions & 3 deletions backend/chainlit/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ def create_jwt(data: User) -> str:
to_encode: Dict[str, Any] = data.to_dict()
to_encode.update(
{
"exp": datetime.utcnow() + timedelta(
seconds=config.project.user_session_timeout
),
"exp": datetime.utcnow()
+ timedelta(seconds=config.project.user_session_timeout),
}
)
encoded_jwt = jwt.encode(to_encode, get_jwt_secret(), algorithm="HS256")
Expand Down
4 changes: 2 additions & 2 deletions backend/chainlit/chat_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def add(self, message: "Message"):

if context.session.id not in chat_contexts:
chat_contexts[context.session.id] = []

if message not in chat_contexts[context.session.id]:
chat_contexts[context.session.id].append(message)

return message

def remove(self, message: "Message") -> bool:
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/data/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def is_thread_author(username: str, thread_id: str):
raise HTTPException(status_code=400, detail="Data layer not initialized")

thread_author = await data_layer.get_thread_author(thread_id)

if not thread_author:
raise HTTPException(status_code=404, detail="Thread not found")

Expand Down
8 changes: 4 additions & 4 deletions backend/chainlit/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ async def resume_thread(self, thread_dict: ThreadDict):
async def send_element(self, element_dict: ElementDict):
"""Stub method to send an element to the UI."""
pass

async def update_audio_connection(self, state: Literal["on", "off"]):
"""Audio connection signaling."""
pass

async def send_audio_chunk(self, chunk: OutputAudioChunk):
"""Stub method to send an audio chunk to the UI."""
pass

async def send_audio_interrupt(self):
"""Stub method to interrupt the current audio response."""
pass
Expand Down Expand Up @@ -178,7 +178,7 @@ async def update_audio_connection(self, state: Literal["on", "off"]):
async def send_audio_chunk(self, chunk: OutputAudioChunk):
"""Send an audio chunk to the UI."""
await self.emit("audio_chunk", chunk)

async def send_audio_interrupt(self):
"""Method to interrupt the current audio response."""
await self.emit("audio_interrupt", {})
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/haystack/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def on_tool_finish(
tool_result: str,
tool_name: Optional[str] = None,
tool_input: Optional[str] = None,
**kwargs: Any
**kwargs: Any,
) -> None:
# Tool finished, send step with tool_result
tool_step = self.stack.pop()
Expand Down
7 changes: 3 additions & 4 deletions backend/chainlit/llama_index/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,15 @@ def on_event_end(
context_var.get().loop.create_task(step.update())

elif event_type == CBEventType.LLM:
formatted_messages = payload.get(
EventPayload.MESSAGES
) # type: Optional[List[ChatMessage]]
formatted_messages = payload.get(EventPayload.MESSAGES) # type: Optional[List[ChatMessage]]
formatted_prompt = payload.get(EventPayload.PROMPT)
response = payload.get(EventPayload.RESPONSE)

if formatted_messages:
messages = [
GenerationMessage(
role=m.role.value, content=m.content or "" # type: ignore
role=m.role.value, # type: ignore
content=m.content or "",
)
for m in formatted_messages
]
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ async def get_file(
detail="Unauthorized",
)

#TODO: Causes 401 error. See https://github.com/Chainlit/chainlit/issues/1472
# TODO: Causes 401 error. See https://github.com/Chainlit/chainlit/issues/1472
# if current_user:
# if not session.user or session.user.identifier != current_user.identifier:
# raise HTTPException(
Expand Down
7 changes: 4 additions & 3 deletions backend/chainlit/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ async def persist_file(

if path:
# Copy the file from the given path
async with aiofiles.open(path, "rb") as src, aiofiles.open(
file_path, "wb"
) as dst:
async with (
aiofiles.open(path, "rb") as src,
aiofiles.open(file_path, "wb") as dst,
):
await dst.write(await src.read())
elif content:
# Write the provided content to the file
Expand Down
10 changes: 5 additions & 5 deletions backend/chainlit/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ async def audio_start(sid):

context = init_ws_context(session)
if config.code.on_audio_start:
connected = bool(await config.code.on_audio_start())
connection_state = "on" if connected else "off"
await context.emitter.update_audio_connection(connection_state)
connected = bool(await config.code.on_audio_start())
connection_state = "on" if connected else "off"
await context.emitter.update_audio_connection(connection_state)


@sio.on("audio_chunk")
async def audio_chunk(sid, payload: InputAudioChunkPayload):
Expand All @@ -350,7 +350,7 @@ async def audio_end(sid):

if config.code.on_audio_end:
await config.code.on_audio_end()

except asyncio.CancelledError:
pass
except Exception as e:
Expand Down
2 changes: 2 additions & 0 deletions backend/chainlit/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ class InputAudioChunk:
elapsedTime: float
data: bytes


class OutputAudioChunk(TypedDict):
track: str
mimeType: str
data: bytes


@dataclass
class AskFileResponse:
id: str
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/elements/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

@cl.step(type="tool")
async def gen_img():

return cl.Image(path="./cat.jpeg", name="image1", display="inline")


@cl.on_chat_start
async def start():

img = await gen_img()

# Element should not be inlined or referenced
Expand Down

0 comments on commit 205a950

Please sign in to comment.