diff --git a/pkg/assets/src/app/components/Sidebar/Chat/Input.tsx b/pkg/assets/src/app/components/Sidebar/Chat/Input.tsx index 056ee95..30e33a4 100644 --- a/pkg/assets/src/app/components/Sidebar/Chat/Input.tsx +++ b/pkg/assets/src/app/components/Sidebar/Chat/Input.tsx @@ -11,7 +11,6 @@ import { PostHogFeature } from "posthog-js/react"; import { useWsDisconnect } from "@/hooks/useWsDisconnect"; import useSessionStorageState from "use-session-storage-state"; import { TipBox } from "@/components/ui/TipBox"; -import LLMSelector from "./LLMSelector"; import Attachments, { AttachmentType } from "./Attachments"; import { useChatContext } from "@/contexts/ChatContext"; import VoiceMode from "./VoiceMode"; @@ -31,7 +30,6 @@ type InputProps = { uploadAttachment: (file: File) => Promise; activeAttachments: any[]; setActiveAttachments: (value: any) => void; - onSelectLLM: (llm: MsgLlm) => void; refetchMessages: () => void; }; @@ -43,7 +41,6 @@ const Input = ({ onSendChatMessage, onCreateThread, onClearSelection, - onSelectLLM, selectedHtml, loading, showDisconnectedMessage = false, @@ -135,10 +132,6 @@ const Input = ({ } }; - const handleSelectLLM = (llm: MsgLlm) => { - onSelectLLM(llm); - }; - useEffect(() => { window.addEventListener("keyup", handleKeyUp); return () => { @@ -197,7 +190,6 @@ const Input = ({ authorId={authorId} refreshMessages={refetchMessages} /> -
@@ -256,7 +248,7 @@ function InputContainer({ >(`ask-ai-attachments-${activeThreadID}`, { defaultValue: [], }); - const [llm, setLlm] = useState("CLAUDE"); + const llm: MsgLlm = "CLAUDE"; useEffect(() => { if (!editor) { @@ -361,7 +353,6 @@ function InputContainer({ uploadAttachment={uploadAttachment} activeAttachments={activeAttachments} setActiveAttachments={setActiveAttachments} - onSelectLLM={(value) => setLlm(value)} /> ); } diff --git a/pkg/dag/llm.go b/pkg/dag/llm.go index eab73c9..93e3283 100644 --- a/pkg/dag/llm.go +++ b/pkg/dag/llm.go @@ -10,7 +10,6 @@ import ( "strings" "time" - "github.com/fivetentaylor/pointy/pkg/client" "github.com/fivetentaylor/pointy/pkg/env" "github.com/fivetentaylor/pointy/pkg/models" "github.com/fivetentaylor/pointy/pkg/stackerr" @@ -210,7 +209,7 @@ func (n *DefaultLLMAdapter) getVertexAI(ctx context.Context, model string) (*ver googleai.WithCloudProject(projectID), googleai.WithCloudLocation(location), googleai.WithCredentialsJSON(decodedCreds), - //googleai.WithCredentialsFile(credsFiles), + // googleai.WithCredentialsFile(credsFiles), googleai.WithDefaultModel(model), ) } @@ -291,30 +290,7 @@ func (n *DefaultLLMAdapter) GenerateContentForStoredPrompt( return nil, fmt.Errorf("error generating content for freeplay prompt: %w", err) } end := time.Now() - - go func() { - freeplay, err := client.NewFreeplayClientFromEnv() - if err != nil { - log.Error("[freeplay] error getting freeplay client", "error", err) - return - } - - userMsg := client.LlmMessageToFreeplayMessage(msgs[len(msgs)-1]) - - data := map[string]string{ - "user": userMsg.Content, - } - - err = freeplay.RecordCompletion(id, prompt.Provider, prompt.ModelName, prompt.Version, msgs, data, response, start, end) - if err != nil { - log.Error("[freeplay] error recording completion", "error", err) - } - err = freeplay.RecordTrace(id, lastUserMessage(messages), response) - if err != nil { - log.Error("[freeplay] error recording trace", "error", err) - } - log.Info("[freeplay] recorded trace", "id", id, "promptName", promptName, "took", end.Sub(start)) - }() + log.Info("[freeplay] recorded trace", "id", id, "promptName", promptName, "took", end.Sub(start)) return response, nil } @@ -392,7 +368,6 @@ func (n *DefaultLLMAdapter) GenerateStoredPrompt( log.Error("[dag] error generating content for stored prompt", "error", err) return nil, fmt.Errorf("error generating content for stored prompt: %w", err) } - end := time.Now() go func() { saveLogFile(ctx, fmt.Sprintf("llm_output-%d.json", start.Unix()), response) @@ -403,22 +378,6 @@ func (n *DefaultLLMAdapter) GenerateStoredPrompt( } saveLogFile(ctx, fmt.Sprintf("llm_choice-%d.txt", start.Unix()), builder.String()) - - freeplay, err := client.NewFreeplayClientFromEnv() - if err != nil { - log.Error("[freeplay] error getting freeplay client", "error", err) - return - } - - err = freeplay.RecordCompletion(id, provider, modelName, prompt.Version, msgs, data, response, start, end) - if err != nil { - log.Error("[freeplay] error recording completion", "error", err) - } - err = freeplay.RecordTrace(id, lastUserMessage(msgs), response) - if err != nil { - log.Error("[freeplay] error recording trace", "error", err) - } - log.Info("[freeplay] recorded trace", "id", id, "promptName", promptName, "took", end.Sub(start)) }() return response, nil diff --git a/pkg/dag/titlethread_node.go b/pkg/dag/titlethread_node.go index 8e3e561..4859bfc 100644 --- a/pkg/dag/titlethread_node.go +++ b/pkg/dag/titlethread_node.go @@ -5,7 +5,6 @@ import ( "fmt" "strings" - "github.com/sashabaranov/go-openai" "github.com/fivetentaylor/pointy/pkg/constants" "github.com/fivetentaylor/pointy/pkg/env" "github.com/fivetentaylor/pointy/pkg/service/messaging" @@ -34,7 +33,11 @@ func (t *TitleThreadNode) Run(ctx context.Context) (Node, error) { if err != nil { return nil, fmt.Errorf("error hydrating: %s", err) } - client := env.OpenAi(ctx) + // Use LLM adapter instead of direct OpenAI client + llmAdapter := &DefaultLLMAdapter{ + Provider: Anthropic, + Model: DefaultClaudeModel, + } messages, err := env.Dynamo(ctx).GetMessagesForThread(input.ThreadId) if err != nil { @@ -59,34 +62,21 @@ func (t *TitleThreadNode) Run(ctx context.Context) (Node, error) { return nil, fmt.Errorf("error getting thread: %s", err) } - //don't title thread if it already has a title + // don't title thread if it already has a title if thread.Title != constants.DefaultThreadTitle { return t.Next, nil } - resp, err := client.CreateChatCompletion( - context.Background(), - openai.ChatCompletionRequest{ - Model: openai.GPT3Dot5Turbo, - Messages: []openai.ChatCompletionMessage{ - { - Role: openai.ChatMessageRoleSystem, - Content: "You are a helpful assistant that summarizes chat threads.", - }, - { - Role: openai.ChatMessageRoleUser, - Content: fmt.Sprintf("Summarize this chat conversation in a concise 3-10 word title, capturing the main topic discussed. Do not use quotations: %s", chatThread.String()), - }, - }, - }, - ) + prompt := fmt.Sprintf("Summarize this chat conversation in a concise 3-10 word title, capturing the main topic discussed. Do not use quotations: %s", chatThread.String()) + + resp, err := llmAdapter.GenerateFromSinglePrompt(ctx, prompt) if err != nil { log.Error("error creating chat completion", "error", err) return nil, fmt.Errorf("error creating chat completion: %s", err) } thread.Title = strings.TrimSpace( - strings.ReplaceAll(resp.Choices[0].Message.Content, "\n", "")) + strings.ReplaceAll(resp, "\n", "")) log.Info("saving thread =>", "thread", thread)