Skip to content

Commit

Permalink
Agents are rough
Browse files Browse the repository at this point in the history
  • Loading branch information
awhiteside1 committed Sep 26, 2024
1 parent a59fec8 commit 78d91a9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 464 deletions.
5 changes: 3 additions & 2 deletions packages/agents/src/Agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { AppLayer } from "./services";

describe("Agent", () => {
it("should ", { timeout: 100000 }, async () => {
const program = Effect.gen(function* (_) {
const agent = new HelloAgent();
const agent = new HelloAgent();
const program = Effect.gen(function* () {

const createTask = Effect.succeed(
new Task(
"Create a greeting for Alex Whiteside, a software architect who enjoys sarcasm and XKCD",
Expand Down
209 changes: 0 additions & 209 deletions packages/agents/src/logic.ts

This file was deleted.

93 changes: 4 additions & 89 deletions packages/agents/src/services.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// services.ts

import { Effect, Context, Layer } from "effect";
import { LogEvent, ProcessStatus, Article } from "./types";
import { Ollama } from "ollama";

/**
Expand All @@ -13,57 +12,10 @@ export class LLMService extends Context.Tag("LLMService")<
readonly generateText: (
prompt: string,
model: string,
) => Effect.Effect<any, Error, string>;
) => Effect.Effect<string, Error, never>;
readonly getEmbedding: (
text: string,
) => Effect.Effect<any, Error, number[]>;
}
>() {}

/**
* VectorStoreService tag
*/
export class VectorStoreService extends Context.Tag("VectorStoreService")<
VectorStoreService,
{
readonly storeVector: (
id: string,
vector: number[],
) => Effect.Effect<any, Error, void>;
readonly queryVector: (
vector: number[],
topK: number,
) => Effect.Effect<any, Error, string[]>;
}
>() {}

/**
* CMSService tag
*/
export class CMSService extends Context.Tag("CMSService")<
CMSService,
{
readonly fetchArticles: (args: any) => Effect.Effect<any, Error, Article[]>;
readonly checkArticleExists: (
title: string,
) => Effect.Effect<any, Error, boolean>;
}
>() {}

/**
* DatabaseService tag
*/
export class DatabaseService extends Context.Tag("DatabaseService")<
DatabaseService,
{
readonly logEvent: (event: LogEvent) => Effect.Effect<any, Error, void>;
readonly getProcessStatus: (
processId: string,
) => Effect.Effect<any, Error, ProcessStatus>;
readonly updateProcessStatus: (
processId: string,
status: ProcessStatus,
) => Effect.Effect<any, Error, void>;
) => Effect.Effect<number[], Error, never>;
}
>() {}

Expand Down Expand Up @@ -93,51 +45,14 @@ export const LLMServiceLive = () => {
try: () =>
ollama
.embed({ model: "nomic-embed-text", input: text })
.then((res) => res.embeddings),
.then((res) => res.embeddings[0]),
catch: (err) => new Error(),
}),
}),
);
};

export const VectorStoreServiceLive = Layer.succeed(
VectorStoreService,
VectorStoreService.of({
storeVector: (id: string, vector: number[]) => Effect.succeed(void 0),
queryVector: (vector: number[], topK: number) =>
Effect.succeed(["id1", "id2"]),
}),
);

export const DatabaseServiceLive = Layer.succeed(
DatabaseService,
DatabaseService.of({
logEvent: (event: LogEvent) => Effect.succeed(void 0),
getProcessStatus: (processId: string) =>
Effect.succeed({ id: processId, status: "in-progress" }),
updateProcessStatus: (processId: string, status: ProcessStatus) =>
Effect.succeed(void 0),
}),
);

export const CMSServiceLive = Layer.succeed(
CMSService,
CMSService.of({
fetchArticles: (args: any) =>
Effect.succeed([
{ id: "1", title: "Existing Article 1", content: "Content 1" },
{ id: "2", title: "Existing Article 2", content: "Content 2" },
]),
checkArticleExists: (title: string) => Effect.succeed(false),
}),
);

/**
* Defines the application layer by composing service layers.
*/
export const AppLayer = Layer.mergeAll(
LLMServiceLive(),
VectorStoreServiceLive,
DatabaseServiceLive,
CMSServiceLive,
);
export const AppLayer = Layer.mergeAll(LLMServiceLive());
Loading

0 comments on commit 78d91a9

Please sign in to comment.