Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove revalidation on focus #137

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.5.2] - 2023-12-20

### Fixed

- screen jitter on revalidation conversations and messages on webui

### Changed

- Removed A/B testing logic

## [0.5.1] - 2023-12-12

### Added
Expand Down
87 changes: 43 additions & 44 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ async def delete_conversation(conversation_id: str):
@app.get("/api/conversations/insert")
async def add_conversation(user_id: str, location_id: str = "web"):
async with LOCK:
metadata = {"A/B": False}
if not user_id.startswith("anon_"):
# metadata = /B": False}
# if not user_id.startswith("anon_"):
# metadata["A/B"] = bool(random.getrandbits(1))
metadata["A/B"] = True
representation = MEDIATOR.add_conversation(location_id=location_id, user_id=user_id, metadata=metadata)
# metadata["A/B"] = True
representation = MEDIATOR.add_conversation(location_id=location_id, user_id=user_id)
conversation_id = representation["id"]
return {
"conversation_id": conversation_id
Expand All @@ -111,17 +111,17 @@ async def get_messages(user_id: str, conversation_id: str):
async def chat(inp: ConversationInput):
async with LOCK:
conversation = Conversation(MEDIATOR, user_id=inp.user_id, conversation_id=inp.conversation_id)
conversation_data = MEDIATOR.conversation(session_id=inp.conversation_id)
if honcho_url and conversation_data and conversation_data["metadata"]:
metadata = conversation_data["metadata"]
if "A/B" in metadata.keys() and metadata["A/B"]:
response = requests.post(f'{honcho_url}/chat', json={
"user_id": inp.user_id,
"conversation_id": inp.conversation_id,
"message": inp.message
}, stream=True)
print(response)
return response
# conversation_data = MEDIATOR.conversation(session_id=inp.conversation_id)
if honcho_url:
# metadata = conversation_data["metadata"]
# if "A/B" in metadata.keys() and metadata["A/B"]:
response = requests.post(f'{honcho_url}/chat', json={
"user_id": inp.user_id,
"conversation_id": inp.conversation_id,
"message": inp.message
}, stream=True)
print(response)
return response
if conversation is None:
raise HTTPException(status_code=404, detail="Item not found")
thought, response = await BloomChain.chat(conversation, inp.message)
Expand All @@ -136,35 +136,34 @@ async def stream(inp: ConversationInput):
"""Stream the response too the user, currently only used by the Web UI and has integration to be able to use Honcho is not anonymous"""
async with LOCK:
conversation = Conversation(MEDIATOR, user_id=inp.user_id, conversation_id=inp.conversation_id)
conversation_data = MEDIATOR.conversation(session_id=inp.conversation_id)
if honcho_url and not inp.user_id.startswith("anon_") and conversation_data and conversation_data["metadata"]:
metadata = conversation_data["metadata"]
if "A/B" in metadata.keys() and metadata["A/B"]:
response = requests.post(f'{honcho_url}/stream', json={
"user_id": inp.user_id,
"conversation_id": inp.conversation_id,
"message": inp.message
}, stream=True)

def generator():
try:
for chunk in response.iter_content(chunk_size=8192):
# print(f"Received chunk: {chunk}")
if chunk:
yield chunk
except ChunkedEncodingError as e:
print(f"Chunked encoding error occurred: {e}")
print(response)
print(response.headers)
# Optionally yield an error message to the client
yield b"An error occurred while streaming the response."
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Optionally yield an error message to the client
yield b"An unexpected error occurred."

print("A/B Confirmed")
return StreamingResponse(generator())
# conversation_data = MEDIATOR.conversation(session_id=inp.conversation_id)
if honcho_url and not inp.user_id.startswith("anon_"):
# metadata = conversation_data["metadata"]
# if "A/B" in metadata.keys() and metadata["A/B"]:
response = requests.post(f'{honcho_url}/stream', json={
"user_id": inp.user_id,
"conversation_id": inp.conversation_id,
"message": inp.message
}, stream=True)

def generator():
try:
for chunk in response.iter_content(chunk_size=8192):
# print(f"Received chunk: {chunk}")
if chunk:
yield chunk
except ChunkedEncodingError as e:
print(f"Chunked encoding error occurred: {e}")
print(response)
print(response.headers)
# Optionally yield an error message to the client
yield b"An error occurred while streaming the response."
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Optionally yield an error message to the client
yield b"An unexpected error occurred."

return StreamingResponse(generator())
if conversation is None:
raise HTTPException(status_code=404, detail="Item not found")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tutor-gpt"
version = "0.5.1"
version = "0.5.2"
description = "LangChain LLM application. Dynamic few-shot metaprompting for the task of tutoring."
authors = ["vintro <vince@plasticlabs.ai>", "VVoruganti <vineeth@plasticlabs.ai"]
readme = "README.md"
Expand Down
101 changes: 50 additions & 51 deletions www/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default function Home() {
setConversationId(conversations[0].conversationId);
setCanSend(true);
},
revalidateOnFocus: false,
});

const messagesFetcher = async (conversationId: string) => {
Expand All @@ -119,7 +120,7 @@ export default function Home() {
mutate: mutateMessages,
isLoading: messagesLoading,
error: _,
} = useSWR(conversationId, messagesFetcher);
} = useSWR(conversationId, messagesFetcher, { revalidateOnFocus: false });

async function chat() {
const textbox = input.current!;
Expand Down Expand Up @@ -163,19 +164,17 @@ export default function Home() {
while (true) {
const { done, value } = await reader.read();
if (done) {
// console.log("done");
setCanSend(true);
break;
}
// console.log(value);
if (isThinking) {
if (value.includes("❀")) {
// a bloom delimiter
isThinking = false;
continue;
}
setThought((prev) => prev + value);
mutateMessages(newMessages, { revalidate: false });
// mutateMessages(newMessages, { revalidate: false });
} else {
if (value.includes("❀")) {
setCanSend(true); // Bloom delimeter
Expand Down Expand Up @@ -265,60 +264,60 @@ export default function Home() {
className="flex flex-col flex-1 overflow-y-auto lg:px-5 dark:text-white"
ref={messageContainerRef}
>
{
messagesLoading || messages === undefined ? (
<MessageBox loading />
) : (
messages.map((message, i) => (
<MessageBox isUser={message.isUser} key={i}>
<MarkdownWrapper text={message.text} />
</MessageBox>
))
)
}
{
messagesLoading || messages === undefined ? (
<MessageBox loading />
) : (
messages.map((message, i) => (
<MessageBox isUser={message.isUser} key={i}>
<MarkdownWrapper text={message.text} />
</MessageBox>
))
)
}
</section >
<form
id="send"
className="flex p-3 lg:p-5 gap-3 border-gray-300"
onSubmit={(e) => {
e.preventDefault();
if (canSend && input.current?.value) {
posthog.capture("user_sent_message");
chat();
}
}}
>
{/* TODO: validate input */}
<textarea
ref={input}
placeholder="Type a message..."
className={`flex-1 px-3 py-1 lg:px-5 lg:py-3 bg-gray-100 dark:bg-gray-800 text-gray-400 rounded-2xl border-2 resize-none ${canSend ? " border-green-200" : "border-red-200 opacity-50"
}`}
disabled={!canSend}
rows={1}
onKeyDown={(e) => {
if (e.key === "Enter" && !e.shiftKey) {
<form
id="send"
className="flex p-3 lg:p-5 gap-3 border-gray-300"
onSubmit={(e) => {
e.preventDefault();
if (canSend && input.current?.value) {
posthog.capture("user_sent_message");
chat();
}
}
}}
/>
<button
className="bg-dark-green text-neon-green rounded-full px-4 py-2 lg:px-7 lg:py-3 flex justify-center items-center gap-2"
type="submit"
>
<FaPaperPlane className="inline" />
</button>
</form>
}}
>
{/* TODO: validate input */}
<textarea
ref={input}
placeholder="Type a message..."
className={`flex-1 px-3 py-1 lg:px-5 lg:py-3 bg-gray-100 dark:bg-gray-800 text-gray-400 rounded-2xl border-2 resize-none ${canSend ? " border-green-200" : "border-red-200 opacity-50"
}`}
rows={1}
onKeyDown={(e) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
if (canSend && input.current?.value) {
posthog.capture("user_sent_message");
chat();
}
}
}}
/>
<button
className="bg-dark-green text-neon-green rounded-full px-4 py-2 lg:px-7 lg:py-3 flex justify-center items-center gap-2"
type="submit"
disabled={!canSend}
>
<FaPaperPlane className="inline" />
</button>
</form>
</div >
<Thoughts
thought={thought}
setIsThoughtsOpen={setIsThoughtsOpen}
isThoughtsOpen={isThoughtsOpen}
/>
<Thoughts
thought={thought}
setIsThoughtsOpen={setIsThoughtsOpen}
isThoughtsOpen={isThoughtsOpen}
/>
</main >
);
}
4 changes: 2 additions & 2 deletions www/components/markdownWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default function MarkdownWrapper({ text }: { text: string }) {
// @ts-expect-error i think typing is wrong from the library itself, this comment should raise an error once its fixed. // TODO: remove this comment
rehypePlugins={[rehypeKatex]}
components={{
ol: ({ node, ...props }) => <ol className="list-decimal" {...props} />,
ul: ({ node, ...props }) => <ul className="list-disc" {...props} />,
ol: ({ node, ...props }) => { const { ordered, ...filteredProps } = props; return <ol className="list-decimal" {...filteredProps} /> },
ul: ({ node, ...props }) => { const { ordered, ...filteredProps } = props; return <ul className="list-disc" {...filteredProps} /> },
code({ node, inline, className, children, ...props }) {
const match = /language-(\w+)/.exec(className || "");
return !inline && match ? (
Expand Down
49 changes: 27 additions & 22 deletions www/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@
tslib "^2.4.0"

"@types/debug@^4.0.0":
version "4.1.8"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.8.tgz#cef723a5d0a90990313faec2d1e22aee5eecb317"
integrity sha512-/vPO1EPOs306Cvhwv7KfVfYvOJqA/S/AXjaHQiJboCZzcNDb+TIJFN9/2C9DZ//ijSKWioNyUxD792QmDJ+HKQ==
version "4.1.12"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917"
integrity sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==
dependencies:
"@types/ms" "*"

Expand All @@ -502,9 +502,9 @@
integrity sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==

"@types/hast@^2.0.0":
version "2.3.5"
resolved "https://registry.yarnpkg.com/@types/hast/-/hast-2.3.5.tgz#08caac88b44d0fdd04dc17a19142355f43bd8a7a"
integrity sha512-SvQi0L/lNpThgPoleH53cdjB3y9zpLlVjRbqB3rH8hx1jiRSBGAhyjV3H+URFjNVRqt2EdYNrbZE5IsGlNfpRg==
version "2.3.8"
resolved "https://registry.yarnpkg.com/@types/hast/-/hast-2.3.8.tgz#4ac5caf38b262b7bd5ca3202dda71f0271635660"
integrity sha512-aMIqAlFd2wTIDZuvLbhUT+TGvMxrNC8ECUIVtH6xxy0sQLs3iu6NO8Kp/VT5je7i5ufnebXzdV1dNDMnvaH6IQ==
dependencies:
"@types/unist" "^2"

Expand All @@ -526,9 +526,9 @@
integrity sha512-CeVMX9EhVUW8MWnei05eIRks4D5Wscw/W9Byz1s3PA+yJvcdvq9SaDjiUKvRvEgjpdTyJMjQA43ae4KTwsvOPg==

"@types/mdast@^3.0.0":
version "3.0.12"
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.12.tgz#beeb511b977c875a5b0cc92eab6fcac2f0895514"
integrity sha512-DT+iNIRNX884cx0/Q1ja7NyUPpZuv0KPyL5rGNxm1WC1OtHstl7n4Jb7nk+xacNShQMbczJjt8uFzznpp6kYBg==
version "3.0.15"
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.15.tgz#49c524a263f30ffa28b71ae282f813ed000ab9f5"
integrity sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==
dependencies:
"@types/unist" "^2"

Expand All @@ -540,9 +540,9 @@
"@types/unist" "*"

"@types/ms@*":
version "0.7.31"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==
version "0.7.34"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433"
integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==

"@types/node@*":
version "20.5.9"
Expand All @@ -559,11 +559,16 @@
resolved "https://registry.yarnpkg.com/@types/phoenix/-/phoenix-1.6.1.tgz#9551cd77a8f4c70c5d81db899f2af762066aabde"
integrity sha512-g2/8Ogi2zfiS25jdGT5iDSo5yjruhhXaOuOJCkOxMW28w16VxFvjtAXjBNRo7WlRS4+UXAMj3mK46UwieNM/5g==

"@types/prop-types@*", "@types/prop-types@^15.0.0":
"@types/prop-types@*":
version "15.7.5"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==

"@types/prop-types@^15.0.0":
version "15.7.11"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.11.tgz#2596fb352ee96a1379c657734d4b913a613ad563"
integrity sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==

"@types/react-dom@18.2.7":
version "18.2.7"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.7.tgz#67222a08c0a6ae0a0da33c3532348277c70abb63"
Expand Down Expand Up @@ -598,9 +603,9 @@
integrity sha512-MFETx3tbTjE7Uk6vvnWINA/1iJ7LuMdO4fcq8UfF0pRbj01aGLduVvQcRyswuACJdpnHgg8E3rQLhaRdNEJS0w==

"@types/unist@^2", "@types/unist@^2.0.0":
version "2.0.7"
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.7.tgz#5b06ad6894b236a1d2bd6b2f07850ca5c59cf4d6"
integrity sha512-cputDpIbFgLUaGQn6Vqg3/YsJwxUwHLO13v3i5ouxT4lat0khip9AEWxtERujXV9wxIB1EyF97BSJFt6vpdI8g==
version "2.0.10"
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.10.tgz#04ffa7f406ab628f7f7e97ca23e290cd8ab15efc"
integrity sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==

"@types/uuid@^9.0.2":
version "9.0.2"
Expand Down Expand Up @@ -3516,9 +3521,9 @@ property-information@^5.0.0:
xtend "^4.0.0"

property-information@^6.0.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/property-information/-/property-information-6.2.0.tgz#b74f522c31c097b5149e3c3cb8d7f3defd986a1d"
integrity sha512-kma4U7AFCTwpqq5twzC1YVIDXSqg6qQK6JN0smOw8fgRy1OkMi0CYSzFmsy6dnqSenamAtj0CyXMUJ1Mf6oROg==
version "6.4.0"
resolved "https://registry.yarnpkg.com/property-information/-/property-information-6.4.0.tgz#6bc4c618b0c2d68b3bb8b552cbb97f8e300a0f82"
integrity sha512-9t5qARVofg2xQqKtytzt+lZ4d1Qvj8t5B8fEwXK6qOfgRLgH/b13QlgEyDh033NOS31nXeFbYv7CLUDG1CeifQ==

proxy-from-env@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -4025,9 +4030,9 @@ strip-json-comments@~2.0.1:
integrity sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==

style-to-object@^0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-0.4.2.tgz#a8247057111dea8bd3b8a1a66d2d0c9cf9218a54"
integrity sha512-1JGpfPB3lo42ZX8cuPrheZbfQ6kqPPnPHlKMyeRYtfKD+0jG+QsXgXN57O/dvJlzlB2elI6dGmrPnl5VPQFPaA==
version "0.4.4"
resolved "https://registry.yarnpkg.com/style-to-object/-/style-to-object-0.4.4.tgz#266e3dfd56391a7eefb7770423612d043c3f33ec"
integrity sha512-HYNoHZa2GorYNyqiCaBgsxvcJIn7OHq6inEga+E6Ke3m5JkoqpQbnFssk4jwe+K7AhGa2fcha4wSOf1Kn01dMg==
dependencies:
inline-style-parser "0.1.1"

Expand Down
Loading