-
Notifications
You must be signed in to change notification settings - Fork 1
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
Frevagpt #69
Open
BiancaWentzel
wants to merge
137
commits into
main
Choose a base branch
from
frevagpt
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.
Open
Frevagpt #69
Changes from 127 commits
Commits
Show all changes
137 commits
Select commit
Hold shift + click to select a range
75669d5
Boilerplate code for a chat-endpoint in react
Karinon 99fa7e7
fixed some sorting issues for the linter...
Karinon 30a9b54
Merge branch 'main' of github.com:FREVA-CLINT/freva-web into frevagpt
antarcticrainforest fade7ec
Catch vault connection errors.
antarcticrainforest e1a0c84
Add skeleton for bot.
antarcticrainforest f092315
Adapted bot menu entry
604cf5c
Added conversation functionality including codeblocks and images
5708ef5
Enabled environment variable handling, added dependencies
476e92f
Changed method of parsing and fetching data stream
76b0665
Updated webpack production configs
76415e1
Added keydown event to input to trigger bot
fd37b6c
Adapted to utilize Bootstrap
d5d95ba
Included thread id into conversation and fetching
3b6f788
Adapted styling of codeblock and conversation bubbles
bf5d0fe
Added sidebar
85232c6
Made Codeblock collapsible
ee64840
Added variant logs
487b9f7
Added thread si to url
ae4c3d1
Made thread id a ref instead of state varaible
aaaf4c1
merged current status of frevagpt
96eeeae
Outsourced sidepanel
2cb1965
WIP viewing old threads
368fa27
adapted conversation to support thread history, adapted codeblock
8a376f3
undone conversation changes
89890a2
added example request on climate data
b654c8f
Formatted Code String
be0ec6b
Changed data streaming to include buffer being parsed bit by bit
0057b1b
Adapted fetching of old thread
cdb9556
added example requests
5633336
Added hanling of markdown in response
496185f
Added differentiation for errors
2fb2510
Added button to stop request
60ec059
Awaiting whole anser of old thread
ce64419
Added code hilighting, updated examples using new code escaping backend
70592f1
Integrated stop button into input, added Button to start new chat
45029ff
Added Error Type to Output
2e1a744
Added freva config to bot request
132d88c
Codeoutput only displayed when content available
dd6a624
Introduced FrontendError
b63fcd9
removed additional encoding of user input
aba1639
disabled input during bot request
e827fc9
Hilighting manual stop by user
792f5a7
Refactored loading parameter
cfda87d
added fetch aborter
5e7f72d
hiding stop button while no request is done
939f547
resolved merge conflict
2ada6a9
changed encoding of user input for requests
024a422
update requests, added freva requests
8c12c01
removed console statement
5ca9378
WIP adaptation of freva bot to use redux
2ff088b
Moved example requests into own file unrelated to redux
b6e56ea
Moved helper function sinto untils file unrelated to redux
003026e
WIP refactoring to use redux for state management
122adb9
State management using redux
38e66ef
Resolved merge conflicts
75bd8d3
added example requests
d3f8a90
Added play button to chatbot input field
028c28a
Adapted user input to reset after submit
ee64fe2
Added hidden switch for selecting bot model
5cb7bf4
outsourced conversation block to optimize rendering and performance
5e8d261
added hidden toggle for bot select list
aa402b7
Fixed assessing thread for stopping request
fbc2da1
Included error logging for fetch request
BiancaWentzel 1b20a6d
Added suggestion buttons to start conversation
9b82cbe
Added handling of unresponsible chatbot
10fac58
Adapted buttons and suggestions to provide inputvalue
27e1b06
Resolved missing ansynchronity during bot check
b2e3556
Seperated components into different render functions, covered display…
8c30e75
removed statement to hide component
7c1b41d
Adapted according to comments from #60
339bea7
Added tooltip to suggestion buttons
89e616c
Adapted suggestion buttons to use responsive grid system
e845ffe
WIP: fixing linting
77c5c09
Fixed linting
87e541c
Prettified code
d9e335b
Removed watch flag from dev build command
a977325
Merge pull request #60 from FREVA-CLINT/suggestions
BiancaWentzel 878fa18
removed hidden statement, shortened Component call
4cac238
Adapted conditional rendering of alert
7bb01d0
Adapted ping request
17ce5b6
Merged current state of frevagpt branch
39a2482
Added support for markdown tables
c1f9260
Removed watch statement for tests
e3f990e
Fixed linting
08de41e
Fixed suggestion display for existing thread
8c482ef
Fixed linting
f5f512f
Merge pull request #66 from FREVA-CLINT/fix-suggestions
BiancaWentzel 958677b
Merge branch 'frevagpt' into markdown-table-support
6f2587d
Merge pull request #65 from FREVA-CLINT/markdown-table-support
BiancaWentzel a668ab6
Merged from main
fbc2adf
Merge pull request #67 from FREVA-CLINT/update-from-main
BiancaWentzel e29989b
Adapted statement determining display of header
5e4eea6
Merge branch 'frevagpt' into unavailability
6e1acaf
Merge pull request #61 from FREVA-CLINT/unavailability
BiancaWentzel e18ea62
Included debug log
7f9483f
Adapted auth
06c3854
Changed proxy to enable streaming
ead2c1b
Live rendering of streamed data, restructured chatbot components
b0405e4
Fixed linting
f76a87b
Adapted spinner while response is streamed
243801f
Shortened proxy view
f463de6
Removed conditional rendering of Answer component enabling realtime r…
606018c
Adapted conditional rendering of spinner
af0b67a
Added code processing placeholder
df37b21
Handling of parsing error for streamed response
9649a58
Adapted bubble color for user input
6bae178
Adapted AnswerComponent to render code in real time
5996571
Fixed linting
f9fab2f
Resolved flickering issue of real time code rendering
c409b1e
Renamed component rendering streamed data in real time
0327f7e
Adapted PendingAnswerComponent and CodeBlock to look the same, define…
f745afb
Fixed linting
64f19d8
Outsourced assistant bubble style into a constant
c153a90
Merge pull request #68 from FREVA-CLINT/data-treaming
BiancaWentzel 33179fe
Removed unused fragments
c80eb18
Added linting rule preventing one-line-statements without braces
6ac470c
Fixed linting
60d50b7
Exchanged console-error-statements with proper error handling
4903cfe
Exchanged third-party has with built-in hasOwn
0318363
Fixed requesting bot on clickung play button
217eca6
Submit request to backend only if userInput not empty
7be1cbc
Removed unused depedencies, including bootstrap icons
f77876f
Removed unused plugins, moved Dotenv to base config
f890cf5
Exchanged old icons with react icons
a2e1486
Removed unused rule
1ea7b93
Moved auth key and freva config to local environment used by proxyview
0e5c3fd
Using query-string instead of custom function
81c3f3f
Adapted SidePanel
617f010
Removed unused dependencies from webpack config
b5e28fb
Deleted empty file
8796deb
Added styling classes to input buttons
69aaa4b
Trimmed unnecessary spaces from input, preventing submission of empty…
69a1486
Added error handling to bot model request
465af02
Added error handling and message display on server error
73b9b1a
Fixed typo
1b6bfe3
Added timeout
9ea6059
Merge remote-tracking branch 'origin/frevagpt' into frevagpt
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 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 |
---|---|---|
|
@@ -125,6 +125,10 @@ | |
{ | ||
"allowAllPropertiesOnSameLine": true | ||
} | ||
], | ||
"curly": [ | ||
"warn", | ||
"all" | ||
] | ||
} | ||
} |
This file contains 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 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 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,22 @@ | ||
import * as constants from "./constants"; | ||
|
||
export function setThread(thread_id) { | ||
return { | ||
type: "SET_THREAD", | ||
payload: thread_id, | ||
}; | ||
} | ||
|
||
export function setConversation(conversation) { | ||
return { | ||
type: "SET_CONVERSATION", | ||
payload: conversation, | ||
}; | ||
} | ||
|
||
export const addElement = (element) => (dispatch) => { | ||
dispatch({ | ||
type: constants.ADD_ELEMENT, | ||
payload: element, | ||
}); | ||
}; |
This file contains 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,139 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { connect } from "react-redux"; | ||
|
||
import { Col, Card } from "react-bootstrap"; | ||
|
||
import { isEmpty } from "lodash"; | ||
|
||
import ReactMarkdown from "react-markdown"; | ||
import remarkGfm from "remark-gfm"; | ||
|
||
import { replaceLinebreaks } from "../utils"; | ||
|
||
import * as constants from "../constants"; | ||
|
||
import CodeBlock from "./CodeBlock"; | ||
|
||
class ChatBlock extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.renderImage = this.renderImage.bind(this); | ||
this.renderCode = this.renderCode.bind(this); | ||
this.renderUser = this.renderUser.bind(this); | ||
this.renderError = this.renderError.bind(this); | ||
this.renderDefault = this.renderDefault.bind(this); | ||
} | ||
|
||
renderImage(element) { | ||
return ( | ||
<Col key={element.content} md={constants.BOT_COLUMN_STYLE}> | ||
<img | ||
className="w-100" | ||
src={`data:image/jpeg;base64,${element.content}`} | ||
/> | ||
</Col> | ||
); | ||
} | ||
|
||
renderCode(element) { | ||
if (isEmpty(element.content[0])) { | ||
return null; | ||
} else { | ||
return ( | ||
<Col md={constants.BOT_COLUMN_STYLE} key={element.content}> | ||
<CodeBlock title={element.variant} code={element.content} /> | ||
</Col> | ||
); | ||
} | ||
} | ||
|
||
renderUser(element) { | ||
return ( | ||
<Col md={{ span: 10, offset: 2 }} key={element.content}> | ||
<Card | ||
className="shadow-sm card-body border-0 border-bottom mb-3" | ||
style={{ backgroundColor: "#eee" }} | ||
> | ||
{element.content} | ||
</Card> | ||
</Col> | ||
); | ||
} | ||
|
||
renderError(element) { | ||
return ( | ||
<Col md={constants.BOT_COLUMN_STYLE} key={element.content}> | ||
<Card className="shadow-sm card-body border-0 border-bottom mb-3 bg-danger"> | ||
<span className="fw-bold">{element.variant}</span> | ||
<ReactMarkdown>{replaceLinebreaks(element.content)}</ReactMarkdown> | ||
</Card> | ||
</Col> | ||
); | ||
} | ||
|
||
renderDefault(element) { | ||
return ( | ||
<Col md={constants.BOT_COLUMN_STYLE} key={element.content}> | ||
<Card className="shadow-sm card-body border-0 border-bottom mb-3 bg-light"> | ||
<ReactMarkdown remarkPlugins={[remarkGfm]}> | ||
{replaceLinebreaks(element.content)} | ||
</ReactMarkdown> | ||
</Card> | ||
</Col> | ||
); | ||
} | ||
|
||
renderChatComponents(element) { | ||
switch (element.variant) { | ||
case "ServerHint": | ||
case "StreamEnd": | ||
return null; | ||
case "Image": | ||
return this.renderImage(element); | ||
|
||
case "Code": | ||
case "CodeOutput": | ||
return this.renderCode(element); | ||
|
||
case "User": | ||
return this.renderUser(element); | ||
|
||
case "ServerError": | ||
case "OpenAIError": | ||
case "CodeError": | ||
case "FrontendError": | ||
case "UserStop": | ||
return this.renderError(element); | ||
|
||
default: | ||
return this.renderDefault(element); | ||
} | ||
} | ||
|
||
render() { | ||
const { conversation } = this.props.chatBlock; | ||
|
||
return ( | ||
<Col> | ||
{conversation.map((element) => { | ||
return this.renderChatComponents(element); | ||
})} | ||
</Col> | ||
); | ||
} | ||
} | ||
|
||
ChatBlock.propTypes = { | ||
chatBlock: PropTypes.shape({ | ||
thread: PropTypes.string, | ||
conversation: PropTypes.array, | ||
}), | ||
}; | ||
|
||
const mapStateToProps = (state) => ({ | ||
chatBlock: state.frevaGPTReducer, | ||
}); | ||
|
||
export default connect(mapStateToProps)(ChatBlock); |
This file contains 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,33 @@ | ||
import React from "react"; | ||
import { Accordion } from "react-bootstrap"; | ||
|
||
import PropTypes from "prop-types"; | ||
|
||
import Highlight from "react-highlight"; | ||
import "highlight.js/styles/atom-one-light.css"; | ||
|
||
import { formatCode } from "../utils"; | ||
|
||
function CodeBlock(props) { | ||
return ( | ||
<div className="mb-3"> | ||
<Accordion defaultActiveKey="0"> | ||
<Accordion.Item eventKey="0"> | ||
<Accordion.Header>python</Accordion.Header> | ||
<Accordion.Body> | ||
<Highlight className="python"> | ||
{formatCode(props.title, props.code[0])} | ||
</Highlight> | ||
</Accordion.Body> | ||
</Accordion.Item> | ||
</Accordion> | ||
</div> | ||
); | ||
} | ||
|
||
CodeBlock.propTypes = { | ||
code: PropTypes.array, | ||
title: PropTypes.string, | ||
}; | ||
|
||
export default CodeBlock; |
93 changes: 93 additions & 0 deletions
93
assets/js/Containers/FrevaGPT/components/PendingAnswerComponent.js
This file contains 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,93 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import { Col, Card, Spinner, Accordion, Row } from "react-bootstrap"; | ||
|
||
import Markdown from "react-markdown"; | ||
|
||
import Highlight from "react-highlight"; | ||
import "highlight.js/styles/atom-one-light.css"; | ||
|
||
import * as constants from "../constants"; | ||
|
||
function PendingAnswerComponent(props) { | ||
const [renderedCode, setRenderedCode] = useState(""); | ||
|
||
useEffect(() => { | ||
const parsedCode = renderCode(props.content); | ||
if (parsedCode !== "") { | ||
setRenderedCode(parsedCode); | ||
} | ||
}, [props.content]); | ||
|
||
function renderCode(rawCode) { | ||
let jsonCode = ""; | ||
let codeSnippets = ""; | ||
|
||
if (!rawCode.endsWith('"}')) { | ||
jsonCode = rawCode + '"}'; | ||
} else { | ||
jsonCode = rawCode; | ||
} | ||
|
||
try { | ||
const code = JSON.parse(jsonCode); | ||
codeSnippets = code.code; | ||
} catch (err) { | ||
// console.error(err); | ||
} | ||
return codeSnippets; | ||
} | ||
|
||
function renderAnswer(props) { | ||
switch (props.variant) { | ||
case "Assistant": | ||
return ( | ||
<Col md={constants.BOT_COLUMN_STYLE}> | ||
<Card className="shadow-sm card-body border-0 border-bottom mb-3 bg-light"> | ||
<Markdown>{props.content}</Markdown> | ||
</Card> | ||
</Col> | ||
); | ||
case "Code": | ||
case "CodeBlock": | ||
return ( | ||
<Col md={constants.BOT_COLUMN_STYLE}> | ||
<div className="mb-3"> | ||
<Accordion defaultActiveKey="0"> | ||
<Accordion.Item eventKey="0"> | ||
<Accordion.Header>python</Accordion.Header> | ||
<Accordion.Body> | ||
<Highlight className="python">{renderedCode}</Highlight> | ||
<span> | ||
<Spinner size="sm" /> | ||
<span className="m-2">Analyzing...</span> | ||
</span> | ||
</Accordion.Body> | ||
</Accordion.Item> | ||
</Accordion> | ||
</div> | ||
</Col> | ||
); | ||
case "ServerHint": | ||
return ( | ||
<Row className="mb-3"> | ||
<Col md={1}> | ||
<Spinner /> | ||
</Col> | ||
</Row> | ||
); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
return renderAnswer(props); | ||
} | ||
|
||
PendingAnswerComponent.propTypes = { | ||
content: PropTypes.string, | ||
variant: PropTypes.string, | ||
}; | ||
|
||
export default PendingAnswerComponent; |
This file contains 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,63 @@ | ||
import React from "react"; | ||
import { Card } from "react-bootstrap"; | ||
|
||
import { browserHistory } from "react-router"; | ||
|
||
import { botRequests } from "../exampleRequests"; | ||
|
||
function SidePanel() { | ||
function changeToThread(thread) { | ||
browserHistory.push({ | ||
pathname: "/chatbot/", | ||
search: `?thread_id=${thread}`, | ||
}); | ||
} | ||
|
||
return ( | ||
<div> | ||
<Card className="mb-3 shadow-sm"> | ||
<div className="btn btn-outline-secondary border-0 p-3 rounded-top text-start card-header shadow-sm button-div"> | ||
General requests | ||
</div> | ||
<div className="p-3 py-2 collapse show"> | ||
{botRequests.general.map((element) => { | ||
return ( | ||
<div key={element.thread}> | ||
<a | ||
className="text-wrap" | ||
href="" | ||
onClick={() => changeToThread(element.thread)} | ||
> | ||
{element.title} | ||
</a> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</Card> | ||
|
||
<Card className="mb-3 shadow-sm"> | ||
<div className="btn btn-outline-secondary border-0 p-3 rounded-top text-start card-header shadow-sm button-div"> | ||
Freva requests | ||
</div> | ||
<div className="p-3 py-2 collapse show"> | ||
{botRequests.freva.map((element) => { | ||
return ( | ||
<div key={element.thread}> | ||
<a | ||
className="text-wrap" | ||
href="" | ||
onClick={() => changeToThread(element.thread)} | ||
> | ||
{element.title} | ||
</a> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</Card> | ||
</div> | ||
); | ||
} | ||
|
||
export default SidePanel; |
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.
<>
btn
here. Due to thebtn
the user experience here implies that the Header of the section/Card
is clickable, which it isn't. A simple<Card.Header>
is fine as well<Card.Body>
looks fine for me, too. It isn't collapsible.onClick
? I think a<a className="text-wrap" href={`/chatbot/?thread_id=${element.thread}`} >
would be totally fine. It would be even better, if you could use<Link to...
instead (fromimport { Link } from "react-router";
) because it wouldn't cause the whole website to reload and the user would stay inside react, but this would need more adjustments.