Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gabehamilton committed Apr 11, 2024
1 parent a558249 commit a76bb78
Show file tree
Hide file tree
Showing 15 changed files with 950 additions and 706 deletions.
2 changes: 1 addition & 1 deletion nexus/components/src/Agent/AgentBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
// model protections: guardrails: jailbreak semantic analysis, behavior limits
// data protections: compliance proofs, encryption, access control,
// logging & monitoring
// UI component(s).
// UI component(s).
34 changes: 22 additions & 12 deletions nexus/components/src/Agent/AgentCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (!href) {
return <></>;
}

const {namespace, entityType, schemaFile} = props;
const { namespace, entityType, schemaFile } = props;

const Card = styled.div`
cursor: pointer;
Expand Down Expand Up @@ -48,13 +48,12 @@ const Card = styled.div`
font-weight: 400;
}
`;
const CardText = styled.div`
`;
const CardText = styled.div``;
const Prompt = styled.span`
color: grey;
color: grey;
`;
const PromptTooltip = styled.span`
white-space: pre-line;
white-space: pre-line;
`;
const Actions = styled.div`
padding-top: 16px;
Expand All @@ -64,22 +63,31 @@ const Actions = styled.div`
`;
const AgentCard = ({ item, editFunction }) => {
const { accountId, name, displayName, prompt, logoUrl } = item;
const agentComponent = item.component ? item.component : `${REPL_AGIGUILD}/widget/Agent.AgentChat`;
const imageUrl = logoUrl ?
logoUrl : "https://ipfs.near.social/ipfs/bafkreibysr2mkwhb4j36h2t7mqwhynqdy4vzjfygfkfg65kuspd2bawauu";
const agentComponent = item.component
? item.component
: `${REPL_AGIGUILD}/widget/Agent.AgentChat`;
const imageUrl = logoUrl
? logoUrl
: "https://ipfs.near.social/ipfs/bafkreibysr2mkwhb4j36h2t7mqwhynqdy4vzjfygfkfg65kuspd2bawauu";
const actionLink = href({
widgetSrc: agentComponent,
params: { src: `${accountId}/agent/${name}` },
});
const detailsLink = href({
widgetSrc: `${REPL_AGIGUILD}/widget/Agent.AgentDetails`,
params: { src: `${accountId}/agent/${name}`, schemaFile, namespace, entityType },
widgetSrc: `${REPL_AGIGUILD}/widget/Agent.AgentDetails`,
params: {
src: `${accountId}/agent/${name}`,
schemaFile,
namespace,
entityType,
},
});

const actionUrl = `https://${REPL_NEAR_URL}/${agentComponent}?src=${accountId}/agent/${item.name}`;
const editType = accountId === context.accountId ? "edit" : "fork";
const editLabel = editType === "edit" ? "Edit" : "Fork";
const editIcon = editType === "edit" ? "ph-bold ph-pencil-simple" : "ph-bold ph-git-fork";
const editIcon =
editType === "edit" ? "ph-bold ph-pencil-simple" : "ph-bold ph-git-fork";

return (
<Card>
Expand All @@ -96,7 +104,9 @@ const AgentCard = ({ item, editFunction }) => {
src="${REPL_ACCOUNT}/widget/DIG.Tooltip"
props={{
content: <PromptTooltip>{prompt}</PromptTooltip>,
trigger: <Prompt>{prompt ? prompt.substring(0, 50) : ""}...</Prompt>,
trigger: (
<Prompt>{prompt ? prompt.substring(0, 50) : ""}...</Prompt>
),
}}
/>
</CardText>
Expand Down
50 changes: 34 additions & 16 deletions nexus/components/src/Agent/AgentChat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ const [loading, setLoading] = useState(false);
const [messages, setMessages] = useState([]);

const [model, setModel] = useState(storedModel ?? "near-llama-7b");
const [localModel, setLocalModel] = useState(storedLocalModel ?? "http://localhost:1234/v1/chat/completions");
const [credentialType, setCredentialType] = useState(storedCredentialType ?? "bearer");
const [localModel, setLocalModel] = useState(
storedLocalModel ?? "http://localhost:1234/v1/chat/completions",
);
const [credentialType, setCredentialType] = useState(
storedCredentialType ?? "bearer",
);
const [credential, setCredential] = useState(storedCredential ?? "");
const [jsonOutputSetting, setJsonOutputSetting] = useState(storedJsonOutputSetting ?? false);
const [jsonOutputSetting, setJsonOutputSetting] = useState(
storedJsonOutputSetting ?? false,
);

useEffect(() => {
Storage.set("agent-model", model);
Expand Down Expand Up @@ -131,10 +137,7 @@ const openAICompatible = async (question) => {
responseType: "json",
body: JSON.stringify({
...options,
messages: [
{ role: "system", content: data.prompt },
...messages,
],
messages: [{ role: "system", content: data.prompt }, ...messages],
}),
}).then((response) => {
const answer = response.body.choices[0].message.content;
Expand Down Expand Up @@ -162,7 +165,10 @@ const submitQuestion = () => {
};
const requiresCredentials = (model) => {
return (
model === "gpt-4" || model === "gpt-3.5-turbo" || model === "mixtral-8x7b-32768" || model === "llama2-70b-4096"
model === "gpt-4" ||
model === "gpt-3.5-turbo" ||
model === "mixtral-8x7b-32768" ||
model === "llama2-70b-4096"
);
};

Expand Down Expand Up @@ -237,7 +243,8 @@ const renderSettings = () => {
return (
<Settings>
<CardControl bold onClick={toggleSettings}>
<i className={settingsOpen ? "ph ph-caret-up" : "ph ph-caret-down"} /> Settings
<i className={settingsOpen ? "ph ph-caret-up" : "ph ph-caret-down"} />{" "}
Settings
</CardControl>
{settingsOpen && (
<AllSettings>
Expand Down Expand Up @@ -307,7 +314,8 @@ const renderSettings = () => {
src="${REPL_ACCOUNT}/widget/DIG.Input"
props={{
label: "Local Model URL",
assistiveText: "Any url that accepts messages in OpenAI format",
assistiveText:
"Any url that accepts messages in OpenAI format",
iconLeft: "ph-bold ph-horse",
onInput: (e) => setLocalModel(e.target.value),
value: localModel,
Expand Down Expand Up @@ -345,7 +353,8 @@ const renderSettings = () => {
src="${REPL_ACCOUNT}/widget/DIG.Input"
props={{
label: "Credentials",
assistiveText: "Your OpenAI API Key or other credentials, will be stored in your browser.",
assistiveText:
"Your OpenAI API Key or other credentials, will be stored in your browser.",
iconLeft: "ph-bold ph-identification-card",
onInput: (e) => setCredential(e.target.value),
value: credential,
Expand Down Expand Up @@ -409,8 +418,8 @@ return (
{renderSettings()}
{requiresCredentials(model) && credential === "" && (
<div className="alert alert-danger mx-3" role="alert">
<i className="ph ph-alert-circle" /> To use an OpenAI or Groq model enter your API Key in Settings or change
to another provider.
<i className="ph ph-alert-circle" /> To use an OpenAI or Groq model
enter your API Key in Settings or change to another provider.
</div>
)}
<div className="input-group">
Expand All @@ -436,7 +445,9 @@ return (
fill: "solid",
size: "large",
label: "Submit",
disabled: (requiresCredentials(model) && credential === "") || question === "",
disabled:
(requiresCredentials(model) && credential === "") ||
question === "",
style: {
borderTopLeftRadius: "0rem",
borderBottomLeftRadius: "0rem",
Expand All @@ -451,7 +462,10 @@ return (
<div key={i} className={`message ${role}`}>
{role === "user" && (
<UserMessage>
<Widget src="${REPL_MOB}/widget/N.ProfileLine" props={{ accountId: context.accountId }} />
<Widget
src="${REPL_MOB}/widget/N.ProfileLine"
props={{ accountId: context.accountId }}
/>
<Markdown text={content} />
</UserMessage>
)}
Expand All @@ -466,7 +480,11 @@ return (
{loading && (
<div key="loading" className={`message system`}>
<div>
<span className="spinner-grow spinner-grow-sm me-1" role="status" aria-hidden="true" />
<span
className="spinner-grow spinner-grow-sm me-1"
role="status"
aria-hidden="true"
/>
</div>
</div>
)}
Expand Down
38 changes: 29 additions & 9 deletions nexus/components/src/Agent/AgentDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,43 @@ let { src, tab, schemaFile, namespace } = props;

const summaryComponent = "${REPL_AGIGUILD}/widget/Agent.AgentSummary";
const customComponentLabel = (component) => {
if (component === `agiguild.near/widget/Agent.AgentChat`) {
return "Chat";
}
return <Widget src="${REPL_ACCOUNT}/widget/DIG.Tooltip" props={{ content: <p>{component}</p>, trigger: "Chat (Custom component)"}} />;
}
if (component === `agiguild.near/widget/Agent.AgentChat`) {
return "Chat";
}
return (
<Widget
src="${REPL_ACCOUNT}/widget/DIG.Tooltip"
props={{
content: <p>{component}</p>,
trigger: "Chat (Custom component)",
}}
/>
);
};

const additionalTabs = (entity) => {
const agentComponent = entity.component ? entity.component : `${REPL_AGIGUILD}/widget/Agent.AgentChat`;
const agentComponent = entity.component
? entity.component
: `${REPL_AGIGUILD}/widget/Agent.AgentChat`;

return {
name: customComponentLabel(agentComponent),
value: "chat",
content: <Widget src={agentComponent} props={{ src, embedded: true }} />,
icon: "ph ph-code",
}};
};
};

return (
<Widget src="${REPL_ACCOUNT}/widget/Entities.Template.EntityDetails"
props={{ src, tab, schemaFile, namespace, summaryComponent, additionalTabs }} />
<Widget
src="${REPL_ACCOUNT}/widget/Entities.Template.EntityDetails"
props={{
src,
tab,
schemaFile,
namespace,
summaryComponent,
additionalTabs,
}}
/>
);
27 changes: 16 additions & 11 deletions nexus/components/src/Agent/AgentEntityConfig.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
const convertSnakeToPascal = (item) => {
const newItems = {};
Object.keys(item).forEach((key) => {
const newItems = {};
Object.keys(item).forEach((key) => {
const pascalKey = key.replace(/(_\w)/g, (m) => m[1].toUpperCase());
newItems[pascalKey] = item[key];
});
return newItems;
};
const renderItem = (item, editFunction) => {
const flatItem = {...item, ...item.attributes};
const flatItem = { ...item, ...item.attributes };
delete flatItem.attributes;
return (
<Widget
src="${REPL_AGIGUILD}/widget/Agent.AgentCard"
props={{
item: convertSnakeToPascal(flatItem),
editFunction,
namespace: 'near',
entityType: 'agent',
namespace: "near",
entityType: "agent",
schemaFile: "${REPL_AGIGUILD}/widget/Schema.Agent",
}}
/>
);
};
return (
<Widget src="${REPL_ACCOUNT}/widget/Entities.Template.GenericEntityConfig"
props={{namespace: 'near', entityType: 'agent', title: 'Agent',
schemaFile: "${REPL_AGIGUILD}/widget/Schema.Agent",
renderItem,
}}/>
)
<Widget
src="${REPL_ACCOUNT}/widget/Entities.Template.GenericEntityConfig"
props={{
namespace: "near",
entityType: "agent",
title: "Agent",
schemaFile: "${REPL_AGIGUILD}/widget/Schema.Agent",
renderItem,
}}
/>
);
24 changes: 18 additions & 6 deletions nexus/components/src/Agent/AgentSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ if (!href) {
}

const { entity, showActions } = props;
const { accountId, name, displayName, prompt, logoUrl, tags, component } = entity;
const { accountId, name, displayName, prompt, logoUrl, tags, component } =
entity;

const agentComponent = item.component ? item.component : `${REPL_AGIGUILD}/widget/Agent.AgentChat`;
const agentComponent = item.component
? item.component
: `${REPL_AGIGUILD}/widget/Agent.AgentChat`;
const chatLink = href({
widgetSrc: agentComponent,
params: { src: `${accountId}/agent/${name}` },
Expand Down Expand Up @@ -156,7 +159,8 @@ return (
src="${REPL_MOB}/widget/Image"
props={{
image: { url: logoUrl },
fallbackUrl: "https://ipfs.near.social/ipfs/bafkreibysr2mkwhb4j36h2t7mqwhynqdy4vzjfygfkfg65kuspd2bawauu",
fallbackUrl:
"https://ipfs.near.social/ipfs/bafkreibysr2mkwhb4j36h2t7mqwhynqdy4vzjfygfkfg65kuspd2bawauu",
alt: name,
}}
/>
Expand Down Expand Up @@ -192,7 +196,8 @@ return (
src="${REPL_ACCOUNT}/widget/DIG.Button"
props={{
label: "Delete",
disabled: !context.accountId || context.accountId !== accountId,
disabled:
!context.accountId || context.accountId !== accountId,
// onClick: () => delete(agent.name),
iconLeft: "ph-bold ph-trash",
variant: "destructive",
Expand Down Expand Up @@ -228,9 +233,16 @@ return (
},
notifyAccountId: accountId,
button: (starCount, starIsActive, starOnClick) => (
<Button type="button" onClick={starOnClick} aria-label="Star this agent">
<Button
type="button"
onClick={starOnClick}
aria-label="Star this agent"
>
{starIsActive ? (
<i className="bi bi-star-fill" style={{ color: "var(--amber10)" }} />
<i
className="bi bi-star-fill"
style={{ color: "var(--amber10)" }}
/>
) : (
<i className="bi bi-star" />
)}{" "}
Expand Down
23 changes: 9 additions & 14 deletions nexus/components/src/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ const Instructions = styled.div`
color: #555;
`;
return (
<div>
<div>
<Instructions>
<p>This is your personal Dashboard</p>
<p>This is your personal Dashboard</p>

<div style={{paddingLeft: "2em"}}>
<p>
It will contain
</p>
<p>
Usage of Agents, Datasets, etc that you have contributed.
</p>
<p>
Your favorite Agents.
</p>
</div>
<div style={{ paddingLeft: "2em" }}>
<p>It will contain</p>
<p>Usage of Agents, Datasets, etc that you have contributed.</p>
<p>Your favorite Agents.</p>
</div>
</Instructions>
</div>)
</div>
);
Loading

0 comments on commit a76bb78

Please sign in to comment.