-
-
Notifications
You must be signed in to change notification settings - Fork 143
Add Chat #7890
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
Draft
dem4ron
wants to merge
23
commits into
main
Choose a base branch
from
add-chat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add Chat #7890
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
948bb53
Add a basic UI
dem4ron dcd1941
Add basic streaming utils
dem4ron 388760f
Add AudioRecorder and tools
dem4ron 9f9e3cb
Make visualizer a littlebit better
dem4ron b7c2be4
Tweak visualizer
dem4ron 1342099
Add variable for drama level
dem4ron b44688c
Add basic gemini chat
dem4ron b574279
Handle audio too
dem4ron 303da9d
Add sending/receving from proxy (#7917)
iHiD e129a64
Make Ruby end work
dem4ron 66245bc
Make streaming work
dem4ron f5f4652
Improve in general
iHiD 6c0eedc
Implement done
iHiD 8a5ae81
Security
iHiD 47ee9ca
Improve prompting
iHiD 11ce8ed
Add messages from front-end page
iHiD 9ddfd70
Show previous messages, parse md, sort out types
dem4ron 38d71ef
Tweaks styling
dem4ron 9ac9a90
Send editor code along, reactive UI statuses
dem4ron 0c43e47
Add author label
dem4ron 26263fc
Scroll-tweaks
dem4ron fdb1668
Add Chat to Jiki editor
dem4ron 5d48adf
Add types, pass data down, add tabs to CSS page too, etc
dem4ron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class BootcampChatChannel < ApplicationCable::Channel | ||
def subscribed | ||
solution = current_user.bootcamp_solutions.find_by!(uuid: params[:solution_uuid]) | ||
stream_from "bootcamp_chat_#{solution.uuid}" | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Bootcamp::ChatMessage | ||
class Create | ||
include Mandate | ||
|
||
initialize_with :solution, :content, :author | ||
|
||
def call | ||
Bootcamp::ChatMessage.create!( | ||
solution:, | ||
content:, | ||
author: | ||
) | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class Bootcamp::ChatMessage | ||
class TriggerLLM | ||
include Mandate | ||
|
||
initialize_with :solution, :student_code | ||
|
||
def call | ||
RestClient.post( | ||
ENV.fetch("GEMINI_STREAMER_URL", "http://localhost:8080/chat"), | ||
{ | ||
solution_uuid: solution.uuid, | ||
exercise_info:, | ||
code:, | ||
messages:, | ||
stream_channel: | ||
}.to_json, | ||
{ content_type: :json } | ||
) | ||
end | ||
|
||
def stream_channel = "bootcamp_chat_#{solution.uuid}" | ||
|
||
def exercise_info | ||
<<~EOS | ||
The role of the student is to create a simple snake game in HTML, CSS, and JavaScript. | ||
The result should be that the snake appears on the screen and moves. | ||
When it gets near the edge, it should change direction (in a clockwise manner). | ||
There are no controls or dots to grow yet. | ||
|
||
These are the instructions the student was given: | ||
````` | ||
#{solution.exercise.introduction_markdown} | ||
````` | ||
EOS | ||
end | ||
|
||
def messages | ||
solution.messages.last(10).map do |message| | ||
{ | ||
author: message.author, | ||
content: message.content | ||
} | ||
end | ||
end | ||
|
||
def code | ||
code = JSON.parse(student_code, symbolize_names: true) | ||
|
||
<<~EOS | ||
### HTML | ||
#{code[:html] || ""} | ||
|
||
### CSS | ||
#{code[:css] || ""} | ||
|
||
### JavaScript | ||
#{code[:js] || ""} | ||
EOS | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class API::Bootcamp::ChatMessagesController < API::BaseController | ||
def create | ||
solution = current_user.bootcamp_solutions.find_by!(uuid: params[:solution_uuid]) | ||
|
||
Bootcamp::ChatMessage::Create.( | ||
solution, | ||
params[:content], | ||
:user | ||
) | ||
|
||
Bootcamp::ChatMessage::TriggerLLM.(solution, params[:code]) | ||
|
||
head :accepted | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class SPI::Bootcamp::ChatMessagesController < SPI::BaseController | ||
def create | ||
Bootcamp::ChatMessage::Create.( | ||
Bootcamp::Solution.find_by!(uuid: params[:solution_uuid]), | ||
params[:content], | ||
:llm | ||
) | ||
|
||
head :ok | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
.chat-textarea { | ||
margin: auto; | ||
resize: none; | ||
cursor: text; | ||
padding: 6px; | ||
} | ||
|
||
.ai-chat-container { | ||
@apply h-100 content-end; | ||
} | ||
|
||
.chat-input-container { | ||
@apply p-8; | ||
@apply flex flex-col items-center hover:cursor-text rounded-12; | ||
@apply border-1 border-[#ccc] focus-within:border-[#2e57e8]; | ||
@apply overflow-hidden; | ||
|
||
textarea { | ||
&::placeholder { | ||
@apply text-textColor7; | ||
} | ||
|
||
&:focus, | ||
&:focus-within { | ||
@apply border-none shadow-none outline-none; | ||
} | ||
@apply border-none shadow-none outline-none; | ||
@apply outline-none; | ||
} | ||
} | ||
|
||
.chat-thread { | ||
@apply flex flex-col gap-8 p-16; | ||
@apply max-h-[calc(100vh-200px)] overflow-y-auto; | ||
} | ||
|
||
.chat-message-wrapper { | ||
@apply self-end flex flex-col; | ||
label { | ||
@apply w-fit; | ||
@apply text-textColor7 text-12 mb-4; | ||
@apply self-end; | ||
} | ||
&.llm { | ||
@apply self-start; | ||
|
||
label { | ||
@apply self-start; | ||
} | ||
} | ||
} | ||
|
||
.chat-message { | ||
@apply text-16; | ||
@apply bg-textColor6 px-12 py-8 rounded-12 text-white font-medium w-fit; | ||
@apply leading-180; | ||
|
||
&.llm { | ||
@apply bg-bootcamp-light-purple; | ||
@apply max-w-[100%]; | ||
@apply text-textColor1 border-1 border-bootcamp-purple; | ||
|
||
p:not(:last-child) { | ||
@apply mb-16; | ||
} | ||
|
||
pre { | ||
@apply bg-thin-border-blue rounded-8 my-8; | ||
} | ||
|
||
& :not(pre) > code { | ||
@apply inline-flex items-center justify-center rounded-5; | ||
@apply not-italic; | ||
@apply px-6 text-textColor10 leading-regular; | ||
background: var(--backgroundColorI); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha :)