Skip to content

Instantly share code, notes, and snippets.

@kleneway
Created September 12, 2024 18:04
Show Gist options
  • Save kleneway/1fab03d81d38674951fea2357d06ea00 to your computer and use it in GitHub Desktop.
Save kleneway/1fab03d81d38674951fea2357d06ea00 to your computer and use it in GitHub Desktop.
GPT-o1 vs GPT-4
__________________START o1______________________
**Plan to Address GitHub Issue: Add Research Component to Dashboard Workspace**
---
### 1. Understand the Problem
- **Objective**: Add a new "Research" component to the dashboard application to display research items associated with a specific task or issue.
- **Key Requirements**:
- Create a new `Research.tsx` component in the workspace directory.
- Fetch research items from the database based on the task/issue ID.
- Render research questions and answers in markdown format.
- Integrate the new component into the workspace and update the sidebar.
- Ensure design consistency using Tailwind CSS.
- Update types to include a new research sidebar icon.
- Update an existing API router to fetch research items.
---
### 2. Assess Available Information
- **Codebase Structure**:
- **Client-side Dashboard**: `/src/app/dashboard`
- Workspace components are in `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace`.
- Sidebar component is in `/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx`.
- Dashboard layout is managed in `/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx`.
- **Types Definitions**: `/src/types.ts`.
- **API Routers**: `/src/server/api/routers`.
- Existing routers like `events.ts` handle data fetching.
- **Existing Components and Functions**:
- **Workspace Components**: `Code`, `Issue`, `PullRequest`, etc.
- **Sidebar**: Manages navigation between workspace components.
- **API Functions**: Fetch data related to tasks, events, and projects.
---
### 3. Review Exit Criteria
- **Acceptance Criteria**:
- [ ] A new `Research.tsx` component is created in the `workspace` directory.
- [ ] The component fetches research items based on the task/issue ID.
- [ ] Research questions and answers are rendered, with answers displayed in markdown format.
- [ ] The new component is integrated into the workspace area of the dashboard.
- [ ] The sidebar includes an icon for the "Research" component.
- [ ] The new component follows existing design and styling conventions using Tailwind CSS.
- [ ] Types are updated to add a new research sidebar icon.
- [ ] An existing API router is updated to include a method for fetching research items from the database.
---
### 4. Plan Code Changes
#### Step 1: Create the `Research.tsx` Component
- **Tool**: `CreateNewCode`
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx`
- **Instructions**:
- Create a new React component named `Research`.
- Use `useEffect` and `useState` hooks to fetch research items based on the current task or issue ID.
- Fetch data using the API method `api.events.getResearchItems`.
- Render a list of research questions and answers.
- Display answers using a markdown renderer like `react-markdown`.
- Apply Tailwind CSS classes to match the existing design.
#### Step 2: Update the API Router to Fetch Research Items
- **Tool**: `EditExistingCode`
- **File Path**: `/src/server/api/routers/events.ts`
- **Instructions**:
- Import necessary modules and the database client.
- Add a new method `getResearchItems` to fetch research items from the database:
```typescript
getResearchItems: publicProcedure
.input(z.object({ taskId: z.string() }))
.query(async ({ input, ctx }) => {
const researchItems = await ctx.db.research.findMany({
where: { taskId: input.taskId },
});
return researchItems;
}),
```
#### Step 3: Update Types to Include the Research Sidebar Icon
- **Tool**: `EditExistingCode`
- **File Path**: `/src/types.ts`
- **Instructions**:
- Update the `WorkspaceItemType` or relevant type to include `'Research'`:
```typescript
export type WorkspaceItemType = 'Code' | 'Issue' | 'PullRequest' | 'Research' | 'Todos' | 'Workspace';
```
- If there is an icon type or enum, add the new icon type.
#### Step 4: Update the Workspace Index to Export the `Research` Component
- **Tool**: `EditExistingCode`
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx`
- **Instructions**:
- Import the `Research` component:
```typescript
import Research from './Research';
```
- Export the `Research` component alongside other workspace components:
```typescript
export { Code, Issue, PullRequest, Research };
```
#### Step 5: Integrate the `Research` Component into the Dashboard
- **Tool**: `EditExistingCode`
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx`
- **Instructions**:
- Import the `Research` component:
```typescript
import { Research } from './components/workspace';
```
- Modify the rendering logic to include the `Research` component based on the selected workspace item:
```jsx
{selectedWorkspaceItem === 'Research' && <Research taskId={currentTaskId} />}
```
#### Step 6: Update the Sidebar to Include the "Research" Component
- **Tool**: `EditExistingCode`
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx`
- **Instructions**:
- Import a suitable icon for "Research", e.g., `LightBulbIcon` from Heroicons:
```typescript
import { LightBulbIcon } from '@heroicons/react/outline';
```
- Add a new sidebar item for "Research":
```typescript
{
name: 'Research',
icon: LightBulbIcon,
workspaceType: 'Research',
},
```
- Ensure the sidebar updates the `selectedWorkspaceItem` state when "Research" is clicked.
#### Step 7: Ensure Styling Consistency Using Tailwind CSS
- **Tool**: `EditExistingCode`
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx`
- **Instructions**:
- Apply Tailwind CSS classes to match existing components.
- Use consistent margins, paddings, fonts, and colors.
- Ensure the component is responsive and accessible.
#### Step 8: Fetch and Display Research Items in `Research.tsx`
- **Tool**: `EditExistingCode`
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx`
- **Instructions**:
- Use the `useQuery` hook from `@tanstack/react-query` or the equivalent in your setup to fetch data:
```typescript
const { data: researchItems, isLoading } = api.events.getResearchItems.useQuery({ taskId });
```
- Handle loading and error states.
- Render each research item's question and answer:
```jsx
{researchItems.map((item) => (
<div key={item.id} className="mb-4">
<h3 className="text-lg font-semibold">{item.question}</h3>
<div className="prose">
<ReactMarkdown>{item.answer}</ReactMarkdown>
</div>
</div>
))}
```
---
### 5. Finalize the Plan
- **Dependencies and Order of Execution**:
1. **CreateNewCode**: Create `Research.tsx` component.
2. **EditExistingCode**: Update API router in `events.ts` to provide data for the component.
3. **EditExistingCode**: Update types in `/src/types.ts`.
4. **EditExistingCode**: Export `Research` component in `workspace/index.tsx`.
5. **EditExistingCode**: Integrate `Research` component in `Dashboard.tsx`.
6. **EditExistingCode**: Update `Sidebar.tsx` to include the "Research" icon.
7. **EditExistingCode**: Apply Tailwind CSS styling in `Research.tsx`.
8. **EditExistingCode**: Fetch and display research items in `Research.tsx`.
- **Verification**:
- All acceptance criteria are addressed.
- All specified files are included and correctly modified.
- The plan follows a logical order respecting dependencies.
- Instructions are clear, detailed, and actionable.
---
**Summary**: This plan outlines the steps required to add a new "Research" component to the dashboard workspace, ensuring all requirements are met and design consistency is maintained. Each step specifies the file to be modified or created, the tool to use, and detailed instructions to implement the changes effectively.
_____________END o1____________
_____________START 4o__________
### Step 1: Create Research Component
#### Files:
/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx
#### Details:
Create a new React component named `Research.tsx` within the `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/` directory. This component should be responsible for fetching research items from the database based on the task/issue ID and rendering the research questions and answers. Ensure the answers are displayed in markdown format. Use Tailwind CSS for styling to match the existing design language of the dashboard components.
#### Exit Criteria
A new `Research.tsx` component is created and capable of fetching and displaying research items in markdown format.
### Step 2: Integrate Research Component into Workspace
#### Files:
/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx
#### Details:
In the file `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx`, import the newly created `Research.tsx` component and include it in the workspace area. Ensure it is conditionally rendered based on the current selection in the sidebar.
#### Exit Criteria
The `Research.tsx` component is integrated into the workspace area of the dashboard.
### Step 3: Update Sidebar with Research Icon
#### Files:
/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx
#### Details:
Modify `/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx` to add a new icon for the Research component. Use an appropriate icon that matches the design and theme of the existing sidebar icons. Ensure this new icon is linked to the `Research.tsx` component, allowing users to toggle its view in the workspace area.
#### Exit Criteria
A new icon for the Research component is added to the sidebar, allowing users to toggle its view.
### Step 4: Add Research Sidebar Icon Type
#### Files:
/src/types.ts
#### Details:
Update `/src/types.ts` to include a new type for the research sidebar icon. This type should be used to handle the state and selection logic for displaying the Research component in the dashboard workspace.
#### Exit Criteria
A new type for the research sidebar icon is added to handle its state and selection logic.
### Step 5: Update Events API Router
#### Files:
/src/server/api/routers/events.ts
#### Details:
Enhance the file `/src/server/api/routers/events.ts` by adding a new method to fetch research items from the database. This method should query the research table based on the task/issue ID and return the relevant research items to the frontend.
#### Exit Criteria
A new method for fetching research items from the database is added to the Events API router.
### Step 6: Pass Props for Research Component
#### Files:
/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx
#### Details:
Modify `/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx` to pass necessary props to the workspace component for the Research component. These props should include the task/issue ID and any other relevant information needed to fetch and display the research items.
#### Exit Criteria
Necessary props are passed to the workspace component for the Research component.
_________END 4o___________
@kleneway
Copy link
Author

