Code Monkey home page Code Monkey logo

Comments (1)

sweep-ai avatar sweep-ai commented on August 11, 2024

πŸš€ Here's the PR! #108

See Sweep's progress at the progress dashboard!
⚑ Sweep Basic Tier: I'm using GPT-4. You have 5 GPT-4 tickets left for the month and 3 for the day. (tracking ID: 5945fbc808)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

Tip

I can email you next time I complete a pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

GitHub Actionsβœ“

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for b4f3e96
Checking src/components/Chat/Chat.tsx for syntax errors... βœ… src/components/Chat/Chat.tsx has no syntax errors! 1/1 βœ“
Checking src/components/Chat/Chat.tsx for syntax errors...
βœ… src/components/Chat/Chat.tsx has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: πŸ”Ž Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

try {
// Log conversation to our Flask Backend (especially Nomic)
const response = await fetch(
`https://flask-production-751b.up.railway.app/onResponseCompletion`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
course_name: getCurrentPageName(),
conversation: conversation,
}),
},
)
const data = await response.json()
if (!response.ok) throw new Error(data.message)
return data.success
} catch (error) {
console.error('Error in chat.tsx running onResponseCompletion():', error)
return false

// src/pages/api/chat.ts
import { DEFAULT_SYSTEM_PROMPT, DEFAULT_TEMPERATURE } from '@/utils/app/const'
import { OpenAIError, OpenAIStream } from '@/utils/server'
import { ChatBody, Content, ContextWithMetadata, OpenAIChatMessage } from '@/types/chat'
// @ts-expect-error - no types
import wasm from '../../../node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm?module'
import tiktokenModel from '@dqbd/tiktoken/encoders/cl100k_base.json'
import { Tiktoken, init } from '@dqbd/tiktoken/lite/init'
import { getExtremePrompt } from './getExtremePrompt'
import { getStuffedPrompt, getSystemPrompt } from './contextStuffingHelper'
import { OpenAIModelID, OpenAIModels } from '~/types/openai'
import { NextResponse } from 'next/server'
export const config = {
runtime: 'edge',
}

body: JSON.stringify({
course_name: getCurrentPageName(),
conversation: conversation,
}),
},
)
const data = await response.json()
if (!response.ok) throw new Error(data.message)
return data.success
} catch (error) {
console.error('Error in chat.tsx running onResponseCompletion():', error)
return false
}
}
// THIS IS WHERE MESSAGES ARE SENT.
const handleSend = useCallback(
async (message: Message, deleteCount = 0, plugin: Plugin | null = null) => {
// New way with React Context API
// TODO: MOVE THIS INTO ChatMessage
// console.log('IN handleSend: ', message)
// setSearchQuery(message.content)
const searchQuery = Array.isArray(message.content)
? message.content.map((content) => content.text).join(' ')
: message.content;
if (selectedConversation) {
let updatedConversation: Conversation
if (deleteCount) {
const updatedMessages = [...selectedConversation.messages]
for (let i = 0; i < deleteCount; i++) {
updatedMessages.pop()
}
updatedConversation = {
...selectedConversation,
messages: [...updatedMessages, message],
}
} else {
updatedConversation = {
...selectedConversation,
messages: [...selectedConversation.messages, message],
}
}
homeDispatch({
field: 'selectedConversation',
value: updatedConversation,
})
homeDispatch({ field: 'loading', value: true })
homeDispatch({ field: 'messageIsStreaming', value: true })
// Run context search, attach to Message object.
if (getCurrentPageName() != 'gpt4') {
// THE ONLY place we fetch contexts (except ExtremePromptStuffing is still in api/chat.ts)
const token_limit =
OpenAIModels[selectedConversation?.model.id as OpenAIModelID]
.tokenLimit
await fetchContexts(
getCurrentPageName(),
searchQuery,
token_limit,
).then((curr_contexts) => {
message.contexts = curr_contexts as ContextWithMetadata[]
})
}
const chatBody: ChatBody = {
model: updatedConversation.model,
messages: updatedConversation.messages,
key:
courseMetadata?.openai_api_key &&
courseMetadata?.openai_api_key != ''
? courseMetadata.openai_api_key
: apiKey,
prompt: updatedConversation.prompt,
temperature: updatedConversation.temperature,
course_name: getCurrentPageName(),
stream: true,
isImage: false,
}

url: string,
) => {
try {
const API_URL = 'https://flask-production-751b.up.railway.app'
const response = await axios.delete(`${API_URL}/delete`, {
params: { course_name, s3_path, url },
})
// Handle successful deletion, show a success message
showToastOnFileDeleted(theme)
// Refresh the page
await router.push(router.asPath, undefined, { scroll: false, shallow: false })
} catch (error) {
console.error(error)
// Show error message
showToastOnFileDeleted(theme, true)

<DropzoneS3Upload
course_name={course_name}
redirect_to_gpt_4={false}
courseMetadata={courseMetadata}
/>
</div>
</Flex>
{/* NOMIC not bad, not great */}
{/* <iframe className="nomic-iframe pl-20" id="iframe6a6ab0e4-06c0-41f6-8798-7891877373be" allow="clipboard-read; clipboard-write" src="https://atlas.nomic.ai/map/d5d9e9d2-6d86-47c1-98fc-9cccba688559/6a6ab0e4-06c0-41f6-8798-7891877373be"/> */}
</div>
<div className="pt-8 pb-2 flex w-[85%] flex-col items-center justify-center">
{course_data && <MantineYourMaterialsTable course_materials={course_data} />}
{/* This is the old table view */}
{/* <MyTableView course_materials={course_data} /> */}
{/* <CourseFilesList files={course_data} /> */}
</div>
</Flex>
</div>
<GlobalFooter />
</main>
</>
)
}
import {
IconAlertTriangle,
IconCheck,
IconDownload,
IconLock,
} from '@tabler/icons-react'
import { CannotEditCourse } from './CannotEditCourse'
import { type CourseMetadata } from '~/types/courseMetadata'
// import { CannotViewCourse } from './CannotViewCourse'
interface CourseFile {
name: string
s3_path: string
course_name: string
readable_filename: string
type: string
url: string
base_url: string
}
interface CourseFilesListProps {
files: CourseFile[]
}
import { IconTrash } from '@tabler/icons-react'
import { MainPageBackground } from './MainPageBackground'
import { LoadingSpinner } from './LoadingSpinner'
import { extractEmailsFromClerk } from './clerkHelpers'
import Navbar from './navbars/Navbar'
import EditCourseCard from '~/components/UIUC-Components/EditCourseCard'
import { notifications } from '@mantine/notifications'
import GlobalFooter from './GlobalFooter'
import { montserrat_heading } from 'fonts'
import MyTableView from './YourMaterialsTable'
import { MantineYourMaterialsTable } from './MantineYourMaterialsTable'
// const CourseFilesList = ({ files }: CourseFilesListProps) => {
// const router = useRouter()
// const { classes, theme } = useStyles()
// const handleDelete = async (
// course_name: string,
// s3_path: string,
// url: string,
// ) => {


Step 2: ⌨️ Coding

  • Modify src/components/Chat/Chat.tsx βœ“ fe1ac85 Edit
Modify src/components/Chat/Chat.tsx with contents:
β€’ Replace the hardcoded URL in the fetch call with a template literal that uses the RAILWAY_URL environment variable.
β€’ Change line 158 to: `https://\${process.env.RAILWAY_URL}/onResponseCompletion`,
--- 
+++ 
@@ -155,7 +155,7 @@
     try {
       // Log conversation to our Flask Backend (especially Nomic)
       const response = await fetch(
-        `https://flask-production-751b.up.railway.app/onResponseCompletion`,
+        `https://${process.env.RAILWAY_URL}/onResponseCompletion`, 
         {
           method: 'POST',
           headers: {
  • Running GitHub Actions for src/components/Chat/Chat.tsx βœ“ Edit
Check src/components/Chat/Chat.tsx with contents:

Ran GitHub Actions for fe1ac85e2fedb7c61b86733713914291eb75bf3d:
β€’ Vercel Preview Comments: βœ“

  • Modify src/components/Chat/NewChat.tsx βœ“ 070d8ea Edit
Modify src/components/Chat/NewChat.tsx with contents:
β€’ Replace the hardcoded URL in the fetch call with a template literal that uses the RAILWAY_URL environment variable.
β€’ Change line 270 to: `https://\${process.env.RAILWAY_URL}/onResponseCompletion`,
--- 
+++ 
@@ -260,8 +260,8 @@
 
     try {
       // Log conversation to our Flask Backend (especially Nomic)
-      const response = await fetch(
-        `https://flask-production-751b.up.railway.app/onResponseCompletion`,
+            const response = await fetch(
+        `https://${process.env.RAILWAY_URL}/onResponseCompletion`,
         {
           method: 'POST',
           headers: {
  • Running GitHub Actions for src/components/Chat/NewChat.tsx βœ“ Edit
Check src/components/Chat/NewChat.tsx with contents:

Ran GitHub Actions for 070d8eac2ddb5f2c8aa2a9aa4cb84bad780fe5ae:
β€’ Vercel Preview Comments: βœ“

  • Modify src/components/UIUC-Components/YourMaterialsTable.tsx βœ“ 6f5d611 Edit
Modify src/components/UIUC-Components/YourMaterialsTable.tsx with contents:
β€’ Replace the hardcoded URL in the axios.delete call with a template literal that uses the RAILWAY_URL environment variable.
β€’ Change line 57 to: `https://\${process.env.RAILWAY_URL}/delete`,
--- 
+++ 
@@ -53,8 +53,7 @@
     url: string,
   ) => {
     try {
-      const API_URL = 'https://flask-production-751b.up.railway.app'
-      const response = await axios.delete(`${API_URL}/delete`, {
+      const response = await axios.delete(`https://${process.env.RAILWAY_URL}/delete`, {
         params: { course_name, s3_path, url },
       })
       // Handle successful deletion, show a success message
  • Running GitHub Actions for src/components/UIUC-Components/YourMaterialsTable.tsx βœ“ Edit
Check src/components/UIUC-Components/YourMaterialsTable.tsx with contents:

Ran GitHub Actions for 6f5d611e029e2f5e328d5a43e3492f7e63967d7d:
β€’ Vercel Preview Comments: βœ“

  • Modify src/components/UIUC-Components/MakeOldCoursePage.tsx ! No changes made Edit
Modify src/components/UIUC-Components/MakeOldCoursePage.tsx with contents:
β€’ Since the file does not contain a hardcoded URL, no changes are required here. The issue description may have included this file by mistake.
  • Running GitHub Actions for src/components/UIUC-Components/MakeOldCoursePage.tsx βœ— Edit
Check src/components/UIUC-Components/MakeOldCoursePage.tsx with contents:
  • Modify src/pages/api/chat.ts ! No changes made Edit
Modify src/pages/api/chat.ts with contents:
β€’ Replace the hardcoded URL in the fetch call with a template literal that uses the RAILWAY_URL environment variable.
β€’ Change line 158 to: `https://\${process.env.RAILWAY_URL}/onResponseCompletion`,
  • Running GitHub Actions for src/pages/api/chat.ts βœ— Edit
Check src/pages/api/chat.ts with contents:

Step 3: πŸ” Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/move_hardcorded_backend_flask_url_from_a.


πŸŽ‰ Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

πŸ’‘ To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.

from ai-ta-frontend.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.