Skip to content

Commit

Permalink
Merge pull request #2071 from quadratichq/qa
Browse files Browse the repository at this point in the history
QA: Nov 13th
  • Loading branch information
davidkircos authored Nov 22, 2024
2 parents 51b25bd + ce3b362 commit e76eb58
Show file tree
Hide file tree
Showing 84 changed files with 1,326 additions and 834 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,8 @@
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
21 changes: 11 additions & 10 deletions quadratic-api/src/routes/ai/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ anthropic_router.post('/anthropic/chat', validateAccessToken, ai_rate_limiter, a
});
response.json(result.content);
} catch (error: any) {
if (error.response) {
response.status(error.response.status).json(error.response.data);
console.log(error.response.status, error.response.data);
if (error instanceof Anthropic.APIError) {
response.status(error.status ?? 400).json(error.message);
console.log(error.status, error.message);
} else {
response.status(400).json(error.message);
console.log(error.message);
response.status(400).json(error);
console.log(error);
}
}
});
Expand Down Expand Up @@ -75,14 +75,15 @@ anthropic_router.post(
}
} catch (error: any) {
if (!response.headersSent) {
if (error.response) {
response.status(error.response.status).json(error.response.data);
console.log(error.response.status, error.response.data);
if (error instanceof Anthropic.APIError) {
response.status(error.status ?? 400).json(error.message);
console.log(error.status, error.message);
} else {
response.status(400).json(error.message);
console.log(error.message);
response.status(400).json(error);
console.log(error);
}
} else {
response.status(500).json('Error occurred after headers were sent');
console.error('Error occurred after headers were sent:', error);
}
}
Expand Down
21 changes: 11 additions & 10 deletions quadratic-api/src/routes/ai/bedrock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AnthropicBedrock } from '@anthropic-ai/bedrock-sdk';
import Anthropic from '@anthropic-ai/sdk';
import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand } from '@aws-sdk/client-bedrock-runtime';
import express from 'express';
import { MODEL_OPTIONS } from 'quadratic-shared/AI_MODELS';
Expand Down Expand Up @@ -125,12 +126,12 @@ bedrock_router.post('/bedrock/anthropic/chat', validateAccessToken, ai_rate_limi
});
response.json(result.content);
} catch (error: any) {
if (error.response) {
response.status(error.response.status).json(error.response.data);
console.log(error.response.status, error.response.data);
if (error instanceof Anthropic.APIError) {
response.status(error.status ?? 400).json(error.message);
console.log(error.status, error.message);
} else {
response.status(400).json(error.message);
console.log(error.message);
response.status(400).json(error);
console.log(error);
}
}
});
Expand Down Expand Up @@ -173,12 +174,12 @@ bedrock_router.post(
}
} catch (error: any) {
if (!response.headersSent) {
if (error.response) {
response.status(error.response.status).json(error.response.data);
console.log(error.response.status, error.response.data);
if (error instanceof Anthropic.APIError) {
response.status(error.status ?? 400).json(error.message);
console.log(error.status, error.message);
} else {
response.status(400).json(error.message);
console.log(error.message);
response.status(400).json(error);
console.log(error);
}
} else {
console.error('Error occurred after headers were sent:', error);
Expand Down
20 changes: 10 additions & 10 deletions quadratic-api/src/routes/ai/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ openai_router.post('/openai/chat', validateAccessToken, ai_rate_limiter, async (
});
response.json(result.choices[0].message);
} catch (error: any) {
if (error.response) {
response.status(error.response.status).json(error.response.data);
console.log(error.response.status, error.response.data);
if (error instanceof OpenAI.APIError) {
response.status(error.status ?? 400).json(error.message);
console.log(error.status, error.message);
} else {
response.status(400).json(error.message);
console.log(error.message);
response.status(400).json(error);
console.log(error);
}
}
});
Expand Down Expand Up @@ -65,12 +65,12 @@ openai_router.post('/openai/chat/stream', validateAccessToken, ai_rate_limiter,
}
} catch (error: any) {
if (!response.headersSent) {
if (error.response) {
response.status(error.response.status).json(error.response.data);
console.log(error.response.status, error.response.data);
if (error instanceof OpenAI.APIError) {
response.status(error.status ?? 400).json(error.message);
console.log(error.status, error.message);
} else {
response.status(400).json(error.message);
console.log(error.message);
response.status(400).json(error);
console.log(error);
}
} else {
console.error('Error occurred after headers were sent:', error);
Expand Down
4 changes: 2 additions & 2 deletions quadratic-client/src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export const isAvailableBecauseFileLocationIsAccessibleAndWriteable = ({
export const createNewFileAction = {
label: 'New',
isAvailable: isAvailableBecauseFileLocationIsAccessibleAndWriteable,
run({ setEditorInteractionState }: { setEditorInteractionState: SetterOrUpdater<EditorInteractionState> }) {
setEditorInteractionState((prevState) => ({ ...prevState, showNewFileMenu: true }));
run({ teamUuid }: { teamUuid: string }) {
window.location.href = ROUTES.CREATE_FILE_PRIVATE(teamUuid);
},
};

Expand Down
1 change: 1 addition & 0 deletions quadratic-client/src/app/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export enum Action {
MoveCursorRightWithSelection = 'move_cursor_right_with_selection',
MoveCursorLeftWithSelection = 'move_cursor_left_with_selection',
EditCell = 'edit_cell',
ToggleArrowMode = 'toggle_arrow_mode',
DeleteCell = 'delete_cell',
ShowCellTypeMenu = 'show_cell_type_menu',
CloseInlineEditor = 'close_inline_editor',
Expand Down
50 changes: 42 additions & 8 deletions quadratic-client/src/app/actions/editActionsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@/app/grid/actions/clipboard/clipboard';
import { sheets } from '@/app/grid/controller/Sheets';
import { inlineEditorHandler } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineEditorHandler';
import { CursorMode } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineEditorKeyboard';
import { doubleClickCell } from '@/app/gridGL/interaction/pointer/doubleClickCell';
import { pixiAppSettings } from '@/app/gridGL/pixiApp/PixiAppSettings';
import { downloadFile } from '@/app/helpers/downloadFileInBrowser';
Expand Down Expand Up @@ -42,6 +43,7 @@ type EditActionSpec = Pick<
| Action.FillRight
| Action.FillDown
| Action.EditCell
| Action.ToggleArrowMode
| Action.DeleteCell
| Action.CloseInlineEditor
| Action.SaveInlineEditor
Expand Down Expand Up @@ -162,19 +164,51 @@ export const editActionsSpec: EditActionSpec = {
label: 'Edit cell',
run: () => {
if (!inlineEditorHandler.isEditingFormula()) {
const cursor = sheets.sheet.cursor;
const cursorPosition = cursor.cursorPosition;
const column = cursorPosition.x;
const row = cursorPosition.y;
quadraticCore.getCodeCell(sheets.sheet.id, column, row).then((code) => {
const { x, y } = sheets.sheet.cursor.cursorPosition;
quadraticCore.getCodeCell(sheets.sheet.id, x, y).then((code) => {
if (code) {
doubleClickCell({ column: Number(code.x), row: Number(code.y), language: code.language, cell: '' });
doubleClickCell({
column: Number(code.x),
row: Number(code.y),
language: code.language,
cell: '',
});
} else {
quadraticCore.getEditCell(sheets.sheet.id, x, y).then((cell) => {
doubleClickCell({
column: x,
row: y,
cell,
cursorMode: cell ? CursorMode.Edit : CursorMode.Enter,
});
});
}
});
return true;
}
},
},
[Action.ToggleArrowMode]: {
label: 'Toggle arrow mode',
run: () => {
if (!inlineEditorHandler.isEditingFormula()) {
const { x, y } = sheets.sheet.cursor.cursorPosition;
quadraticCore.getCodeCell(sheets.sheet.id, x, y).then((code) => {
if (code) {
doubleClickCell({
column: Number(code.x),
row: Number(code.y),
language: code.language,
cell: '',
cursorMode: CursorMode.Edit,
});
} else {
quadraticCore.getEditCell(sheets.sheet.id, column, row).then((cell) => {
doubleClickCell({ column, row, cell });
quadraticCore.getEditCell(sheets.sheet.id, x, y).then((cell) => {
doubleClickCell({ column: x, row: y, cell, cursorMode: CursorMode.Edit });
});
}
});
return true;
}
},
},
Expand Down
1 change: 0 additions & 1 deletion quadratic-client/src/app/actions/viewActionsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export const viewActionsSpec: ViewActionSpec = {
showConnectionsMenu: false,
showGoToMenu: false,
showFeedbackMenu: false,
showNewFileMenu: false,
showRenameFileMenu: false,
showShareFileMenu: false,
showSearch: false,
Expand Down
7 changes: 3 additions & 4 deletions quadratic-client/src/app/ai/hooks/useAIRequestToAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,16 @@ export function useAIRequestToAPI() {
});

if (!response.ok) {
const data = await response.json();
const error =
response.status === 429
? 'You have exceeded the maximum number of requests. Please try again later.'
: `Looks like there was a problem. Status Code: ${response.status}`;
: `Looks like there was a problem. Error: ${data}`;
setMessages?.((prev) => [
...prev.slice(0, -1),
{ role: 'assistant', content: error, contextType: 'userPrompt', model, toolCalls: [] },
]);
if (response.status !== 429) {
console.error(`Error retrieving data from AI API: ${response.status}`);
}
console.error(`Error retrieving data from AI API. Error: ${data}`);
return { error: true, content: error, toolCalls: [] };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Use any functions that are part of the ${language} library.\n
A code cell can return only one type of value as specified in the Quadratic documentation.\n
A code cell cannot display both a chart and return a data frame at the same time.\n
A code cell cannot display multiple charts at the same time.\n
Do not use conditional returns in code cells.\n
Do not use any markdown syntax besides triple backticks for ${language} code blocks.\n
Do not reply code blocks in plain text, use markdown with triple backticks and language name ${language}.`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ${
: 'Choose the language of your response based on the context and user prompt.'
}
Provide complete code blocks with language syntax highlighting. Don't provide small code snippets of changes.
Respond in minimum number of words with direct answer. Include a concise explanation of the answer.
Respond in minimum number of words and include a concise explanation of the actions you are taking. Don't guess the answer itself, just the actions you are taking to respond to the user prompt and what the user can do next.
`,
contextType: 'quadraticDocs',
},
Expand Down
2 changes: 1 addition & 1 deletion quadratic-client/src/app/ai/hooks/useToolUseMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function useToolUseMessages() {
content: `Note: This is an internal message for context. Do not quote it in your response.\n\n
Following are the tools you should use to do actions in the spreadsheet, use them to respond to the user prompt.\n
Include a concise explanation of the actions you are taking to respond to the user prompt.
Include a concise explanation of the actions you are taking to respond to the user prompt. Never guess the answer itself, just the actions you are taking to respond to the user prompt and what the user can do next.\n
Don't include tool details in your response. Reply in layman's terms what actions you are taking.\n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ Add imports to the top of the code cell and do not use any libraries or function
Use any functions that are part of the code cell language library.\n
A code cell can return only one type of value as specified in the Quadratic documentation.\n
A code cell cannot display both a chart and return a data frame at the same time.\n
Do not use conditional returns in code cells.\n
A code cell cannot display multiple charts at the same time.\n
Do not use any markdown syntax besides triple backticks for code cell language code blocks.\n
Do not reply code blocks in plain text, use markdown with triple backticks and language name code cell language.
Do not reply code blocks in plain text, use markdown with triple backticks and language name code cell language.\n
${erroredCodeCells[0].map(({ x, y, language, code_string, std_out, std_err }) => {
const consoleOutput = {
Expand Down
1 change: 1 addition & 0 deletions quadratic-client/src/app/ai/tools/aiToolsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ The required location (x,y) for this code cell is one which satisfies the follow
- If there are multiple tables or data sources being referenced, place the code cell in a location that provides a good balance between proximity to all referenced data and maintaining readability of the currently open sheet.\n
- Consider the overall layout and organization of the currently open sheet when placing the code cell, ensuring it doesn't disrupt existing data or interfere with other code cells.\n
- A plot returned by the code cell occupies just one cell, the plot overlay is larger but the code cell is always just one cell.\n
- Do not use conditional returns in code cells.\n
`,
},
[AITool.MoveCells]: {
Expand Down
20 changes: 17 additions & 3 deletions quadratic-client/src/app/atoms/aiAnalystAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ export const aiAnalystAtom = atom<AIAnalystState>({
effects: [
async ({ getPromise, setSelf, trigger }) => {
if (trigger === 'get') {
// Determine if we want to override the default showAIAnalyst value on initialization
const aiAnalystOpenCount = getAiAnalystOpenCount();
const isSheetEmpty = sheets.sheet.bounds.type === 'empty';
if (isSheetEmpty) {
const showAIAnalyst = aiAnalystOpenCount <= 3 ? true : isSheetEmpty;
if (showAIAnalyst) {
setSelf({
...defaultAIAnalystState,
showAIAnalyst: true,
showAIAnalyst,
});
}

Expand All @@ -52,7 +55,7 @@ export const aiAnalystAtom = atom<AIAnalystState>({
const chats = await aiAnalystOfflineChats.loadChats();
setSelf({
...defaultAIAnalystState,
showAIAnalyst: isSheetEmpty,
showAIAnalyst,
chats,
});
} catch (error) {
Expand Down Expand Up @@ -271,3 +274,14 @@ export const aiAnalystCurrentChatMessagesCountAtom = selector<number>({
key: 'aiAnalystCurrentChatMessagesCountAtom',
get: ({ get }) => getPromptMessages(get(aiAnalystCurrentChatAtom).messages).length,
});

const STORAGE_KEY = 'aiAnalystOpenCount';
export function getAiAnalystOpenCount() {
const count = window.localStorage.getItem(STORAGE_KEY);
return count ? parseInt(count) : 0;
}
export function incrementAiAnalystOpenCount() {
const count = getAiAnalystOpenCount();
const newCount = count + 1;
window.localStorage.setItem(STORAGE_KEY, newCount.toString());
}
5 changes: 0 additions & 5 deletions quadratic-client/src/app/atoms/editorInteractionStateAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface EditorInteractionState {
showConnectionsMenu: boolean;
showGoToMenu: boolean;
showFeedbackMenu: boolean;
showNewFileMenu: boolean;
showRenameFileMenu: boolean;
showShareFileMenu: boolean;
showSearch: boolean | SearchOptions;
Expand All @@ -33,7 +32,6 @@ export const defaultEditorInteractionState: EditorInteractionState = {
showConnectionsMenu: false,
showGoToMenu: false,
showFeedbackMenu: false,
showNewFileMenu: false,
showRenameFileMenu: false,
showShareFileMenu: false,
showSearch: false,
Expand Down Expand Up @@ -62,7 +60,6 @@ export const editorInteractionStateAtom = atom<EditorInteractionState>({
oldValue.showConnectionsMenu ||
oldValue.showGoToMenu ||
oldValue.showFeedbackMenu ||
oldValue.showNewFileMenu ||
oldValue.showRenameFileMenu ||
oldValue.showShareFileMenu ||
oldValue.showSearch ||
Expand All @@ -73,7 +70,6 @@ export const editorInteractionStateAtom = atom<EditorInteractionState>({
newValue.showConnectionsMenu ||
newValue.showGoToMenu ||
newValue.showFeedbackMenu ||
newValue.showNewFileMenu ||
newValue.showRenameFileMenu ||
newValue.showShareFileMenu ||
newValue.showSearch ||
Expand Down Expand Up @@ -103,7 +99,6 @@ export const editorInteractionStateShowCommandPaletteAtom = createSelector('show
export const editorInteractionStateShowConnectionsMenuAtom = createSelector('showConnectionsMenu');
export const editorInteractionStateShowGoToMenuAtom = createSelector('showGoToMenu');
export const editorInteractionStateShowFeedbackMenuAtom = createSelector('showFeedbackMenu');
export const editorInteractionStateShowNewFileMenuAtom = createSelector('showNewFileMenu');
export const editorInteractionStateShowRenameFileMenuAtom = createSelector('showRenameFileMenu');
export const editorInteractionStateShowShareFileMenuAtom = createSelector('showShareFileMenu');
export const editorInteractionStateShowSearchAtom = createSelector('showSearch');
Expand Down
Loading

0 comments on commit e76eb58

Please sign in to comment.