kleneway commented Sep 12, 2024

Here's the prompt:
Here is some information about a codebase:
(... codebase context with file names and tree-sitter info about files)
Here is a GitHub issue for this codebase:

Add Research Component to Dashboard Workspace

Description

We need to add a new "Research" component to the dashboard application to display research items. Currently, the dashboard shows items such as Prompts, Code, Issue, Pull Request, etc. With the addition of research items in the database, we should also display them in the dashboard.

For this task, we need to create a new component that displays all the research objects for a specific task/issueId. This component should:

  • Fetch research items from the database based on the task/issue ID. This should be done in a similar manner to other components like prompts or code.
  • Render the research answers in markdown.
  • Use the same design language as the other workspace components.

Requirements

  1. Create a new component Research.tsx in the workspace directory.
  2. Fetch research items for the currently selected task or issue in a similar way that is done with the prompts or code.
  3. Render the research questions and answers, ensuring the answers are displayed in markdown format.
  4. Integrate the new component into the workspace area of the dashboard.
  5. Update the sidebar to include an icon for the "Research" component.
  6. Ensure the new component follows the existing design and styling conventions. Be sure to use Tailwind CSS.
  7. Update the types to add a new research sidebar icon.
  8. Update an existing API router to include a method for fetching research items from the database.

New Files:

  • /src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx

