Skip to content

Commit

Permalink
Merge pull request modelscope#4 from qbc2016/dev_input_refine
Browse files Browse the repository at this point in the history
refine input
  • Loading branch information
pan-x-c committed Jun 6, 2024
2 parents e41a701 + 3ba8269 commit b81b935
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"protobuf==4.25.0",
"expiringdict",
"dill",
"psutil",
]

service_requires = [
Expand Down Expand Up @@ -50,6 +51,11 @@
"black",
]

studio_requires = [
"appdirs",
"flask_sqlalchemy",
]

# released requires
minimal_requires = [
"docstring_parser",
Expand Down Expand Up @@ -85,6 +91,7 @@
+ doc_requires
+ test_requires
+ gradio_requires
+ studio_requires
)

with open("README.md", "r", encoding="UTF-8") as fh:
Expand Down
2 changes: 1 addition & 1 deletion src/agentscope/web/studio/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def close_a_request(cls, run_id: str, agent_id: str) -> None:
cls._requests[run_id].pop(agent_id)


class Run(db.Model):
class Run(db.Model): # type: ignore[name-defined]
"""Runtime object."""

run_id = db.Column(db.String, primary_key=True)
Expand Down
7 changes: 7 additions & 0 deletions src/agentscope/web/studio/static/css/workstation.css
Original file line number Diff line number Diff line change
Expand Up @@ -832,4 +832,11 @@ pre[class*="language-"] {
to {
opacity: 1;
}
}

.text-input {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.2;
resize: vertical;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<br>

<label>System prompt</label>
<input type="text" df-args-sys_prompt
placeholder="You're an assistant." data-required="true">
<textarea type="text" df-args-sys_prompt class="text-input"
placeholder="You're an assistant." data-required="true"></textarea>
<br>

<label>Model config name</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<br>

<label>System prompt</label>
<input type="text" df-args-sys_prompt
placeholder="You're an assistant." data-required="true">
<textarea type="text" df-args-sys_prompt class="text-input"
placeholder="You're an assistant." data-required="true"></textarea>
<br>

<label>Model config name</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
<br>

<label>System prompt</label>
<input type="text" df-args-sys_prompt
placeholder="You're an assistant.">
<textarea type="text" df-args-sys_prompt class="text-input"
placeholder="You're an assistant."
data-required="true"></textarea>
<br>

<label>Model config name</label>
Expand Down
32 changes: 15 additions & 17 deletions src/agentscope/web/studio/static/js/workstation.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async function initializeWorkstationPage() {
setupNodeListeners(id);
setupNodeCopyListens(id);
addEventListenersToNumberInputs(id);
setupTextInputListeners(id);
})

editor.on('nodeRemoved', function (id) {
Expand Down Expand Up @@ -769,6 +770,20 @@ async function addNodeToDrawFlow(name, pos_x, pos_y) {
}
}

function setupTextInputListeners(nodeId) {
const newNode = document.getElementById(`node-${nodeId}`);
if (newNode) {
const stopPropagation = function(event) {
event.stopPropagation();
};
newNode.addEventListener('mousedown', function(event) {
const target = event.target;
if (target.tagName === 'TEXTAREA' || target.tagName === 'INPUT') {
stopPropagation(event);
}
}, false);
}
}

function toggleAdvanced() {
var advancedBox = document.querySelector('.advanced-box');
Expand Down Expand Up @@ -1260,7 +1275,6 @@ function checkConditions() {
console.log("node", node);
console.log("node.inputs", node.inputs);


if (node.inputs) {
for (let inputKey in node.inputs) {
if (node.inputs[inputKey].connections &&
Expand All @@ -1277,22 +1291,6 @@ function checkConditions() {
}
}

if (node.outputs) {
for (let outputKey in node.outputs) {
if (node.outputs[outputKey].connections &&
node.outputs[outputKey].connections.length > 1) {
Swal.fire({
title: 'Invalid Connections',
text:
`${node.name} has more than one connection in outputs.`,
icon: 'error',
confirmButtonText: 'Ok'
});
return false;
}
}
}

let nodeElement = document.getElementById('node-' + nodeId);
const requiredInputs = nodeElement.querySelectorAll('input[data-required="true"]');

Expand Down

0 comments on commit b81b935

Please sign in to comment.