Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge staging to main #189

Merged
merged 33 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
31c0a77
Define Azure models
punitda Nov 3, 2024
5a3f1d7
Add Azure model to list
punitda Nov 3, 2024
14385bd
Modify util to account for azure open ai provider
punitda Nov 3, 2024
cd74585
Add azure to list of model in ModelSelector
punitda Nov 3, 2024
0019011
Update nodes to use initChatModelWithConfig
punitda Nov 3, 2024
931b226
Update customModelName in case of azure
punitda Nov 3, 2024
ec8a910
Update .env.example
punitda Nov 3, 2024
42ac81c
Change default api version
punitda Nov 3, 2024
242aa24
Remove workaround
punitda Nov 3, 2024
6010979
fix: hide new model dialog when chat started
bracesproul Nov 3, 2024
26f5758
Merge pull request #175 from langchain-ai/brace/fix-showing-model-dialog
bracesproul Nov 3, 2024
47e9cdc
feat: Custom assistants
bracesproul Nov 4, 2024
4488ee0
Replace with modelName
punitda Nov 4, 2024
04879b2
Add azure open ai base path for custom domains
punitda Nov 4, 2024
d925dd5
Move ModelConfig to types
punitda Nov 4, 2024
1a954d3
cr
bracesproul Nov 4, 2024
a48a906
cr
bracesproul Nov 4, 2024
6b021b1
connect to BE
bracesproul Nov 4, 2024
8dbf96d
add alert
bracesproul Nov 4, 2024
d0ee106
fix build
bracesproul Nov 4, 2024
6379719
merge staging
bracesproul Nov 4, 2024
27b5ab6
bump deps
bracesproul Nov 4, 2024
8131d29
update default model
bracesproul Nov 4, 2024
c8ecae5
Merge pull request #183 from langchain-ai/brace/custom-assistants
bracesproul Nov 4, 2024
9e26ade
fix: Add back claude 3 haiku old
bracesproul Nov 4, 2024
38418fa
cr
bracesproul Nov 4, 2024
11dcdc2
Merge pull request #184 from langchain-ai/brace/add-3-haiku-back
bracesproul Nov 4, 2024
593bcaa
merge staging
bracesproul Nov 5, 2024
d0ea4be
cr
bracesproul Nov 5, 2024
0a41bd1
cr
bracesproul Nov 5, 2024
f3db0de
Merge pull request #179 from punitda/feat/azure-open-ai
bracesproul Nov 5, 2024
8e119a2
fix: Gate azure model
bracesproul Nov 6, 2024
ca3673f
Merge pull request #190 from langchain-ai/brace/add-azure-gating
bracesproul Nov 6, 2024
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
"langsmith": "^0.1.61",
"lodash": "^4.17.21",
"lucide-react": "^0.441.0",
"next": "14.2.7",
"next": "14.2.10",
"react": "^18",
"react-colorful": "^5.6.1",
"react-dom": "^18",
"react-icons": "^5.3.0",
"react-json-view": "^1.21.3",
Expand All @@ -97,7 +98,7 @@
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.8.1",
"eslint": "^8",
"eslint-config-next": "14.2.7",
"eslint-config-next": "14.2.10",
"postcss": "^8",
"prettier": "^3.3.3",
"tailwind-scrollbar": "^3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/agent/open-canvas/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { END, Send, START, StateGraph } from "@langchain/langgraph";
import { DEFAULT_INPUTS } from "../../constants";
import { customAction } from "./nodes/customAction";
import { generateArtifact } from "./nodes/generateArtifact";
import { generateArtifact } from "./nodes/generate-artifact";
import { generateFollowup } from "./nodes/generateFollowup";
import { generatePath } from "./nodes/generatePath";
import { reflectNode } from "./nodes/reflect";
import { rewriteArtifact } from "./nodes/rewriteArtifact";
import { rewriteArtifact } from "./nodes/rewrite-artifact";
import { rewriteArtifactTheme } from "./nodes/rewriteArtifactTheme";
import { updateArtifact } from "./nodes/updateArtifact";
import { replyToGeneralInput } from "./nodes/replyToGeneralInput";
Expand Down
61 changes: 61 additions & 0 deletions src/agent/open-canvas/nodes/generate-artifact/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
OpenCanvasGraphAnnotation,
OpenCanvasGraphReturnType,
} from "../../state";
import { LangGraphRunnableConfig } from "@langchain/langgraph";
import {
getFormattedReflections,
getModelFromConfig,
getModelNameAndProviderFromConfig,
optionallyGetSystemPromptFromConfig,
} from "@/agent/utils";
import { ARTIFACT_TOOL_SCHEMA } from "./schemas";
import { ArtifactV3 } from "@/types";
import { createArtifactContent, formatNewArtifactPrompt } from "./utils";