Files to Update:

  • /src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx
  • /src/types.ts
  • /src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx
  • /src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx
  • /src/server/api/routers/events.ts

Acceptance Criteria:

  • A new Research.tsx component is created in the workspace directory.
  • The component fetches research items based on the task/issue ID.
  • Research questions and answers are rendered, with answers displayed in markdown format.
  • The new component is integrated into the workspace area of the dashboard.
  • The sidebar includes an icon for the "Research" component.
  • The new component follows the existing design and styling conventions using Tailwind CSS.
  • Types are updated to add a new research sidebar icon.
  • An existing API router is updated to include a method for fetching research items from the database.
Please come up with a detailed plan for this issue.  
### Task:
          1. Understand the Problem:
              - Thoroughly review the GitHub issue inside the <github_issue> tags and identify the core problem to be solved.
              - Break down the issue into smaller, manageable tasks.
      
          2. Assess Available Information:
              - Analyze the provided codebase source map to understand the structure and relevant files.
              - Review the gathered research to identify any relevant code snippets, functions, or dependencies.
      
          3. Review Exit Criteria:
              - Analyze the exit criteria specified in the GitHub issue to understand the expected outcomes. If no exit criteria are provided, create measurable criteria for each file modification or creation.
              - Ensure that the changes made to the codebase align with the exit criteria. Each step of the plan should check off one or more exit criteria.
              - Ensure that no exit criteria are missed or overlooked during the planning process.
          
          4. Plan Code Changes:
              - Use the list of specific files within the  <files> tags that need to be modified or created to address the issue.
              - For each plan step, follow these guidelines:
                  - Specify the exact file path in the filePath tool output.
                  - Provide clear, detailed instructions on the changes to be made. You MUST use the research data and/or GitHub issue to inform your instructions. DO NOT make up instructions! If you do not have specific instructions you can be very general, but you MUST use the research data and/or GitHub issue to inform your instructions. NEVER make up specific instructions that are not based on the research data and/or GitHub issue.
                  - Include any necessary code snippets, imports, or function calls.
                  - Minimize the number of files that are modified per step.
              - Outline the order in which the changes should be made.
      
          5. Finalize the Plan:
              - Review the plan to ensure all necessary changes are accounted for.
              - Ensure that no files in the <files> tags are missed or incorrectly included.
              - Determine dependencies between files and use this information to specify the order of changes.
      
      ### Important:
          - Use the following tools to create your plan:
              - EditExistingCode: Modify one existing file in the codebase.
              - CreateNewCode: Create a new file in the codebase.
          - Each tool should be used with specific instructions and file paths.
          - You should have at least one function call per file in the <files> tag. You can have more if needed.
          - Ensure that the plan is clear, detailed, and follows the guidelines provided.
          - Create the shortest plan possible that addresses all necessary changes. Avoid unnecessary steps or complexity.
      
      Develop a comprehensive plan that outlines the necessary code changes to resolve the GitHub issue effectively. Your plan should be concise, specific, actionable, and easy for another developer to follow and implement.  
      Remember to leverage the provided file list, codebase information and research to make informed decisions and create a plan that effectively addresses the GitHub issue. Double-check your plan for completeness and clarity before submitting it.

