Skip to content

Commit

Permalink
chore: improved text formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Aug 21, 2023
1 parent 02fca90 commit ef7ce00
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 25 deletions.
3 changes: 2 additions & 1 deletion apps/browser/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "./Chat.css";
export interface ChatMessage {
text: string;
user: string;
color?: string;
}

export interface ChatProps {
Expand Down Expand Up @@ -101,7 +102,7 @@ const Chat: React.FC<ChatProps> = ({ evo, onMessage, messages }: ChatProps) => {
{messages.map((msg, index) => (
<div key={index} className={`MessageContainer ${msg.user}`}>
<div className="SenderName">{msg.user.toUpperCase()}</div>
<div className={`Message ${msg.user}`}>
<div className={`Message ${msg.user}`} style={msg.color ? { borderColor: msg.color } : undefined}>
<ReactMarkdown>{msg.text}</ReactMarkdown>
</div>
</div>
Expand Down
18 changes: 12 additions & 6 deletions apps/browser/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Sidebar = ({ onSettingsClick, scripts, userFiles, uploadUserFiles }: Sideb
<h3>
<FontAwesomeIcon icon={faUserNinja} /> SCRIPTS
</h3>
{scripts.map((file, i) => (
{scripts.filter((file) => !file.path.startsWith("agent.")).map((file, i) => (
<File file={file} />
))}
</div>
Expand All @@ -44,11 +44,17 @@ const Sidebar = ({ onSettingsClick, scripts, userFiles, uploadUserFiles }: Sideb
<footer className="Footer">
<div className="Polywrap">
<span className="BuiltWithLove">Built with love by</span>
<img
src="polywrap-logo.png"
alt="Image Banner"
className="ImageBanner"
/>
<a
href="https://polywrap.io"
target="_blank"
rel="noopener noreferrer"
>
<img
src="polywrap-logo.png"
alt="Image Banner"
className="ImageBanner"
/>
</a>
</div>
<div className="Footer__Links">
<a
Expand Down
7 changes: 4 additions & 3 deletions apps/browser/src/pages/Dojo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ function Dojo() {
setDojoError(undefined);

const markdownLogger = new MarkdownLogger({
onLog: (markdown: string) => {
onLog: (markdown: string, color?: string) => {
onMessage({
user: "evo",
text: markdown
})
text: markdown,
color
});
}
});
const logger = new EvoCore.Logger([
Expand Down
16 changes: 11 additions & 5 deletions apps/browser/src/sys/logger/MarkdownLogger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ILogger, Message } from "@evo-ninja/core";

export interface MarkdownLoggerConfig {
onLog(markdown: string): void;
onLog(markdown: string, color?: string): void;
}

export class MarkdownLogger implements ILogger {
Expand Down Expand Up @@ -32,18 +32,24 @@ export class MarkdownLogger implements ILogger {
}

notice(msg: string): void {
this._config.onLog(msg, "cyan");
}

success(msg: string): void {
this._config.onLog(
`**Notice!**\n${msg}`
`**Success!**\n${msg}`,
"green"
);
}

success(msg: string): void {
warning(msg: string): void {
this._config.onLog(
`**Success!**\n${msg}`
`**Warning:** ${msg}`,
"yellow"
);
}

error(msg: string): void {
this._config.onLog(`**ERROR:**\n${msg}`);
this._config.onLog(`**ERROR:**\n${msg}`, "red");
}
}
4 changes: 4 additions & 0 deletions apps/cli/src/sys/FileLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class FileLogger implements ILogger {
this.info(msg + "\n \n");
}

warning(msg: string): void {
this.info(msg + "\n \n");
}

error(msg: string): void {
this.info(msg + "\n \n");
}
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/agents/agent-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Workspace, Logger } from "../sys";
import { Scripts } from "../Scripts";
import { WrapClient } from "../wrap";
import { LlmApi, Chat } from "../llm";
import { trimText } from "./utils";
import JSON5 from "json5";

export interface AgentContext {
Expand Down Expand Up @@ -56,7 +55,7 @@ export const executeAgentFunction: ExecuteAgentFunction = async (
const fnName = name as string;

const argsStr = JSON.stringify(fnArgs, null, 2);
let functionCallSummary = `Function call: \`${fnName}(${argsStr})\`\n`;
let functionCallSummary = `# Function Call:\n\`\`\`javascript\n${fnName}(${argsStr})\n\`\`\`\n`;

const executor = func.buildExecutor(context);

Expand All @@ -67,7 +66,6 @@ export const executeAgentFunction: ExecuteAgentFunction = async (
}

if (fnName === "executeScript") {
functionCallSummary += `Result stored into global var: \`{{${fnArgs.result}}}\`. Preview: \`${trimText(response.result, 200)}\`\n`;
functionCallSummary += EXECUTE_SCRIPT_OUTPUT(fnArgs.result, response.result);
} else if (fnName === "readVar") {
functionCallSummary += READ_GLOBAL_VAR_OUTPUT(fnArgs.name, response.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function createScript(createScriptWriter: () => ScriptWriter): AgentFunct
while(true) {
const response = await iterator.next();

response.value.message && context.logger.notice(response.value.message);
response.value.message && context.logger.info(response.value.message);

// TODO: we should not be communicating the ScriptWriter's completion
// via a special file in the workspace
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/agents/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export const UNDEFINED_FUNCTION_ARGS = (name: string) =>
`Function call argument for '${name}' were undefined.`;

export const FUNCTION_CALL_FAILED = (name: string, error: string, args: string | undefined) =>
`The function '${name}' failed, this is the error:\n----------\n${
`The function '${name}' failed, this is the error:\n\`\`\`\n${
error && typeof error === "string"
? trimText(error, 300)
: "Unknown error."
}\nJSON Arguments: ${args}\n----------\\n`;
}\n\`\`\`\n\nArguments:\n\`\`\`\n${args}\n\`\`\``;

export const READ_GLOBAL_VAR_OUTPUT = (name: string, value: string) =>
`Global var '{{${name}}}':\n\`\`\`${value}\`\`\`\n`;
`## Read Variable\n**'{{${name}}}'**:\n\`\`\`\n${value}\n\`\`\`\n`;

export const EXECUTE_SCRIPT_OUTPUT = (varName: string, result: string) =>
`Result stored into global var: \`{{${varName}}}\`. Preview: \`${trimText(result, 200)}\`\n`;
`## Result\nPreview: \`\`\`\n${trimText(result, 200)}\`\`\`\n\nResult Stored in Variable: \`{{${varName}}}\`\n`;

export const OTHER_EXECUTE_FUNCTION_OUTPUT = (result: string) =>
`Result: \`${result}\`\n`;
`## Result\n\`\`\`\n${result}\n\`\`\``;
2 changes: 1 addition & 1 deletion packages/core/src/llm/OpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class OpenAI implements LlmApi {

// If a rate limit error is thrown
if (maybeOpenAiError.status === 429) {
this._logger.notice("Warning: OpenAI rate limit exceeded, sleeping for 15 seconds.");
this._logger.warning("Warning: OpenAI rate limit exceeded, sleeping for 15 seconds.");

// Try again after a short sleep
await new Promise((resolve) => setTimeout(resolve, 15000));
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/sys/logger/ConsoleLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class ConsoleLogger implements ILogger {
this.info(chalk.green(msg));
}

warning(msg: string): void {
this.info(chalk.yellow(msg));
}

error(msg: string): void {
this.info(chalk.red(msg));
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/sys/logger/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ILogger {
action: (msg: Message) => void;
notice: (msg: string) => void;
success: (msg: string) => void;
warning: (msg: string) => void;
error: (msg: string, error?: unknown) => void;
}

Expand Down Expand Up @@ -44,6 +45,10 @@ export class Logger implements ILogger {
this._loggers.forEach((l) => l.success(msg));
}

warning(msg: string) {
this._loggers.forEach((l) => l.warning(msg));
}

error(msg: string, error?: unknown) {
if (!error) {
this._loggers.forEach((l) => l.error(msg));
Expand Down

0 comments on commit ef7ce00

Please sign in to comment.