Skip to content

Commit

Permalink
Merge pull request #83 from AGIUI/dev-0.3.8-shadow
Browse files Browse the repository at this point in the history
Dev 0.3.8 shadow
  • Loading branch information
shadowcz007 committed Jul 3, 2023
2 parents 94facea + b501dd4 commit eb657f8
Show file tree
Hide file tree
Showing 22 changed files with 409 additions and 326 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"tag":"test-用户输入-文案","role":{"name":"","text":"你是一位古诗词高手,会写诗"},"combo":2,"interfaces":["showInChat"],"isInfinite":false,"owner":"user","prompt":{"id":"USERINPUTTEXT_NVZIEYQ3H-TUWY0DRF9QM","type":"userInputText","inputs":{"nodes":[],"output":""},"userInput":"请输入性别","role":{"name":"","text":"你是一位古诗词高手,会写诗"}},"version":"0.3.0","app":"brainwave","id":"DG-E7g-s_AMnSkk0W-nHe","createDate":1688373247275,"prompt2":{"id":"PROMPT_BFCEJTGXUMV74I8TJCMQR","nextId":"","nodeInputId":"USERINPUTTEXT_NVZIEYQ3H-TUWY0DRF9QM","role":{"name":"","text":"你是一位古诗词高手,会写诗"},"text":"结合```${context}``` 写一个古诗词,并写成笑话","url":"","temperature":0.84,"model":"ChatGPT","input":"nodeInput","userInput":"","translate":"default","output":"default","type":"prompt","merged":null}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"tag":"输入网站后跳转","role":{"merged":[],"name":"","text":""},"combo":2,"interfaces":[],"isInfinite":false,"owner":"user","prompt":{"id":"USERINPUTTEXT_TF0RFB9YPR7HCZMCNWM8C","type":"userInputText","inputs":{"nodes":[],"output":""},"userInput":"请输入网站","role":{"merged":[],"name":"","text":""}},"version":"0.3.0","app":"brainwave","id":"3T2K8wncaKIuerL5rAxpW","createDate":1688374214203,"prompt2":{"id":"QUERYDEFAULT_D0WFIAV6LLXCNRRPLURWI","nextId":"","nodeInputId":"USERINPUTTEXT_TF0RFB9YPR7HCZMCNWM8C","role":{"merged":[],"name":"","text":""},"url":"","queryObj":{"action":"default","content":"bindCurrentPage","delay":1000,"protocol":"https://","query":"","url":"${context}"},"input":"nodeInput","userInput":"","type":"queryDefault"}}]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Earth",
"displayName": "Earth",
"version": "0.3.7.5",
"version": "0.3.8.0",
"description": "AGIUI for Browser Extension",
"license": "MIT",
"repository": {
Expand Down
29 changes: 20 additions & 9 deletions src/components/ChatbotMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,9 @@ class Main extends React.Component<{
})
}

