Skip to content

Commit

Permalink
Merge pull request langchain-ai#13 from langchain-ai/brace/always-pas…
Browse files Browse the repository at this point in the history
…s-selected-artifact

Brace/always pass selected artifact
  • Loading branch information
bracesproul authored Oct 6, 2024
2 parents a02836d + 4145661 commit 828e2c7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
24 changes: 17 additions & 7 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const rewriteArtifactTheme = async (
}
formattedPrompt = CHANGE_ARTIFACT_READING_LEVEL_PROMPT.replace(
"{newReadingLevel}",
""
newReadingLevel
).replace("{artifactContent}", selectedArtifact.content);
} else if (state.readingLevel && state.readingLevel === "pirate") {
formattedPrompt = CHANGE_ARTIFACT_TO_PIRATE_PROMPT.replace(
Expand Down Expand Up @@ -467,6 +467,9 @@ const generatePath = async (state: typeof GraphAnnotation.State) => {
(artifact) => artifact.id === state.selectedArtifactId
)
: state.artifacts[state.artifacts.length - 1];
const allArtifactsButSelected = state.artifacts.filter(
(a) => a.id !== state.selectedArtifactId
);

// Call model and decide if we need to respond to a users query, or generate a new artifact
const formattedPrompt = ROUTE_QUERY_PROMPT.replace(
Expand All @@ -475,12 +478,19 @@ const generatePath = async (state: typeof GraphAnnotation.State) => {
.slice(-3)
.map((message) => `${message._getType()}: ${message.content}`)
.join("\n\n")
).replace(
"{artifacts}",
selectedArtifact
? formatArtifacts([selectedArtifact], true)
: "No artifacts found."
);
)
.replace(
"{artifacts}",
allArtifactsButSelected.length
? formatArtifacts(allArtifactsButSelected, true)
: "No artifacts found."
)
.replace(
"{selectedArtifact}",
selectedArtifact
? formatArtifacts([selectedArtifact], true)
: "No artifacts found."
);

const modelWithTool = new ChatOpenAI({
model: "gpt-4o-mini",
Expand Down
9 changes: 7 additions & 2 deletions src/agent/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ A few of the recent messages in the chat history are:
{recentMessages}
</recent-messages>
The artifacts in the chat history are:
The following contains every artifact the user has generated in the chat history:
<artifacts>
{artifacts}
</artifacts>`;
</artifacts>
This artifact is the one the user is currently viewing. You should weigh this artifact more heavily compared to the others when determining the route.
<selected-artifact>
{selectedArtifact}
</selected-artifact>`;

export const FOLLOWUP_ARTIFACT_PROMPT = `You are an AI assistant tasked with generating a followup to the artifact the user just generated.
The context is you're having a conversation with the user, and you've just generated an artifact for them. Now you should follow up with a message that notifies them you're done. Make this message creative!
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export function useGraph() {
const client = createClient();

const defaultInputs = {
selectedArtifactId: undefined,
// We should always pass the currently selected artifact ID to the server.
selectedArtifactId,
highlighted: undefined,
next: undefined,
language: undefined,
Expand Down

0 comments on commit 828e2c7

Please sign in to comment.