/**
* Generate a new artifact based on the user's query.
*/
export const generateArtifact = async (
state: typeof OpenCanvasGraphAnnotation.State,
config: LangGraphRunnableConfig
): Promise<OpenCanvasGraphReturnType> => {
const { modelName } = getModelNameAndProviderFromConfig(config);
const smallModel = await getModelFromConfig(config, 0.5);

const modelWithArtifactTool = smallModel.bindTools(
[
{
name: "generate_artifact",
schema: ARTIFACT_TOOL_SCHEMA,
},
],
{ tool_choice: "generate_artifact" }
);

const memoriesAsString = await getFormattedReflections(config);
const formattedNewArtifactPrompt = formatNewArtifactPrompt(
memoriesAsString,
modelName
);

const userSystemPrompt = optionallyGetSystemPromptFromConfig(config);
const fullSystemPrompt = userSystemPrompt
? `${userSystemPrompt}\n${formattedNewArtifactPrompt}`
: formattedNewArtifactPrompt;

const response = await modelWithArtifactTool.invoke(
[{ role: "system", content: fullSystemPrompt }, ...state.messages],
{ runName: "generate_artifact" }
);

const newArtifactContent = createArtifactContent(response.tool_calls?.[0]);
const newArtifact: ArtifactV3 = {
currentIndex: 1,
contents: [newArtifactContent],
};

return {
artifact: newArtifact,
};
};
33 changes: 33 additions & 0 deletions src/agent/open-canvas/nodes/generate-artifact/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { PROGRAMMING_LANGUAGES } from "@/types";
import { z } from "zod";

export const ARTIFACT_TOOL_SCHEMA = z.object({
type: z
.enum(["code", "text"])
.describe("The content type of the artifact generated."),
language: z
.enum(
PROGRAMMING_LANGUAGES.map((lang) => lang.language) as [
string,
...string[],
]
)
.optional()
.describe(
"The language/programming language of the artifact generated.\n" +
"If generating code, it should be one of the options, or 'other'.\n" +
"If not generating code, the language should ALWAYS be 'other'."
),
isValidReact: z
.boolean()
.optional()
.describe(
"Whether or not the generated code is valid React code. Only populate this field if generating code."
),
artifact: z.string().describe("The content of the artifact to generate."),
title: z
.string()
.describe(
"A short title to give to the artifact. Should be less than 5 words."
),
});
39 changes: 39 additions & 0 deletions src/agent/open-canvas/nodes/generate-artifact/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NEW_ARTIFACT_PROMPT } from "../../prompts";
import { ArtifactCodeV3, ArtifactMarkdownV3 } from "@/types";
import { ToolCall } from "@langchain/core/messages/tool";

export const formatNewArtifactPrompt = (
memoriesAsString: string,
modelName: string
): string => {
return NEW_ARTIFACT_PROMPT.replace("{reflections}", memoriesAsString).replace(
"{disableChainOfThought}",
modelName.includes("claude")
? "\n\nIMPORTANT: Do NOT preform chain of thought beforehand. Instead, go STRAIGHT to generating the tool response. This is VERY important."
: ""
);
};

export const createArtifactContent = (
toolCall: ToolCall | undefined
): ArtifactCodeV3 | ArtifactMarkdownV3 => {
const toolArgs = toolCall?.args;
const artifactType = toolArgs?.type;

if (artifactType === "code") {
return {
index: 1,
type: "code",
title: toolArgs?.title,
code: toolArgs?.artifact,
language: toolArgs?.language,
};
}

return {
index: 1,
type: "text",
title: toolArgs?.title,
fullMarkdown: toolArgs?.artifact,
};
};
131 changes: 0 additions & 131 deletions src/agent/open-canvas/nodes/generateArtifact.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/agent/open-canvas/nodes/generatePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const generatePath = async (
state: typeof OpenCanvasGraphAnnotation.State,
config: LangGraphRunnableConfig
) => {
console.log("config.configurable!!", config.configurable);
if (state.highlightedCode) {
return {
next: "updateArtifact",
Expand Down
68 changes: 68 additions & 0 deletions src/agent/open-canvas/nodes/rewrite-artifact/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
OpenCanvasGraphAnnotation,
OpenCanvasGraphReturnType,
} from "../../state";
import { LangGraphRunnableConfig } from "@langchain/langgraph";
import { optionallyUpdateArtifactMeta } from "./update-meta";
import { buildPrompt, createNewArtifactContent, validateState } from "./utils";
import {
getFormattedReflections,
getModelFromConfig,
optionallyGetSystemPromptFromConfig,
} from "@/agent/utils";
import { isArtifactMarkdownContent } from "@/lib/artifact_content_types";

export const rewriteArtifact = async (
state: typeof OpenCanvasGraphAnnotation.State,
config: LangGraphRunnableConfig
): Promise<OpenCanvasGraphReturnType> => {
const smallModelWithConfig = (await getModelFromConfig(config)).withConfig({
runName: "rewrite_artifact_model_call",
});
const memoriesAsString = await getFormattedReflections(config);
const { currentArtifactContent, recentHumanMessage } = validateState(state);

const artifactMetaToolCall = await optionallyUpdateArtifactMeta(
state,
config
);
const artifactType = artifactMetaToolCall?.args?.type;
const isNewType = artifactType !== currentArtifactContent.type;

const artifactContent = isArtifactMarkdownContent(currentArtifactContent)
? currentArtifactContent.fullMarkdown
: currentArtifactContent.code;

const formattedPrompt = buildPrompt({
artifactContent,
memoriesAsString,
isNewType,
artifactMetaToolCall,
});

const userSystemPrompt = optionallyGetSystemPromptFromConfig(config);
const fullSystemPrompt = userSystemPrompt
? `${userSystemPrompt}\n${formattedPrompt}`
: formattedPrompt;

const newArtifactResponse = await smallModelWithConfig.invoke([
{ role: "system", content: fullSystemPrompt },
recentHumanMessage,
]);

const newArtifactContent = createNewArtifactContent({
artifactType,
state,
currentArtifactContent,
artifactMetaToolCall,
newContent: newArtifactResponse.content as string,
});

return {
artifact: {
...state.artifact,
currentIndex: state.artifact.contents.length + 1,
contents: [...state.artifact.contents, newArtifactContent],
},
};
};
Loading