Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions pkg/assets/src/app/components/Sidebar/Chat/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -31,7 +30,6 @@ type InputProps = {
uploadAttachment: (file: File) => Promise<any>;
activeAttachments: any[];
setActiveAttachments: (value: any) => void;
onSelectLLM: (llm: MsgLlm) => void;
refetchMessages: () => void;
};

Expand All @@ -43,7 +41,6 @@ const Input = ({
onSendChatMessage,
onCreateThread,
onClearSelection,
onSelectLLM,
selectedHtml,
loading,
showDisconnectedMessage = false,
Expand Down Expand Up @@ -135,10 +132,6 @@ const Input = ({
}
};

const handleSelectLLM = (llm: MsgLlm) => {
onSelectLLM(llm);
};

useEffect(() => {
window.addEventListener("keyup", handleKeyUp);
return () => {
Expand Down Expand Up @@ -197,7 +190,6 @@ const Input = ({
authorId={authorId}
refreshMessages={refetchMessages}
/>
<LLMSelector onChange={handleSelectLLM} />
</div>

<div className="flex-shrink">
Expand Down Expand Up @@ -256,7 +248,7 @@ function InputContainer({
>(`ask-ai-attachments-${activeThreadID}`, {
defaultValue: [],
});
const [llm, setLlm] = useState<MsgLlm>("CLAUDE");
const llm: MsgLlm = "CLAUDE";

useEffect(() => {
if (!editor) {
Expand Down Expand Up @@ -361,7 +353,6 @@ function InputContainer({
uploadAttachment={uploadAttachment}
activeAttachments={activeAttachments}
setActiveAttachments={setActiveAttachments}
onSelectLLM={(value) => setLlm(value)}
/>
);
}
Expand Down
45 changes: 2 additions & 43 deletions pkg/dag/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
30 changes: 10 additions & 20 deletions pkg/dag/titlethread_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)

Expand Down