Skip to content

Commit 7c1ee24

Browse files
authored
🪄 feat: Code Artifacts (danny-avila#3798)
* feat: Add CodeArtifacts component to Beta settings tab * chore: Update npm dependency to @codesandbox/[email protected] * WIP: artifacts first pass * WIP first pass remark-directive * chore: revert markdown to original component + new artifacts rendering * refactor: first pass rewrite * refactor: add throttling * first pass styling * style: Add Radix Tabs, more styling changes * feat: second pass * style: code styling * fix: package markdown fixes * feat: Add useEffect hook to Artifacts component for visibility control, slide in animation * fix: only set artifact if there is content * refactor: typing and make latest artifact active if the number of artifacts changed * feat: artifacts + shadcnui * feat: Add Copy Code button to Artifacts component * feat: first pass streaming updates * refactor: optimize ordering of artifacts in Artifacts component * refactor: optimize ordering of artifacts and add latest artifact activation in Artifacts component * refactor: add order prop to Artifact * feat: update to latest, use update time for ordering * refactor: optimize ordering of artifacts and activate latest artifact in Artifacts component * wip: remove thinking text and artifact formatting if empty * refactor: optimize Markdown rendering and add support for code artifacts * feat: global state for current artifact Id and set on artifact preview click * refactor: Rename CodePreview component to ArtifactButton * refactor: apply growth to artifact frame so artifact preview can take full space * refactor: remove artifactIdsState * refactor: nullify artifact state and reset on empty conversation * feat: reset artifact state on conversation change * feat: artifacts system prompt in backend * refactor: update UI artifact toggle label to match localization key * style: remove ArtifactButton inline-block styling * feat: memoize ArtifactPreview, add html support * refactor: abstract out components * chore: bump react-resizable-panel * refactor: resizable panel order props * fix: side panel resizing crashes * style: temporarily remove scrolling, add better styling * chore: remove thinking for now * chore: preprocess artifacts for now * feat: Add auto scrolling to CodeMarkdown (artifacts) * feat: autoswitch to preview * feat: auto switch to code, adjust prompt, remove unused code * feat: refresh button * feat: open/close artifacts * wip: mermaid * refactor: w-fit Artifact button * chore: organize code * feat: first pass mermaid * refactor: improve panning logic in MermaidDiagram component * feat: center/zoom on first render * refactor: add centering with reset button * style: mermaid styling * refactor: add back MermaidDiagram * fix: static/html template * fix: mermaid * add examples to artifacts prompt * refactor: fix CodeBar plugin prop logic * refactor: remove unnecessary mention of artifacts when not requested * fix: remove preprocessCodeArtifacts function and fix imports * feat: improve artifacts guidelines and remove unnecessary mentions * refactor: improve artifacts guidelines and remove unnecessary mentions * chore: uninstall unused packages * chore: bump vite * chore: update three dependency to version 0.167.1 * refactor: move beta settings, add additional artifacts toggles * feat: artifacts mode toggles * refactor: adjust prompt * feat: shadcnui instructions * feat: code artifacts custom prompt mode * chore: Update artifacts UI labels and instructions localizations * refactor: Remove unused code in Markdown component
1 parent 80e1bdc commit 7c1ee24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+14010
-3991
lines changed

api/app/clients/AnthropicClient.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ class AnthropicClient extends BaseClient {
492492
identityPrefix = `${identityPrefix}\nYou are ${this.options.modelLabel}`;
493493
}
494494

495-
let promptPrefix = (this.options.promptPrefix || '').trim();
495+
let promptPrefix = (this.options.promptPrefix ?? '').trim();
496+
if (typeof this.options.artifactsPrompt === 'string' && this.options.artifactsPrompt) {
497+
promptPrefix = `${promptPrefix ?? ''}\n${this.options.artifactsPrompt}`.trim();
498+
}
496499
if (promptPrefix) {
497500
// If the prompt prefix doesn't end with the end token, add it.
498501
if (!promptPrefix.endsWith(`${this.endToken}`)) {
@@ -820,6 +823,7 @@ class AnthropicClient extends BaseClient {
820823
getSaveOptions() {
821824
return {
822825
maxContextTokens: this.options.maxContextTokens,
826+
artifacts: this.options.artifacts,
823827
promptPrefix: this.options.promptPrefix,
824828
modelLabel: this.options.modelLabel,
825829
promptCache: this.options.promptCache,

api/app/clients/GoogleClient.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,13 @@ class GoogleClient extends BaseClient {
390390
parameters: this.modelOptions,
391391
};
392392

393-
if (this.options.promptPrefix) {
394-
payload.instances[0].context = this.options.promptPrefix;
393+
let promptPrefix = (this.options.promptPrefix ?? '').trim();
394+
if (typeof this.options.artifactsPrompt === 'string' && this.options.artifactsPrompt) {
395+
promptPrefix = `${promptPrefix ?? ''}\n${this.options.artifactsPrompt}`.trim();
396+
}
397+
398+
if (promptPrefix) {
399+
payload.instances[0].context = promptPrefix;
395400
}
396401

397402
if (this.options.examples.length > 0) {
@@ -445,7 +450,10 @@ class GoogleClient extends BaseClient {
445450
identityPrefix = `${identityPrefix}\nYou are ${this.options.modelLabel}`;
446451
}
447452

448-
let promptPrefix = (this.options.promptPrefix || '').trim();
453+
let promptPrefix = (this.options.promptPrefix ?? '').trim();
454+
if (typeof this.options.artifactsPrompt === 'string' && this.options.artifactsPrompt) {
455+
promptPrefix = `${promptPrefix ?? ''}\n${this.options.artifactsPrompt}`.trim();
456+
}
449457
if (promptPrefix) {
450458
// If the prompt prefix doesn't end with the end token, add it.
451459
if (!promptPrefix.endsWith(`${this.endToken}`)) {
@@ -670,11 +678,16 @@ class GoogleClient extends BaseClient {
670678
contents: _payload,
671679
};
672680

681+
let promptPrefix = (this.options.promptPrefix ?? '').trim();
682+
if (typeof this.options.artifactsPrompt === 'string' && this.options.artifactsPrompt) {
683+
promptPrefix = `${promptPrefix ?? ''}\n${this.options.artifactsPrompt}`.trim();
684+
}
685+
673686
if (this.options?.promptPrefix?.length) {
674687
requestOptions.systemInstruction = {
675688
parts: [
676689
{
677-
text: this.options.promptPrefix,
690+
text: promptPrefix,
678691
},
679692
],
680693
};
@@ -767,11 +780,16 @@ class GoogleClient extends BaseClient {
767780
contents: _payload,
768781
};
769782

783+
let promptPrefix = (this.options.promptPrefix ?? '').trim();
784+
if (typeof this.options.artifactsPrompt === 'string' && this.options.artifactsPrompt) {
785+
promptPrefix = `${promptPrefix ?? ''}\n${this.options.artifactsPrompt}`.trim();
786+
}
787+
770788
if (this.options?.promptPrefix?.length) {
771789
requestOptions.systemInstruction = {
772790
parts: [
773791
{
774-
text: this.options.promptPrefix,
792+
text: promptPrefix,
775793
},
776794
],
777795
};
@@ -842,6 +860,7 @@ class GoogleClient extends BaseClient {
842860

843861
getSaveOptions() {
844862
return {
863+
artifacts: this.options.artifacts,
845864
promptPrefix: this.options.promptPrefix,
846865
modelLabel: this.options.modelLabel,
847866
iconURL: this.options.iconURL,

api/app/clients/OpenAIClient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ class OpenAIClient extends BaseClient {
401401

402402
getSaveOptions() {
403403
return {
404+
artifacts: this.options.artifacts,
404405
maxContextTokens: this.options.maxContextTokens,
405406
chatGptLabel: this.options.chatGptLabel,
406407
promptPrefix: this.options.promptPrefix,
@@ -463,6 +464,9 @@ class OpenAIClient extends BaseClient {
463464
let promptTokens;
464465

465466
promptPrefix = (promptPrefix || this.options.promptPrefix || '').trim();
467+
if (typeof this.options.artifactsPrompt === 'string' && this.options.artifactsPrompt) {
468+
promptPrefix = `${promptPrefix ?? ''}\n${this.options.artifactsPrompt}`.trim();
469+
}
466470

467471
if (this.options.attachments) {
468472
const attachments = await this.options.attachments;

api/app/clients/PluginsClient.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PluginsClient extends OpenAIClient {
4242

4343
getSaveOptions() {
4444
return {
45+
artifacts: this.options.artifacts,
4546
chatGptLabel: this.options.chatGptLabel,
4647
promptPrefix: this.options.promptPrefix,
4748
tools: this.options.tools,
@@ -145,16 +146,22 @@ class PluginsClient extends OpenAIClient {
145146

146147
// initialize agent
147148
const initializer = this.functionsAgent ? initializeFunctionsAgent : initializeCustomAgent;
149+
150+
let customInstructions = (this.options.promptPrefix ?? '').trim();
151+
if (typeof this.options.artifactsPrompt === 'string' && this.options.artifactsPrompt) {
152+
customInstructions = `${customInstructions ?? ''}\n${this.options.artifactsPrompt}`.trim();
153+
}
154+
148155
this.executor = await initializer({
149156
model,
150157
signal,
151158
pastMessages,
152159
tools: this.tools,
160+
customInstructions,
153161
verbose: this.options.debug,
154162
returnIntermediateSteps: true,
155163
customName: this.options.chatGptLabel,
156164
currentDateString: this.currentDateString,
157-
customInstructions: this.options.promptPrefix,
158165
callbackManager: CallbackManager.fromHandlers({
159166
async handleAgentAction(action, runId) {
160167
handleAction(action, runId, onAgentAction);

0 commit comments

Comments
 (0)