From af9b0acba82e2f64eb1915081af79ebd82041250 Mon Sep 17 00:00:00 2001 From: pedrofrxncx Date: Sat, 26 Oct 2024 11:33:53 -0300 Subject: [PATCH 1/7] Update AppContext type to include prompt --- decopilot-app/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decopilot-app/mod.ts b/decopilot-app/mod.ts index ba68763ba..6a924795a 100644 --- a/decopilot-app/mod.ts +++ b/decopilot-app/mod.ts @@ -22,7 +22,7 @@ import AnthropicApp from "../anthropic/mod.ts"; // export type AppManifest = ManifestOf; export type App = ReturnType; -export type AppContext = AC; +export type AppContext = AC & { prompt: Prompt }; export interface Props { credentials: Credentials[]; From 2c0731c596427bd77fed9f30dfdd03007e69097e Mon Sep 17 00:00:00 2001 From: pedrofrxncx Date: Sat, 26 Oct 2024 11:34:07 -0300 Subject: [PATCH 2/7] Refactor prompt provider in runPrompt.ts --- decopilot-app/actions/prompt/runPrompt.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/decopilot-app/actions/prompt/runPrompt.ts b/decopilot-app/actions/prompt/runPrompt.ts index e6411733a..0715ba6d7 100644 --- a/decopilot-app/actions/prompt/runPrompt.ts +++ b/decopilot-app/actions/prompt/runPrompt.ts @@ -1,5 +1,4 @@ -// import { shortcircuit } from "@deco/deco"; -import { callAntropic, callOpenAI } from "../../clients/llmClientObjects.ts"; +import { callAnthropic } from "../../clients/llmClientObjects.ts"; import type { AppContext } from "../../mod.ts"; import type { Attachment, LLMResponseType, Prompt } from "../../types.ts"; @@ -42,15 +41,8 @@ export default async function action( } if (prompt.provider === "Anthropic") { - return await callAntropic(prompt, ctx, attachments ?? []); + return await callAnthropic(prompt, ctx, attachments ?? []); } - if (prompt.provider === "OpenAI") { - return await callOpenAI(prompt, ctx, attachments ?? []); - } - // if (prompt.provider === "Custom") { - // return await callCustomProvider(prompt, ctx, attachments); - // } - throw new Error(`Provider ${prompt.provider} is not supported`); } From b5366364bf6f6e6f973c469583089f49c1bead5b Mon Sep 17 00:00:00 2001 From: pedrofrxncx Date: Sat, 26 Oct 2024 11:34:23 -0300 Subject: [PATCH 3/7] Refactor prompt provider in runSavedPrompts.ts --- decopilot-app/actions/prompt/runSavedPrompts.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/decopilot-app/actions/prompt/runSavedPrompts.ts b/decopilot-app/actions/prompt/runSavedPrompts.ts index 428691f5e..b844e88a6 100644 --- a/decopilot-app/actions/prompt/runSavedPrompts.ts +++ b/decopilot-app/actions/prompt/runSavedPrompts.ts @@ -1,5 +1,4 @@ -// import { shortcircuit } from "@deco/deco"; -import { callAntropic, callOpenAI } from "../../clients/llmClientObjects.ts"; +import { callAnthropic } from "../../clients/llmClientObjects.ts"; import type { AppContext } from "../../mod.ts"; import type { Attachment, LLMResponseType } from "../../types.ts"; @@ -24,15 +23,8 @@ export default async function action( } if (prompt.provider === "Anthropic") { - return await callAntropic(prompt, ctx, attachments ?? []); + return await callAnthropic(prompt, ctx, attachments ?? []); } - if (prompt.provider === "OpenAI") { - return await callOpenAI(prompt, ctx, attachments ?? []); - } - // if (prompt.provider === "Custom") { - // return await callCustomProvider(prompt, ctx, attachments); - // } - throw new Error(`Provider ${prompt.provider} is not supported`); } From e5b6ff893cfc48da84ad41d0792dde2d952bb8a2 Mon Sep 17 00:00:00 2001 From: pedrofrxncx Date: Sat, 26 Oct 2024 11:34:30 -0300 Subject: [PATCH 4/7] Refactor prompt provider in llmClientObjects.ts --- decopilot-app/clients/llmClientObjects.ts | 25 +---------------------- 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/decopilot-app/clients/llmClientObjects.ts b/decopilot-app/clients/llmClientObjects.ts index 7fb1685ea..b23993617 100644 --- a/decopilot-app/clients/llmClientObjects.ts +++ b/decopilot-app/clients/llmClientObjects.ts @@ -1,4 +1,3 @@ -// import getAppTools from "../../openai/actions/code.ts"; import { AppContext as AnthropicAppContext } from "../../anthropic/mod.ts"; import { allowedModels } from "../../anthropic/actions/code.ts"; @@ -6,7 +5,7 @@ import { AppContext } from "../mod.ts"; import { Attachment, LLMResponseType, Prompt } from "../types.ts"; import assembleFinalPrompt from "../utils/assembleComplexPrompt.ts"; -export const callAntropic = async ( +export const callAnthropic = async ( prompt: Prompt, ctx: AppContext, attachments?: Attachment[], @@ -72,28 +71,6 @@ export const callAntropic = async ( // logica pra chamar a openai }; -export const callOpenAI = ( - prompt: Prompt, - _ctx: AppContext, - _attachments?: Attachment[], -): LLMResponseType => { - const response: LLMResponseType = { - id: "None", - created: 0, - provider: "OpenAI", // Provider is OpenAI - model: prompt.model, - tools: [""], - llm_response: [{ - message: { - role: "Not Ready", - content: `OpenAI functions still not ready`, - }, - index: 0, - }], - }; - return response; -}; - export type Caller = ( prompt: Prompt, attachments: Attachment[], From c0786d75df36feab89293c2aea439c586b873e94 Mon Sep 17 00:00:00 2001 From: pedrofrxncx Date: Sat, 26 Oct 2024 11:34:39 -0300 Subject: [PATCH 5/7] Refactor prompt provider in assembleComplexPrompt.ts --- decopilot-app/utils/assembleComplexPrompt.ts | 107 ++----------------- 1 file changed, 8 insertions(+), 99 deletions(-) diff --git a/decopilot-app/utils/assembleComplexPrompt.ts b/decopilot-app/utils/assembleComplexPrompt.ts index ba49fa0eb..7beb293be 100644 --- a/decopilot-app/utils/assembleComplexPrompt.ts +++ b/decopilot-app/utils/assembleComplexPrompt.ts @@ -1,71 +1,7 @@ import { Attachment, Prompt, PromptDetails } from "../types.ts"; -import { handleAnthropicAttachments } from "./handleAttachments.ts"; +import { handleAttachments } from "./handleAttachments.ts"; -export function assembleOpenAIPrompt( - mainPrompt: string, - advanced?: PromptDetails, - handledAttachments?: string | null, -): string { - let finalPrompt = mainPrompt; - - if (advanced) { - const { context, examples, restrictions } = advanced; - - if (context) { - finalPrompt += `\n\nContext:\n${context}`; - } - - if (examples) { - finalPrompt += `\n\nExamples:\n${examples}`; - } - - if (handledAttachments) { - finalPrompt += handledAttachments; - } - - if (restrictions) { - finalPrompt += `\n\nRestrictions:\n${restrictions}`; - } - } else if (handledAttachments) { - finalPrompt += handledAttachments; - } - - return finalPrompt; -} - -export function assembleAnthropicPrompt( - mainPrompt: string, - advanced?: PromptDetails, - handledAttachments?: string | null, -): string { - let finalPrompt = mainPrompt; - - if (advanced) { - const { context, examples, restrictions } = advanced; - - if (context) { - finalPrompt += `\n\n\n${context}\n`; - } - - if (examples) { - finalPrompt += `\n\n\n${examples}\n`; - } - - if (handledAttachments) { - finalPrompt += handledAttachments; - } - - if (restrictions) { - finalPrompt += `\n\n\n${restrictions}\n`; - } - } else if (handledAttachments) { - finalPrompt += handledAttachments; - } - - return finalPrompt; -} - -function assembleFallbackPrompt( +export function assemblePrompt( mainPrompt: string, advanced?: PromptDetails, handledAttachments?: string | null, @@ -101,40 +37,13 @@ export default async function assembleFinalPrompt( prompt: Prompt, attachments?: Attachment[], ): Promise { - const { provider, prompt: mainPrompt, advanced } = prompt; - - let finalPrompt = ""; - let handledAttachments = ""; - - if (attachments) { - handledAttachments = await handleAnthropicAttachments(attachments); - } - - switch (provider) { - case "OpenAI": - finalPrompt = assembleOpenAIPrompt( - mainPrompt, - advanced, - handledAttachments, - ); - break; + const { prompt: mainPrompt, advanced } = prompt; - case "Anthropic": - finalPrompt = assembleAnthropicPrompt( - mainPrompt, - advanced, - handledAttachments, - ); - break; - - default: - finalPrompt = assembleFallbackPrompt( - mainPrompt, - advanced, - handledAttachments, - ); - break; - } + const finalPrompt = assemblePrompt( + mainPrompt, + advanced, + attachments ? await handleAttachments(attachments) : "", + ); return finalPrompt; } From c086c875228de8b9320e80274463ba3a45b82b94 Mon Sep 17 00:00:00 2001 From: pedrofrxncx Date: Sat, 26 Oct 2024 11:34:43 -0300 Subject: [PATCH 6/7] Refactor handleAttachments function to use anthropic supported method --- decopilot-app/utils/handleAttachments.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/decopilot-app/utils/handleAttachments.ts b/decopilot-app/utils/handleAttachments.ts index 42309bd05..c4d135c46 100644 --- a/decopilot-app/utils/handleAttachments.ts +++ b/decopilot-app/utils/handleAttachments.ts @@ -1,6 +1,8 @@ import { Attachment, FileURL } from "../types.ts"; -export async function handleAnthropicAttachments( +// currently handles using anthropic supported method + +export async function handleAttachments( attachments: Attachment[], ): Promise { const treated_Attachments: string[] = []; From d628635ed8ca4fc49193cb51876ec5dfff262427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Fran=C3=A7a?= Date: Sat, 26 Oct 2024 11:45:16 -0300 Subject: [PATCH 7/7] Update handleAttachments.ts --- decopilot-app/utils/handleAttachments.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decopilot-app/utils/handleAttachments.ts b/decopilot-app/utils/handleAttachments.ts index c4d135c46..e56d533d7 100644 --- a/decopilot-app/utils/handleAttachments.ts +++ b/decopilot-app/utils/handleAttachments.ts @@ -1,6 +1,6 @@ import { Attachment, FileURL } from "../types.ts"; -// currently handles using anthropic supported method +// currently handles using anthropic suggested method export async function handleAttachments( attachments: Attachment[],