Skip to content

Commit

Permalink
Wd/0.6.401 (#349)
Browse files Browse the repository at this point in the history
* fix last message loading

* make follow_symlink default to False and configurable

* relax fastapi version requirement

* fix local db client

* try to stringify content instead of throwing

* remove prints
  • Loading branch information
willydouhard authored Sep 1, 2023
1 parent 9efa918 commit 3985c9e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/chainlit/client/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def before_write(self, variables: Dict):
# Sqlite doesn't support list of primitives, so we need to serialize it.
variables["forIds"] = json.dumps(variables["forIds"])

if "streaming" in variables:
del variables["streaming"]

def after_read(self, variables: Dict):
if "prompt" in variables:
# Sqlite doesn't support json fields, so we need to parse it.
Expand Down
5 changes: 5 additions & 0 deletions src/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
# Enable third parties caching (e.g LangChain cache)
cache = false
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
# follow_symlink = false
# Chainlit server address
# chainlit_server = ""
Expand Down Expand Up @@ -203,6 +206,8 @@ class ProjectSettings(DataClassJsonMixin):
session_timeout: int = 3600
# Enable third parties caching (e.g LangChain cache)
cache: bool = False
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
follow_symlink: bool = False
# Chainlit server address
chainlit_server: Optional[str] = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ interface Props {
isRunning?: boolean;
}

function isLastMessage(messages: INestedMessage[], index: number) {
if (messages.length - 1 === index) {
return true;
}

for (let i = index + 1; i < messages.length; i++) {
if (messages[i].streaming) {
continue;
} else {
return false;
}
}

return true;
}

export default function Messages({
messages,
elements,
Expand All @@ -24,21 +40,25 @@ export default function Messages({
isRunning
}: Props) {
const loading = useRecoilValue(loadingState);
const isRoot = indent === 0;
let previousAuthor = '';

const filtered = messages.filter((m, i) => {
const hasContent = !!m.content;
const hasChildren = !!m.subMessages?.length;
const isLast = i === messages.length - 1;
const _isRunning =
const messageRunning =
isRunning === undefined ? loading && isLast : isRunning && isLast;
return hasContent || hasChildren || (!hasContent && _isRunning);
return hasContent || hasChildren || (!hasContent && messageRunning);
});
return (
<>
{filtered.map((m, i) => {
const isLast = i === filtered.length - 1;
const _isRunning =
isRunning === undefined ? loading && isLast : isRunning && isLast;
const isLast = isLastMessage(filtered, i);
let messageRunning = isRunning === undefined ? loading : isRunning;
if (isRoot) {
messageRunning = messageRunning && isLast;
}
const showAvatar = m.author !== previousAuthor;
const showBorder = false;
previousAuthor = m.author;
Expand All @@ -49,9 +69,9 @@ export default function Messages({
actions={actions}
showAvatar={showAvatar}
showBorder={showBorder}
key={i}
key={m.id}
indent={indent}
isRunning={_isRunning}
isRunning={messageRunning}
isLast={isLast}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/chainlit/frontend/src/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface IMessage {
parentId?: string;
isError?: boolean;
prompt?: IPrompt;
streaming?: boolean;
}

export interface IMessageUpdate extends IMessage {
Expand Down
6 changes: 5 additions & 1 deletion src/chainlit/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ def __init__(
elif isinstance(content, str):
self.content = content
else:
raise TypeError(f"Unsupported type {type(content)} for message content")
logger.warn(
f"Unsupported type {type(content)} for message content. Attempting to stringify it"
)
self.content = str(content)

self.author = author
self.prompt = prompt
Expand Down Expand Up @@ -192,6 +195,7 @@ def to_dict(self):
"language": self.language,
"parentId": self.parent_id,
"indent": self.indent,
"streaming": self.streaming,
}

if self.prompt:
Expand Down
3 changes: 2 additions & 1 deletion src/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ async def watch_files_for_changes():
app.mount(
"/assets",
StaticFiles(
packages=[("chainlit", os.path.join(build_dir, "assets"))], follow_symlink=True
packages=[("chainlit", os.path.join(build_dir, "assets"))],
follow_symlink=config.project.follow_symlink,
),
name="assets",
)
Expand Down
4 changes: 2 additions & 2 deletions src/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "chainlit"
version = "0.6.4"
version = "0.6.401"
keywords = ['LLM', 'Agents', 'gen ai', 'chat ui', 'chatbot ui', 'langchain']
description = "A faster way to build chatbot UIs."
authors = ["Chainlit"]
Expand All @@ -22,7 +22,7 @@ chainlit = 'chainlit.cli:cli'
python = "^3.8.1"
dataclasses_json = "^0.5.7"
uvicorn = "^0.23.2"
fastapi = "^0.103.0"
fastapi = "^0.99.0"
fastapi-socketio = "^0.0.10"
aiohttp = "^3.8.4"
aiofiles = "^23.1.0"
Expand Down

0 comments on commit 3985c9e

Please sign in to comment.