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

added description to entity variables #13

Merged
merged 3 commits into from
Aug 1, 2022
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
79 changes: 49 additions & 30 deletions packages/client/src/workspaces/spells/windows/EntityWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ const EntityWindow = ({ id, updateCallback }) => {
useState('')
const [twitter_auto_tweet_interval_max, setTwitterAutoTweetIntervalMax] =
useState('')
const [twitter_auto_tweet_start_phrases, setTwitterAutoTweetStartPhrases] =
useState('')
const [twitter_bot_name, setTwitterBotName] = useState('')
const [twitter_bot_name_regex, setTwitterBotNameRegex] = useState('')
const [twitter_spell_handler_incoming, setTwitterSpellHandlerIncoming] =
useState('')
const [twitter_spell_handler_auto, setTwitterSpellHandlerAuto] = useState('')

const [telegram_enabled, setTelegramEnabled] = useState('')
const [telegram_bot_token, setTelegramBotToken] = useState('')
Expand Down Expand Up @@ -256,12 +255,10 @@ const EntityWindow = ({ id, updateCallback }) => {
setTwitterTweetRules(res.data.twitter_tweet_rules)
setTwitterAutoTweetIntervalMin(res.data.twitter_auto_tweet_interval_min)
setTwitterAutoTweetIntervalMax(res.data.twitter_auto_tweet_interval_max)
setTwitterAutoTweetStartPhrases(
res.data.twitter_auto_tweet_start_phrases
)
setTwitterBotName(res.data.twitter_bot_name)
setTwitterBotNameRegex(res.data.twitter_bot_name_regex)
setTwitterSpellHandlerIncoming(res.data.twitter_spell_handler_incoming)
setTwitterSpellHandlerAuto(res.data.twitter_spell_handler_auto)

setTelegramEnabled(res.data.telegram_enabled === true)
setTelegramBotToken(res.data.telegram_bot_token)
Expand Down Expand Up @@ -403,10 +400,10 @@ const EntityWindow = ({ id, updateCallback }) => {
twitter_tweet_rules,
twitter_auto_tweet_interval_min,
twitter_auto_tweet_interval_max,
twitter_auto_tweet_start_phrases,
twitter_bot_name,
twitter_bot_name_regex,
twitter_spell_handler_incoming,
twitter_spell_handler_auto,
telegram_enabled,
telegram_bot_token,
telegram_bot_name,
Expand Down Expand Up @@ -515,14 +512,12 @@ const EntityWindow = ({ id, updateCallback }) => {
setTwitterAutoTweetIntervalMax(
responseData.twitter_auto_tweet_interval_max
)
setTwitterAutoTweetStartPhrases(
responseData.twitter_auto_tweet_start_phrases
)
setTwitterBotName(responseData.twitter_bot_name)
setTwitterBotNameRegex(responseData.twitter_bot_name_regex)
setTwitterSpellHandlerIncoming(
responseData.twitter_spell_handler_incoming
)
setTwitterSpellHandlerAuto(responseData.twitter_spell_handler_auto)

setTelegramEnabled(responseData.telegram_enabled)
setTelegramBotToken(responseData.telegram_bot_token)
Expand Down Expand Up @@ -641,10 +636,10 @@ const EntityWindow = ({ id, updateCallback }) => {
twitter_tweet_rules,
twitter_auto_tweet_interval_min,
twitter_auto_tweet_interval_max,
twitter_auto_tweet_start_phrases,
twitter_bot_name,
twitter_bot_name_regex,
twitter_spell_handler_incoming,
twitter_spell_handler_auto,
telegram_enabled,
telegram_bot_token,
telegram_bot_name,
Expand Down Expand Up @@ -877,7 +872,9 @@ const EntityWindow = ({ id, updateCallback }) => {
</div>

<div className="form-item">
<span className="form-item-label">Voice Default Phrases</span>
<span className="form-item-label">
Voice Default Phrases - Separate using | (n1|n2|...|nN)
</span>
<input
type="text"
defaultValue={voice_default_phrases}
Expand All @@ -889,7 +886,10 @@ const EntityWindow = ({ id, updateCallback }) => {

{voice_provider === 'tiktalknet' && (
<div className="form-item">
<span className="form-item-label">Tiktalknet URL</span>
<span className="form-item-label">
Tiktalknet URL - URL where Tiktalknet is hosted and the requests
will be sent there
</span>
<input
type="text"
defaultValue={tiktalknet_url}
Expand Down Expand Up @@ -936,7 +936,9 @@ const EntityWindow = ({ id, updateCallback }) => {
</div>

<div className="form-item">
<span className="form-item-label">Discord Starting Words</span>
<span className="form-item-label">
Discord Starting Words - Separated by ,
</span>
<input
type="text"
defaultValue={discord_starting_words}
Expand Down Expand Up @@ -969,7 +971,9 @@ const EntityWindow = ({ id, updateCallback }) => {
</div>

<div className="form-item">
<span className="form-item-label">Discord Empty Responses</span>
<span className="form-item-label">
Discord Empty Responses - Separated by |
</span>
<input
type="text"
defaultValue={discord_empty_responses}
Expand Down Expand Up @@ -1123,7 +1127,9 @@ const EntityWindow = ({ id, updateCallback }) => {
</div>

<div className="form-item">
<span className="form-item-label">Empty Responses</span>
<span className="form-item-label">
Empty Responses - Separated by |
</span>
<input
type="text"
defaultValue={xrengine_empty_responses}
Expand Down Expand Up @@ -1275,7 +1281,7 @@ const EntityWindow = ({ id, updateCallback }) => {
/>
</div>
<div className="form-item">
<span className="form-item-label">Twitter Enable Twits</span>
<span className="form-item-label">Twitter Enable Tweets</span>
<input
type="checkbox"
value={twitter_enable_twits}
Expand All @@ -1288,7 +1294,10 @@ const EntityWindow = ({ id, updateCallback }) => {
/>
</div>
<div className="form-item">
<span className="form-item-label">Twitter Tweet Rules</span>
<span className="form-item-label">
Twitter Tweet Rules - Regex rules for tweets to answer
automatically, Separated by ,
</span>
<input
type="text"
defaultValue={twitter_tweet_rules}
Expand Down Expand Up @@ -1321,18 +1330,6 @@ const EntityWindow = ({ id, updateCallback }) => {
}}
/>
</div>
<div className="form-item">
<span className="form-item-label">
Twitter Auto Start Phrases
</span>
<input
type="text"
defaultValue={twitter_auto_tweet_start_phrases}
onChange={e => {
setTwitterAutoTweetStartPhrases(e.target.value)
}}
/>
</div>
<div className="form-item">
<span className="form-item-label">Bot Name</span>
<input
Expand Down Expand Up @@ -1373,6 +1370,26 @@ const EntityWindow = ({ id, updateCallback }) => {
))}
</select>
</div>
<div className="form-item agent-select">
<span className="form-item-label">
Spell Handler (Auto tweets)
</span>
<select
name="spellHandlerIncoming"
id="spellHandlerIncoming"
value={twitter_spell_handler_auto}
onChange={event => {
setTwitterSpellHandlerAuto(event.target.value)
}}
>
{spellList.length > 0 &&
spellList.map((spell, idx) => (
<option value={spell.name} key={idx}>
{spell.name}
</option>
))}
</select>
</div>
</>
)}

Expand Down Expand Up @@ -1894,7 +1911,9 @@ const EntityWindow = ({ id, updateCallback }) => {
/>
</div>
<div className="form-item">
<span className="form-item-label">Empty Responses</span>
<span className="form-item-label">
Empty Responses - Separated by |
</span>
<input
type="text"
defaultValue={twilio_empty_responses}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { DocumentSetMass } from './search/DocumentSetMass'
import { RSSGet } from './search/RSSGet'
import { CustomTextCompletion } from './entities/CustomTextCompletion'
import { IsQuery } from './logic/IsQuery'
import { VariableReplacer } from './utility/VariableReplacer'

// Here we load up all components of the builder into our editor for usage.
// We might be able to programatically generate components from enki
Expand All @@ -91,6 +92,7 @@ export const components = {
entityDetector: () => new EntityDetector(),
complexStringMatcher: () => new ComplexStringMatcher(),
echo: () => new Echo(),
variableReplacer: () => new VariableReplacer(),
SummarizeFacts: () => new SummarizeFacts(),
textToSpeech: () => new TextToSpeech(),
agentTextCompletion: () => new AgentTextCompletion(),
Expand Down
6 changes: 0 additions & 6 deletions packages/core/src/components/entities/CustomTextCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ export class CustomTextCompletion extends ThothComponent<
data += (inputs['Static Chat'] as string) ?? '' + '\n'
data += inputs['Chat']
data += '\n' + agent + ':'
data = data
.replace(/ai/g, agent)
.replace(/agent/g, agent)
.replace(/human/g, speaker)
.replace(/speaker/g, speaker)
.replace(/\n/g, '\n')

const settings = ((rawInputs.settings && rawInputs.settings[0]) ??
{}) as any
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/components/entities/InputDestructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type InputReturn = {
isBot: boolean
info3d: string
}[]
channel_type: string
}

export class InputDestructureComponent extends ThothComponent<
Expand All @@ -52,6 +53,7 @@ export class InputDestructureComponent extends ThothComponent<
channel: 'output',
entity: 'output',
roomInfo: 'output',
channel_type: 'output',
trigger: 'option',
},
init: (task = {} as Task, node: ThothNode) => {
Expand All @@ -78,6 +80,11 @@ export class InputDestructureComponent extends ThothComponent<
const channelId = new Rete.Output('channel', 'channel', stringSocket)
const entity = new Rete.Output('entity', 'entity', stringSocket)
const roomInfo = new Rete.Output('roomInfo', 'roomInfo', arraySocket)
const channel_type = new Rete.Output(
'channel_type',
'channel_type',
stringSocket
)
const dataOutput = new Rete.Output('trigger', 'Trigger', triggerSocket)

return node
Expand All @@ -89,6 +96,7 @@ export class InputDestructureComponent extends ThothComponent<
.addOutput(channelId)
.addOutput(entity)
.addOutput(roomInfo)
.addOutput(channel_type)
.addOutput(out)
.addOutput(dataOutput)
}
Expand All @@ -115,6 +123,7 @@ export class InputDestructureComponent extends ThothComponent<
channel: (input as any)['ChannelID'] ?? 'TestChannel',
entity: (input as any)['Entity'],
roomInfo: (input as any)['RoomInfo'],
channel_type: (input as any)['Channel'],
}
}
}
106 changes: 106 additions & 0 deletions packages/core/src/components/utility/VariableReplacer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

/* eslint-disable no-async-promise-executor */
/* eslint-disable camelcase */
/* eslint-disable @typescript-eslint/no-inferrable-types */
/* eslint-disable no-console */
/* eslint-disable require-await */
/* eslint-disable @typescript-eslint/no-unused-vars */
import axios from 'axios'
import Rete from 'rete'

import {
NodeData,
ThothNode,
ThothWorkerInputs,
ThothWorkerOutputs,
EngineContext,
} from '../../../types'
import { InputControl } from '../../dataControls/InputControl'
import { SocketGeneratorControl } from '../../dataControls/SocketGenerator'
import { triggerSocket, stringSocket, anySocket } from '../../sockets'
import { ThothComponent } from '../../thoth-component'

const info =
'Variable Replacer is used to replace keywords with new values in a text input.'

type WorkerReturn = {
output: string
}

export class VariableReplacer extends ThothComponent<Promise<WorkerReturn>> {
constructor() {
super('Variable Replacer')

this.task = {
outputs: {
output: 'output',
trigger: 'option',
},
}

this.category = 'Agents'
this.display = true
this.info = info
}

builder(node: ThothNode) {
const strInput = new Rete.Input('inp', 'Input', stringSocket)
const agentInput = new Rete.Input('agent', 'Agent', stringSocket)
const speakerInput = new Rete.Input('speaker', 'Speaker', stringSocket)
const dataInput = new Rete.Input('trigger', 'Trigger', triggerSocket, true)
const dataOutput = new Rete.Output('trigger', 'Trigger', triggerSocket)
const outp = new Rete.Output('output', 'output', stringSocket)

const inputGenerator = new SocketGeneratorControl({
connectionType: 'input',
name: 'Input Sockets',
ignored: ['trigger'],
})

node.inspector.add(inputGenerator)

return node
.addInput(strInput)
.addInput(agentInput)
.addInput(speakerInput)
.addInput(dataInput)
.addOutput(dataOutput)
.addOutput(outp)
}

async worker(
node: NodeData,
rawInputs: ThothWorkerInputs,
outputs: ThothWorkerOutputs,
{ silent, thoth }: { silent: boolean; thoth: EngineContext }
) {
let input = rawInputs['inp'][0] as string
const agent = rawInputs['agent'][0] as string
const speaker = rawInputs['speaker'][0] as string
const inputs: any = Object.entries(rawInputs).reduce(
(acc, [key, value]) => {
console.log('key:', key, 'value:', value)
acc[key] = value[0]
return acc
},
{} as Record<string, unknown>
)

for (const key in inputs) {
if (input.includes(key)) {
if (key === 'agent') {
input = input.replace(key, agent)
} else if (key === 'speaker') {
input = input.replace(key, speaker)
} else {
input = input.replace(key, inputs[key])
}
}
}

return {
output: input,
}
}
}
Loading