Skip to content

Commit

Permalink
fix coud
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 15, 2024
1 parent 9341e97 commit b9441d2
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 97 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "rollup -c && npm run build:types",
"build:types": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"lint": "eslint --ext .ts --ext .js . --fix",
"dev": "wrangler dev",
"dev": "wrangler dev -- --dev",
"shell:dev": "node --no-warnings scripts/shell.mjs --dev",
"concat": "node ./scripts/concat.mjs",
"shell:cloud": "node --no-warnings scripts/shell.mjs",
Expand Down
11 changes: 7 additions & 4 deletions src/agents/cj/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createClient, type SupabaseClient } from "@supabase/supabase-js";
import jwt from "@tsndr/cloudflare-worker-jwt";
import { type UUID } from "crypto";
import { DefaultActions } from "../../lib/actions";
import logger from "../../lib/logger";
import { BgentRuntime } from "../../lib/runtime";
import {
Expand All @@ -28,8 +27,7 @@ export function shouldSkipMessage(state: State, agentId: string): boolean {
const lastTwoMessagesFromAgent = lastThreeMessagesFromAgent.slice(-2);
const lastTwoMessagesFromAgentWithWaitAction =
lastTwoMessagesFromAgent.filter(
(message: Memory) =>
(message.content as Content).action === DefaultActions.WAIT,
(message: Memory) => (message.content as Content).action === "WAIT",
);
if (lastTwoMessagesFromAgentWithWaitAction.length === 2) {
return true;
Expand Down Expand Up @@ -64,6 +62,7 @@ interface HandlerArgs {
SUPABASE_URL: string;
SUPABASE_SERVICE_API_KEY: string;
OPENAI_API_KEY: string;
NODE_ENV: string;
};
match?: RegExpMatchArray;
userId: UUID;
Expand Down Expand Up @@ -96,8 +95,10 @@ const routes: Route[] = [

const message = await req.json();

console.log("NODE_ENV", env.NODE_ENV);

const runtime = new BgentRuntime({
debugMode: false,
debugMode: env.NODE_ENV === "development",
serverUrl: "https://api.openai.com/v1",
supabase,
token: env.OPENAI_API_KEY,
Expand Down Expand Up @@ -176,6 +177,7 @@ async function handleRequest(
SUPABASE_URL: string;
SUPABASE_SERVICE_API_KEY: string;
OPENAI_API_KEY: string;
NODE_ENV: string;
},
) {
const { pathname } = new URL(req.url);
Expand Down Expand Up @@ -260,6 +262,7 @@ export const fetch = async (
SUPABASE_URL: string;
SUPABASE_SERVICE_API_KEY: string;
OPENAI_API_KEY: string;
NODE_ENV: string;
},
) => {
try {
Expand Down
7 changes: 6 additions & 1 deletion src/agents/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface HandlerArgs {
SUPABASE_URL: string;
SUPABASE_SERVICE_API_KEY: string;
OPENAI_API_KEY: string;
NODE_ENV: string;
};
match?: RegExpMatchArray;
userId: UUID;
Expand Down Expand Up @@ -64,8 +65,10 @@ const routes: Route[] = [
// parse the body from the request
const message = await req.json();

console.log("NODE_ENV", env.NODE_ENV);

const runtime = new BgentRuntime({
debugMode: false,
debugMode: env.NODE_ENV === "development",
serverUrl: "https://api.openai.com/v1",
supabase,
token: env.OPENAI_API_KEY,
Expand Down Expand Up @@ -104,6 +107,7 @@ async function handleRequest(
SUPABASE_URL: string;
SUPABASE_SERVICE_API_KEY: string;
OPENAI_API_KEY: string;
NODE_ENV: string;
},
) {
const { pathname } = new URL(req.url);
Expand Down Expand Up @@ -189,6 +193,7 @@ export const fetch = async (
SUPABASE_URL: string;
SUPABASE_SERVICE_API_KEY: string;
OPENAI_API_KEY: string;
NODE_ENV: string;
},
) => {
try {
Expand Down
5 changes: 2 additions & 3 deletions src/lib/__tests__/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { type UUID } from "crypto";
import dotenv from "dotenv";
import { getCachedEmbedding, writeCachedEmbedding } from "../../test/cache";
import { createRuntime } from "../../test/createRuntime";
import { GetTellMeAboutYourselfConversationTroll1 } from "../../test/data";
import { getRelationship } from "../relationships";
import { type BgentRuntime } from "../runtime";
import { Content, type Message } from "../types";
import { GetTellMeAboutYourselfConversationTroll1 } from "../../test/data";
import { DefaultActions } from "../actions";

dotenv.config();

Expand Down Expand Up @@ -101,7 +100,7 @@ describe("User Profile", () => {

console.log("*** lastMessage", lastMessage.content);

expect((lastMessage.content as Content).action).toBe(DefaultActions.IGNORE);
expect((lastMessage.content as Content).action).toBe("IGNORE");
}, 60000);

test("Action handler test: continue", async () => {
Expand Down
6 changes: 0 additions & 6 deletions src/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import cont from "./actions/continue";
import ignore from "./actions/ignore";
import wait from "./actions/wait";

export enum DefaultActions {
WAIT = "WAIT",
CONTINUE = "CONTINUE",
IGNORE = "IGNORE",
}

export const defaultActions: Action[] = [cont, wait, ignore];

export const composeActionExamples = (actionsData: Action[], count: number) => {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/actions/__tests__/continue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getRelationship } from "../../relationships";
import { type BgentRuntime } from "../../runtime";
import { Content, type Message } from "../../types";
import action from "../continue";
import { DefaultActions } from "@/lib/actions";

dotenv.config();

Expand Down Expand Up @@ -84,7 +83,7 @@ describe("User Profile", () => {
content: {
content:
"Hmm, let think for a second, I was going to tell you about something...",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
room_id: room_id as UUID,
};
Expand Down
3 changes: 1 addition & 2 deletions src/lib/actions/__tests__/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getRelationship } from "../../relationships";
import { type BgentRuntime } from "../../runtime";
import { type Message } from "../../types";
import action from "../continue";
import { DefaultActions } from "@/lib/actions";

dotenv.config();

Expand Down Expand Up @@ -80,7 +79,7 @@ describe("User Profile", () => {
senderId: zeroUuid as UUID,
agentId: zeroUuid,
userIds: [user?.id as UUID, zeroUuid],
content: { content: "", action: DefaultActions.CONTINUE },
content: { content: "", action: "CONTINUE" },
room_id: room_id as UUID,
};

Expand Down
3 changes: 1 addition & 2 deletions src/lib/actions/__tests__/wait.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getRelationship } from "../../relationships";
import { type BgentRuntime } from "../../runtime";
import { type Message } from "../../types";
import action from "../wait"; // Import the wait action
import { DefaultActions } from "@/lib/actions";

dotenv.config();

Expand Down Expand Up @@ -83,7 +82,7 @@ describe("Wait Action Behavior", () => {
userIds: [user?.id as UUID, zeroUuid],
content: {
content: "Please wait a moment, I need to think about this...",
action: DefaultActions.WAIT,
action: "WAIT",
},
room_id: room_id as UUID,
};
Expand Down
45 changes: 21 additions & 24 deletions src/lib/actions/continue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DefaultActions } from "../actions";
import { composeContext } from "../context";
import logger from "../logger";
import { type BgentRuntime } from "../runtime";
Expand All @@ -9,7 +8,7 @@ import { parseJSONObjectFromText } from "../utils";
const maxContinuesInARow = 2;

export default {
name: DefaultActions.CONTINUE,
name: "CONTINUE",
description: "Continue the conversation with the user",
validate: async (runtime: BgentRuntime, message: Message, state: State) => {
if (!state) state = await runtime.composeState(message);
Expand All @@ -24,9 +23,7 @@ export default {
if (agentMessages) {
const lastMessages = agentMessages.slice(-maxContinuesInARow);
if (lastMessages.length === maxContinuesInARow) {
const allContinues = lastMessages.every(
(m) => m === DefaultActions.CONTINUE,
);
const allContinues = lastMessages.every((m) => m === "CONTINUE");
if (allContinues) {
return false;
}
Expand Down Expand Up @@ -126,40 +123,40 @@ export default {
{
user: "{{user2}}",
content: "Adventurous",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user2}}",
content: "Any particular destination?",
action: DefaultActions.WAIT,
action: "WAIT",
},
],

[
{
user: "{{user1}}",
content: "I started learning the guitar this month!",
action: DefaultActions.WAIT,
action: "WAIT",
},
{
user: "{{user2}}",
content: "How’s that going?",
action: DefaultActions.WAIT,
action: "WAIT",
},
{
user: "{{user1}}",
content: "Challenging, but rewarding.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user1}}",
content: "My fingers hurt though.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user1}}",
content: "Seriously lol it hurts to type",
action: DefaultActions.WAIT,
action: "WAIT",
},
],

Expand All @@ -168,42 +165,42 @@ export default {
user: "{{user1}}",
content:
"I've been summarying a lot on what happiness means to me lately.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user1}}",
content: "That it’s more about moments than things.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user2}}",
content:
"Like the best things that have ever happened were things that happened, or moments that I had with someone.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
],

[
{
user: "{{user1}}",
content: "I found some incredible art today.",
action: DefaultActions.WAIT,
action: "WAIT",
},
{
user: "{{user2}}",
content: "Who's the artist?",
action: DefaultActions.WAIT,
action: "WAIT",
},
{
user: "{{user1}}",
content: "Not sure lol, they are anon",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user1}}",
content:
"But the pieces are just so insane looking. Once sec, let me grab a link.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
],

Expand All @@ -212,27 +209,27 @@ export default {
user: "{{user1}}",
content:
"The new exhibit downtown is thought-provoking. It's all about tribalism in online spaces.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user1}}",
content: "Really challenges your perceptions. Highly recommend it!",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user2}}",
content: "I’m in. When are you free to go?",
action: DefaultActions.WAIT,
action: "WAIT",
},
{
user: "{{user1}}",
content: "Hmm, let me check.",
action: DefaultActions.CONTINUE,
action: "CONTINUE",
},
{
user: "{{user1}}",
content: "How about this weekend?",
action: DefaultActions.WAIT,
action: "WAIT",
},
],

Expand Down
Loading

0 comments on commit b9441d2

Please sign in to comment.