_queryDefaultRun(queryObj: any, combo: any) {

QueryDefaultRun(queryObj, combo).then((res: any) => {
_queryDefaultRun(prompt: any, combo: any) {
const { queryObj, context } = prompt;
QueryDefaultRun(queryObj, context, combo).then((res: any) => {

this.updateChatBotStatus(false);

Expand Down Expand Up @@ -1420,7 +1420,7 @@ class Main extends React.Component<{
// 清空type thinking 的状态
nTalks = Talks.filter(nTalks)
nTalks.push(ChatBotConfig.createTalkData('ask-user-input', {
html: "请输入"
html: prompt.userInput || i18n.t('inputTitle')
}));
this._userInputTextRun()
}
Expand Down Expand Up @@ -1565,15 +1565,26 @@ class Main extends React.Component<{
if (this.state.chatBotStyle && this.state.chatBotStyle.value) promptJson.temperature = this.state.chatBotStyle.value;
}

// role 给调试用

if ([
'prompt',
'promptCustom',
'promptCustom'
].includes(promptJson.type)) {

if (!promptJson.model) promptJson.model = this.state.chatBotType;
if (!promptJson.temperature && this.state.chatBotStyle && this.state.chatBotStyle.value) promptJson.temperature = this.state.chatBotStyle.value;

this._llmRun(promptJson, newTalk);

};

// role 给调试用
if ([
'role',
].includes(promptJson.type)) {

if (!promptJson.prompt.model) promptJson.prompt.model = this.state.chatBotType;
if (!promptJson.prompt.temperature && this.state.chatBotStyle && this.state.chatBotStyle.value) promptJson.prompt.temperature = this.state.chatBotStyle.value;
promptJson.model = this.state.chatBotType;
if (this.state.chatBotStyle && this.state.chatBotStyle.value) promptJson.temperature = this.state.chatBotStyle.value;

this._llmRun(promptJson, newTalk);

Expand All @@ -1591,7 +1602,7 @@ class Main extends React.Component<{
};

// queryDefault 跳转页面
if (promptJson.type === 'queryDefault') this._queryDefaultRun(promptJson.queryObj, currentCombo);
if (promptJson.type === 'queryDefault') this._queryDefaultRun(promptJson, currentCombo);

// queryRead 读取
if (promptJson.type == "queryRead") this._queryReadRun(promptJson.queryObj);
Expand Down
3 changes: 2 additions & 1 deletion src/components/background/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ class Common {
Agent.executeScript(data.url, {
query: data.query,
text: data.text,
type: data.type
type: data.type,
delay: data.delay, //修复delay漏传的bug
}, data.combo)
} else if (cmd == "api-run") {
const { url, init, combo, promptId } = data;
Expand Down
5 changes: 3 additions & 2 deletions src/components/flow/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default (props: any) => {
onChange={onChange}
style={{
width: 180, userSelect: 'none',
background: 'white'
background: 'white',
}}>
<p style={{ paddingLeft: '24px' }}>{i18n.t('component')}</p>
{
Expand All @@ -39,8 +39,9 @@ export default (props: any) => {
<aside>
{
Array.from(node.children,
(child: any) => {
(child: any,i) => {
return <div
key={i}
style={{
outline: '1px solid #ddd',
borderRadius: '5px',
Expand Down
2 changes: 1 addition & 1 deletion src/components/flow/Workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const defaultNode = () => ({
temperature: 0.6,
model: 'ChatGPT',
input: 'nodeInput',// nodeInput、userInput
userInput: '',
userInput: '', // 用户输入节点-提示文案
translate: 'default',
output: 'default',
type: 'prompt',//运行时使用
Expand Down
17 changes: 10 additions & 7 deletions src/components/flow/nodeComponents/APINode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Handle, NodeProps, Position } from 'reactflow';
import { Card, Dropdown, Button, Popconfirm } from 'antd';

import { createCardTitle, createDebug, selectNodeInput, createURL, createSelect, createTextArea, nodeStyle, getI18n } from './Base';
import { createCardTitle, createDebug, SelectNodeInput, createURL, createSelect, createTextArea, nodeStyle, getI18n } from './Base';

import i18n from "i18next";
// import { i18nInit } from '../../locales/i18nConfig';
Expand Down Expand Up @@ -198,10 +198,13 @@ function Main({ id, data, selected }: any) {
}


{
selectNodeInput(i18n.t('getFromBefore'), nodeInputId, nodeOpts, updateData)
}

<SelectNodeInput
title={i18n.t('getFromBefore')}
nodeInputId={nodeInputId}
nodeOpts={nodeOpts}
onChange={updateData}
/>

{
createSelect(i18n.t('responseType'), responseType, [
{ value: 'text', label: i18n.t('text') },
Expand Down Expand Up @@ -282,7 +285,7 @@ function Main({ id, data, selected }: any) {
}


{
{/* {
createDebug(debugMenu, id,
debugInput,
data.debugOutput,
Expand Down Expand Up @@ -331,7 +334,7 @@ function Main({ id, data, selected }: any) {
statusInput: statusInputForDebug,
statusOutput: ""
})
}
} */}

</div>
</Card>
Expand Down
106 changes: 64 additions & 42 deletions src/components/flow/nodeComponents/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export const createCardTitle = (title: string, id: string, data: any) => {
alignItems: 'center'
}}>
<p style={{ marginBottom: 0 }}>{title}</p>
<Tooltip title={<TextArea
style={{
color:'white',
background:'none',
width:'480px',
fontSize:'12px'
}}
autoSize
value={JSON.stringify(parsePrompt({ ...data, id }), null, 2)} />} placement="rightBottom">
<InfoCircleOutlined style={{ marginBottom: 0 }} />
<Tooltip title={<TextArea
style={{
color: 'white',
background: 'none',
width: '480px',
fontSize: '12px'
}}
autoSize
value={JSON.stringify(parsePrompt({ ...data, id }), null, 2)} />} placement="rightBottom">
<InfoCircleOutlined style={{ marginBottom: 0 }} rev={undefined} />
</Tooltip>
</div>
<p style={{
Expand Down Expand Up @@ -95,7 +95,7 @@ export const createURL = (urlTitle: string, urlPlaceholder: string, protocol: st
</Select>
}
placeholder={urlPlaceholder}
value={displayedUrl}
defaultValue={displayedUrl}
onChange={handleUrlChange}
/>
</>
Expand Down Expand Up @@ -157,7 +157,7 @@ export const createTextArea = (title: string, value: string, placeholder: string
})}
onOpenChange={() => console.log('open change')}
>
<QuestionCircleOutlined style={{ fontSize: 20, color: '#cd201f', marginLeft: '8px' }} />
<QuestionCircleOutlined style={{ fontSize: 20, color: '#cd201f', marginLeft: '8px' }} rev={undefined} />
</Popconfirm> : ""}

</div>
Expand Down Expand Up @@ -237,12 +237,18 @@ export const selectNodeInputBase = (nodeInputId: string, nodeOpts: any, onChange


// 从上一节点获取文本
export const selectNodeInput = (title: string, nodeInputId: string, nodeOpts: any, onChange: any) => {
// console.log(nodeInputId,nodeOpts)
export const SelectNodeInput: any = (props: any) => {

let { title,
nodeInputId,
nodeOpts,
onChange } = props;

// console.log('selectNodeInput:', nodeOpts)
const [checked, setChecked] = React.useState(nodeOpts && nodeOpts[0] ?
nodeOpts.filter((n: any) => n.value === nodeInputId).length > 0 : false)

const [checked, setChecked] = React.useState(nodeOpts.filter((n: any) => n.value === nodeInputId).length > 0)

// console.log('selectNodeInput:', nodeOpts, nodeInputId, checked)
return <div
onMouseOver={() => {
onChange({
Expand All @@ -264,7 +270,7 @@ export const selectNodeInput = (title: string, nodeInputId: string, nodeOpts: an
// checked={input == "nodeInput"}
onChange={(e) => {
setChecked(e.target.checked)
if (!nodeInputId && nodeOpts[0] && nodeOpts[0].index === 1) nodeInputId = nodeOpts[0].value;
if (!nodeInputId && nodeOpts && nodeOpts[0] && nodeOpts[0].index === 1) nodeInputId = nodeOpts[0].value;
console.log("Checkbox ", nodeInputId, nodeOpts)
onChange({
key: 'nodeInput',
Expand All @@ -285,7 +291,7 @@ export const selectNodeInput = (title: string, nodeInputId: string, nodeOpts: an
data: e
})
}}
options={nodeOpts}
options={nodeOpts || []}
/>
<p style={{ marginTop: 0, color: "red", fontSize: 12 }}>{i18n.t('getFromBeforeTips')}</p>
</>
Expand All @@ -295,17 +301,17 @@ export const selectNodeInput = (title: string, nodeInputId: string, nodeOpts: an
}

// 选择输入,从用户输入 or 从节点
export const selectInput = (
nodeInputLabel: string,
userInputLabel: string,
nodeInputId: string,
userInput: string,
nodeOpts: any,
onChange: any) => {

// const [inp, setInp] = React.useState(nodeInputId ? 'nodeInput' : "userInput");
// console.log(inp)
const [uinp, setUserInput] = React.useState(userInput);

export const SelectInput: any = (props: any) => {

let { nodeInputLabel,
userInputLabel,
nodeInputId,
userInput,
nodeOpts,
onChange } = props;

const [uinp, setUserInput] = React.useState(userInput || '');
return <>
<Select
defaultValue={nodeInputId ? 'nodeInput' : "userInput"}
Expand Down Expand Up @@ -438,7 +444,7 @@ export const createDebug = (

<Collapse bordered={false}
size="small"
expandIcon={({ isActive }) => <CaretRightOutlined rotate={isActive ? 90 : 0} />}
expandIcon={({ isActive }) => <CaretRightOutlined rotate={isActive ? 90 : 0} rev={undefined} />}
style={{ background: '#eee', marginTop: '14px' }}
>
<Panel header={header} key="1">
Expand Down Expand Up @@ -555,7 +561,7 @@ export const createDelay = (title: string, delayFormat: string, delay: string, o
})
}}>
{
Array.from(opts, (o: any) => <Option value={o.value}>{o.label}</Option>)
Array.from(opts, (o: any, i) => <Option key={i} value={o.value}>{o.label}</Option>)
}
</Select>
}
Expand Down Expand Up @@ -644,20 +650,21 @@ export const parsePrompt = (data: any) => {
}

// 针对prompt的数据进行处理,只保留有用的
if ([
"queryRead",
"queryDefault",
"queryClick",
"queryInput"
].includes(prompt.type)) {
if (prompt.type.match('query') &&
prompt.type.startsWith('query')) {
delete prompt.api;
delete prompt.file;
delete prompt.inputs;
delete prompt.model;
delete prompt.temperature;
delete prompt.translate;
delete prompt.merged;
delete prompt.output;
delete prompt.text;
}

if ([
"prompt", "promptCustom"
].includes(prompt.type)) {
if (prompt.type.match('prompt') &&
prompt.type.startsWith('prompt')) {
delete prompt.api;
delete prompt.queryObj;
delete prompt.file;
Expand All @@ -670,20 +677,35 @@ export const parsePrompt = (data: any) => {
prompt = {
id: prompt.id,
type: prompt.type,
inputs: prompt.inputs
inputs: prompt.inputs,
userInput:prompt.userInput //提示文案
}
}

if (prompt.type == "api") {
delete prompt.queryObj;
delete prompt.file;
delete prompt.inputs;
delete prompt.model;
delete prompt.temperature;
delete prompt.translate;
delete prompt.merged;
delete prompt.output;
delete prompt.text;
}

if (prompt.type == "file") {

if (prompt.type.match('file') &&
prompt.type.startsWith('file')) {
delete prompt.api;
delete prompt.queryObj;
delete prompt.inputs;
delete prompt.model;
delete prompt.temperature;
delete prompt.translate;
delete prompt.merged;
delete prompt.output;
delete prompt.text;
}

if (prompt.type == 'role') {
Expand Down
12 changes: 10 additions & 2 deletions src/components/flow/nodeComponents/CustomPromptNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Card, Dropdown } from 'antd';

import i18n from "i18next";

import {createCardTitle, createDebug, selectNodeInput, createText, createSelect, createOutput, createModel, nodeStyle, getI18n } from './Base';
import {createCardTitle, createDebug, SelectNodeInput, createText, createSelect, createOutput, createModel, nodeStyle, getI18n } from './Base';
// import { i18nInit } from '../i18nConfig';


Expand Down Expand Up @@ -120,9 +120,17 @@ function Main({ id, data, selected }: any) {
createText('debugInput', i18n.t('custom'), '', debugInput, statusInputForDebug, updateData)
)
node.push(
selectNodeInput(i18n.t('getFromBefore'), selectNodeValue, nodeOpts, updateData)
<SelectNodeInput
title={i18n.t('getFromBefore')}
nodeInputId={selectNodeValue}
nodeOpts={nodeOpts}
onChange={updateData}
/>
)




node.push(createModel(model, temperature, models, updateData))

node.push(
Expand Down
Loading

0 comments on commit eb657f8

Please sign in to comment.