From 5a798fa7bed2cba51a29c37f6027bcd5c1c46a47 Mon Sep 17 00:00:00 2001 From: Simon Rose Date: Tue, 27 Aug 2024 15:54:07 +0100 Subject: [PATCH 1/4] feat: send quiz designer langchain ChatOpenAI calls through helicone --- packages/core/src/llm/openai.ts | 24 ++++++++++++++++++++++++ packages/core/src/models/prompts.ts | 26 ++++++++------------------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/packages/core/src/llm/openai.ts b/packages/core/src/llm/openai.ts index db3fa54fc..4690b1f22 100644 --- a/packages/core/src/llm/openai.ts +++ b/packages/core/src/llm/openai.ts @@ -1,3 +1,4 @@ +import { ChatOpenAI as LangchainChatOpenAI } from "langchain/chat_models/openai"; import { BaseLLMParams } from "langchain/llms/base"; import { AzureOpenAIInput, @@ -103,8 +104,31 @@ function createOpenAILangchainClient({ }); } +function createOpenAILangchainChatClient({ + app, + fields = {}, +}: { + app: string; + fields?: Partial & + Partial & + BaseLLMParams & { + configuration?: ClientOptions; + }; +}) { + const defaultHeaders = heliconeHeaders({ app }); + return new LangchainChatOpenAI({ + ...fields, + configuration: { + apiKey: process.env.OPENAI_API_KEY, + baseURL: process.env.HELICONE_EU_HOST, + defaultHeaders, + }, + }); +} + export { createOpenAIClient, createOpenAIModerationsClient, createOpenAILangchainClient, + createOpenAILangchainChatClient, }; diff --git a/packages/core/src/models/prompts.ts b/packages/core/src/models/prompts.ts index e5e69c629..1b0a3176c 100644 --- a/packages/core/src/models/prompts.ts +++ b/packages/core/src/models/prompts.ts @@ -1,21 +1,11 @@ import { PrismaClientWithAccelerate } from "@oakai/db"; import defaultLogger, { Logger } from "@oakai/logger"; import { Logger as InngestLogger } from "inngest/middleware/logger"; -import { ChatOpenAI } from "langchain/chat_models/openai"; import { PromptTemplate } from "langchain/prompts"; import { BaseMessage, SystemMessage } from "langchain/schema"; import untruncateJson from "untruncate-json"; -const checkProductionOpenAiUsage = () => { - if ( - process.env.VERCEL_ENV === "production" && - process.env.BYPASS_HELICONE_CHECK !== "true" - ) { - throw new Error( - "Security: Helicone is required for production OpenAI calls", - ); - } -}; +import { createOpenAILangchainChatClient } from "../llm/openai"; type CompletionMeta = { timeTaken: number; @@ -85,13 +75,13 @@ export class Prompts { const streaming = typeof onPartialResponse !== "undefined"; - checkProductionOpenAiUsage(); - const model = new ChatOpenAI({ - // TODO The temperature should be a variable we can pass per prompt - temperature: 0.2, - // TODO The model should be a variable we can pass per prompt - modelName: "gpt-4", - streaming, + const model = createOpenAILangchainChatClient({ + app: "quiz-designer", + fields: { + temperature: 0.2, + modelName: "gpt-4", + streaming, + }, }); const llmInput = [new SystemMessage(promptText)]; From ac9bbc00fe76a705715a0f80abb972fda1ef0ae5 Mon Sep 17 00:00:00 2001 From: Simon Rose Date: Tue, 27 Aug 2024 15:56:40 +0100 Subject: [PATCH 2/4] feat: end of session survey --- .../src/app/aila/[id]/download/index.tsx | 2 +- ...hatActions.tsx => EndOfLessonFeedback.tsx} | 6 +- .../DialogControl/DialogContents.tsx | 4 +- apps/nextjs/src/components/Feedback/index.tsx | 85 ++++++++----------- .../hooks/surveys/usePosthogFeedbackSurvey.ts | 5 +- 5 files changed, 44 insertions(+), 58 deletions(-) rename apps/nextjs/src/components/DialogControl/ContentOptions/{ChatActions.tsx => EndOfLessonFeedback.tsx} (78%) diff --git a/apps/nextjs/src/app/aila/[id]/download/index.tsx b/apps/nextjs/src/app/aila/[id]/download/index.tsx index 621d31aee..49347ebfe 100644 --- a/apps/nextjs/src/app/aila/[id]/download/index.tsx +++ b/apps/nextjs/src/app/aila/[id]/download/index.tsx @@ -77,7 +77,7 @@ export function DownloadPageContents({ chat }: Readonly) { const { survey } = usePosthogFeedbackSurvey({ closeDialog: () => null, - surveyName: "Chat Feedback With Stats", + surveyName: "End of Aila generation survey launch aug24", }); useEffect(() => { diff --git a/apps/nextjs/src/components/DialogControl/ContentOptions/ChatActions.tsx b/apps/nextjs/src/components/DialogControl/ContentOptions/EndOfLessonFeedback.tsx similarity index 78% rename from apps/nextjs/src/components/DialogControl/ContentOptions/ChatActions.tsx rename to apps/nextjs/src/components/DialogControl/ContentOptions/EndOfLessonFeedback.tsx index 0db21eff3..37e0c49fc 100644 --- a/apps/nextjs/src/components/DialogControl/ContentOptions/ChatActions.tsx +++ b/apps/nextjs/src/components/DialogControl/ContentOptions/EndOfLessonFeedback.tsx @@ -3,11 +3,11 @@ import { usePosthogFeedbackSurvey } from "hooks/surveys/usePosthogFeedbackSurvey import FeedBack from "@/components/Feedback"; -const ChatActions = ({ closeDialog }: { closeDialog: () => void }) => { +const EndOfLessonFeedback = ({ closeDialog }: { closeDialog: () => void }) => { const { survey, submitSurvey, closeDialogWithPostHogDismiss } = usePosthogFeedbackSurvey({ closeDialog, - surveyName: "Chat Feedback With Stats", + surveyName: "End of Aila generation survey launch aug24", }); return ( @@ -26,4 +26,4 @@ const ChatActions = ({ closeDialog }: { closeDialog: () => void }) => { ); }; -export default ChatActions; +export default EndOfLessonFeedback; diff --git a/apps/nextjs/src/components/DialogControl/DialogContents.tsx b/apps/nextjs/src/components/DialogControl/DialogContents.tsx index 2e4174ad3..8f148b249 100644 --- a/apps/nextjs/src/components/DialogControl/DialogContents.tsx +++ b/apps/nextjs/src/components/DialogControl/DialogContents.tsx @@ -5,9 +5,9 @@ import { Message } from "ai"; import { useDialog } from "../AppComponents/DialogContext"; import { Icon } from "../Icon"; -import ChatActions from "./ContentOptions/ChatActions"; import DemoInterstitialDialog from "./ContentOptions/DemoInterstitialDialog"; import DemoShareLockedDialog from "./ContentOptions/DemoShareLockedDialog"; +import EndOfLessonFeedback from "./ContentOptions/EndOfLessonFeedback"; import ReportContentDialog from "./ContentOptions/ReportContentDialog"; import ShareChatDialog from "./ContentOptions/ShareChatDialog"; import { @@ -61,7 +61,7 @@ const DialogContents = ({ )} {dialogWindow === "feedback" && ( - + )} {dialogWindow === "report-content" && ( void; + submitSurvey: (usersResponse: { [key: string]: string }) => void; closeDialogWithPostHogDismiss: () => void; onSubmit: () => void; }) => { - const numbersOfHoursSaved = [0, 1, 2, 3, 4, 5, 6]; - const [usersResponse, setUsersResponse] = useState({ - $survey_response: "", - $survey_response_1: "", - $survey_response_2: "", - }); + const rating = [ + { text: "Poor", number: 1 }, + { text: "Needs Improvement", number: 2 }, + { text: "Satisfactory", number: 3 }, + { text: "Good", number: 4 }, + { text: "Excellent", number: 5 }, + ]; + const [usersResponse, setUsersResponse] = useState<{ [key: string]: string }>( + {}, + ); + console.log("usersResponse", usersResponse); if (!survey?.id) return null; + return ( -

Before you continue...

+

Before you continue...

{ @@ -44,32 +46,7 @@ const FeedBack = ({ }} className="flex w-full flex-col gap-14" > - {survey?.questions.map((question) => { - if (question.type === "open") { - return ( -
- -