Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from palico-ai/context
Browse files Browse the repository at this point in the history
FEAT: Allowing users to add context to their prompt builder
  • Loading branch information
shikdernyc authored Jan 27, 2024
2 parents e35ea2c + 6904755 commit 86e7424
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
16 changes: 0 additions & 16 deletions src/agent/index.ts

This file was deleted.

16 changes: 12 additions & 4 deletions src/app/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { type ChatCompletionTool } from 'openai/resources/chat/completions'
import { type RequestHandler } from '../types'
import zodToJsonSchema from 'zod-to-json-schema'
import { type MessageContext } from '../../types'

// TODO: Add request validation

export interface GetSystemPromptResponseBody {
prompt: string
}

export const GetSystemPromptRequestHandler: RequestHandler<
unknown,
MessageContext,
GetSystemPromptResponseBody
> = async (_, app) => {
const prompt = await app.promptBuilder.getSystemPrompt()
> = async (payload, app) => {
const prompt = await app.promptBuilder.getSystemPrompt({
context: payload
})
return {
statusCode: 200,
body: {
Expand All @@ -21,6 +26,7 @@ GetSystemPromptResponseBody

export interface GetPromptRequestBody {
query: string
context: Record<string, unknown>
}

export interface GetPromptResponseBody {
Expand All @@ -31,7 +37,9 @@ export const GetPromptRequestHandler: RequestHandler<
GetPromptRequestBody,
GetPromptResponseBody
> = async (payload, app) => {
const prompt = await app.promptBuilder.getPromptForQuery(payload.query)
const prompt = await app.promptBuilder.getPromptForQuery(payload.query, {
context: payload.context
})
return {
statusCode: 200,
body: {
Expand Down
16 changes: 8 additions & 8 deletions src/app/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApplicationConfig } from "../types";
import CurrentProject from "../utils/current_project";
import EventHandler from "./request_handler";
import { type ApplicationConfig } from '../types'
import CurrentProject from '../utils/current_project'
import EventHandler from './request_handler'

export const handler = async (event: any): Promise<any> => {
const appConfig : ApplicationConfig = await CurrentProject.getApplicationConfig(false);
const app = new EventHandler(appConfig);
const response = await app.handle(event);
return response;
};
const appConfig: ApplicationConfig = await CurrentProject.getApplicationConfig(false)
const app = new EventHandler(appConfig)
const response = await app.handle(event)
return response
}
10 changes: 8 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ export interface Toolset {
}

export interface PromptBuilder {
getSystemPrompt: () => Promise<string>
getPromptForQuery: (query: string) => Promise<string>
getSystemPrompt: (params: {
context: MessageContext
}) => Promise<string>
getPromptForQuery: (query: string, params: {
context: MessageContext
}) => Promise<string>
}

export type MessageContext = Record<string, unknown>

export interface ProjectConfig {
orgId: number
projectId: number
Expand Down

0 comments on commit 86e7424

Please sign in to comment.