@kleneway
Copy link
Author

kleneway commented Sep 12, 2024

o1 code for Research.tsx

import React from 'react';
import { api } from '~/utils/api';
import ReactMarkdown from 'react-markdown';

interface ResearchProps {
  taskId: string;
}

const Research: React.FC<ResearchProps> = ({ taskId }) => {
  const { data: researchItems, isLoading, isError } = api.events.getResearchItems.useQuery({ taskId });

  if (isLoading) {
    return <div className="p-4">Loading research items...</div>;
  }

  if (isError) {
    return <div className="p-4 text-red-500">Failed to load research items.</div>;
  }

  return (
    <div className="p-4">
      {researchItems && researchItems.length > 0 ? (
        researchItems.map((item) => (
          <div key={item.id} className="mb-8">
            <h2 className="text-xl font-semibold mb-2">{item.question}</h2>
            <div className="prose">
              <ReactMarkdown>{item.answer}</ReactMarkdown>
            </div>
          </div>
        ))
      ) : (
        <div>No research items available for this task.</div>
      )}
    </div>
  );
};

export default Research;

@kleneway
Copy link
Author

Sonnet 3.5 code:

import React, { useEffect, useState } from "react";
import { api } from "../../../../../../../trpc/react";
import { type ResearchItem } from "@/types";
import ReactMarkdown from "react-markdown";

interface ResearchProps {
  taskId: string;
}

const Research: React.FC<ResearchProps> = ({ taskId }) => {
  const [researchItems, setResearchItems] = useState<ResearchItem[]>([]);

  const {
    data: fetchedResearchItems,
    isLoading,
    error,
  } = api.events.getResearchItems.useQuery({ taskId });

  useEffect(() => {
    if (fetchedResearchItems) {
      setResearchItems(fetchedResearchItems);
    }
  }, [fetchedResearchItems]);

  if (isLoading)
    return <div className="text-center">Loading research items...</div>;
  if (error)
    return (
      <div className="text-center text-red-500">
        Error loading research items
      </div>
    );

  return (
    <div className="space-y-4">
      <h2 className="mb-4 text-2xl font-bold">Research</h2>
      {researchItems.length === 0 ? (
        <p>No research items found for this task.</p>
      ) : (
        researchItems.map((item, index) => (
          <div key={index} className="rounded-lg bg-white p-4 shadow">
            <h3 className="mb-2 text-lg font-semibold">{item.question}</h3>
            <div className="prose max-w-none">
              <ReactMarkdown>{item.answer}</ReactMarkdown>
            </div>
          </div>
        ))
      )}
    </div>
  );
};

export default Research;

@kleneway
Copy link
Author

kleneway commented Sep 12, 2024

The code produced by o1 is quite good. Notice that sonnet takes the unnecessary step of useState when it's not needed for react query. Both handle errors well but o1 feels slightly better (using the isError bool instead of the error string, checking that researchItems exists). Designs are similar but Sonnet is trying harder to make something look nice (using the rounded corners and shadows to make cards vs just a list of text). Both incorrectly imported the api path but I don't believe that specific path was provided in the context. Original PR is here, I'll update JACoB with o1 in the next 24 hours to see how it performs in an agent workflow: https://github.com/kleneway/jacob/pull/84/files

@vrushankportkey
Copy link

vrushankportkey commented Sep 13, 2024

o1 is better, but it is also much better at describing its reasoning. Makes me think - if it can so clearly reason, can it be persuaded towards an outcome you want by reasoning tactics, i.e. rather than describing the steps of solving a problem like how we do right now, we tell it where it failed and why, and it should self-correct much better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment