UNPKG

codebridge-ai

Version:

Complete fullstack AI coding platform with AST-based code integration and local LLM support. Now with comprehensive web technology support (HTML/CSS/JS) plus JavaScript, Python, Rust, and C++.

259 lines (209 loc) 6.57 kB
# GPT-3.5 및 저가형 LLM 호환성 가이드 ## 개요 CodeBridge는 고급 LLM(Claude, GPT-4)뿐만 아니라 GPT-3.5-turbo 같은 저렴한 모델과도 잘 작동하도록 설계되었습니다. 이 가이드는 GPT-3.5의 특성을 고려한 최적 사용법을 제공합니다. ## GPT-3.5 특성 이해 ### 장점 - ✅ 빠른 응답 속도 - ✅ 저렴한 비용 (GPT-4 대비 10배 저렴) - ✅ 기본적인 코드 수정 작업에 충분 - ✅ 간단한 명령 이해 가능 ### 한계점 - ⚠️ 복잡한 명령어 형식 이해 부족 - ⚠️ 일관성 없는 출력 형식 - ⚠️ 불필요한 설명 추가 경향 - ⚠️ `@command` 형식 미지원 ## 전처리기 사용법 ### 설치 ```javascript const { preprocessGPT35Output } = require('./utils/gpt-35-preprocessor'); ``` ### 기본 사용 ```javascript // GPT-3.5 응답 const gptResponse = ` Here's the updated method: \`\`\` getUser(id) { if (!id) throw new Error('ID required'); return this.users.find(u => u.id === id); } \`\`\` `; // 전처리 및 병합 const preprocessed = preprocessGPT35Output(gptResponse); const result = codeBridge.process(originalCode, preprocessed, 'js'); ``` ## 효과적인 프롬프트 작성 ### 기본 템플릿 ``` Update the [methodName] method to [specific change]. Requirements: 1. Return ONLY the updated method code 2. Include the method name and parameters 3. Put the code in a code block using ``` Do not include explanations or additional text. ``` ### 명령어 사용 시 ``` Update the method with these specific changes: - To make it private, add: // @access private - To add logging, add: // @decorator log - To rename, add: // @rename newName Format: // @command value methodName(params) { // implementation } ``` ## 일반적인 시나리오 ### 1. 에러 처리 추가 ``` 프롬프트: "Add error handling to the getData method. Check if id parameter exists and throw an error if not. Return null on any errors. Return only the method code." GPT-3.5 응답 예시: ```javascript getData(id) { try { if (!id) { throw new Error('ID is required'); } return this.data[id] || null; } catch (error) { console.error(error); return null; } } ``` ``` ### 2. 메서드를 비동기로 변경 ``` 프롬프트: "Make the fetchData method async. Add 'async' keyword and use await for fetch calls. Return only the updated method." GPT-3.5 응답 예시: ```javascript async fetchData(url) { const response = await fetch(url); const data = await response.json(); return data; } ``` ``` ### 3. 접근 제어 변경 ``` 프롬프트: "Make the calculateTotal method private. Add this comment above the method: // @access private Return only the method with the comment." GPT-3.5 응답 예시: ```javascript // @access private calculateTotal(items) { return items.reduce((sum, item) => sum + item.price, 0); } ``` ``` ## 전처리기가 처리하는 패턴 ### 자연어 → 명령어 변환 | GPT-3.5 출력 | 변환 결과 | |------------|----------| | "make it private" | `// @access private` | | "add logging" | `// @decorator log` | | "rename to calculateSum" | `// @rename calculateSum` | | "make async" | `// @decorator async` | | "delete this method" | `// @delete` | ### 코드 형식 정규화 | GPT-3.5 출력 | 정규화 결과 | |------------|-------------| | `const getData = function() {}` | `getData() {}` | | `getData: function() {}` | `getData() {}` | | `const getData = () => {}` | `getData() {}` | ## 트러블슈팅 ### 문제: 코드 블록 없음 **해결책**: ```javascript // 전처리기가 자동으로 메서드 추출 const preprocessed = preprocessGPT35Output(responseWithoutCodeBlock); ``` ### 문제: 너무 많은 설명 **해결책**: - 프롬프트에 "Return ONLY the code" 추가 - 전처리기가 자동으로 설명 제거 ### 문제: 잘못된 명령어 형식 **해결책**: ```javascript // 전처리기가 자동 변환 "// make private" → "// @access private" "// add cache decorator" → "// @decorator cache" ``` ### 문제: 들여쓰기 불일치 **해결책**: 전처리기가 자동으로 들여쓰기 정규화 ## 모델별 최적화 ### GPT-3.5-turbo (권장) - 가장 비용 효율적 - 기본적인 코드 수정에 적합 - 응답 속도 빠름 ### GPT-3.5-turbo-16k - 긴 컨텍스트 처리 가능 - 여러 메서드 동시 수정 시 유용 ### text-davinci-003 (레거시) - 더 장황한 응답 - 추가 전처리 필요 ## 성능 비교 | 작업 | GPT-4 | GPT-3.5 + 전처리 | 차이 | |-----|-------|----------------|-----| | 기본 메서드 수정 | 95% | 90% | -5% | | 복잡한 리팩토링 | 90% | 70% | -20% | | 명령어 이해 | 98% | 85%* | -13% | | 비용 | $0.03/1K | $0.003/1K | 90% 절감 | *전처리기 사용 시 ## 권장 사용 사례 ### ✅ GPT-3.5에 적합 - 단순 메서드 수정 - 에러 처리 추가 - 기본적인 검증 로직 - 메서드 이름 변경 - 간단한 비동기 변환 ### ⚠️ GPT-4 권장 - 복잡한 알고리즘 최적화 - 다중 파일 리팩토링 - 고급 디자인 패턴 적용 - 복잡한 타입 시스템 작업 ## 통합 예제 ```javascript const CodeBridge = require('codebridge'); const { preprocessGPT35Output } = require('./utils/gpt-35-preprocessor'); async function enhanceCodeWithGPT35(originalCode, instruction) { // 1. GPT-3.5 API 호출 (예시) const gptResponse = await callGPT35API({ model: "gpt-3.5-turbo", messages: [{ role: "user", content: `${instruction}\n\nReturn only the updated method code in a code block.` }], temperature: 0.3 // 낮은 temperature로 일관성 향상 }); // 2. 전처리 const preprocessed = preprocessGPT35Output(gptResponse.choices[0].message.content); // 3. CodeBridge 처리 const processor = new CodeBridge(); return processor.process(originalCode, preprocessed, 'js'); } ``` ## 비용 최적화 팁 1. **배치 처리**: 여러 메서드를 한 번에 수정 2. **캐싱**: 동일한 패턴의 수정사항 재사용 3. **프롬프트 최적화**: 짧고 명확한 지시사항 4. **온도 설정**: 0.3-0.5로 설정하여 일관성 향상 ## 결론 GPT-3.5는 적절한 전처리와 함께 사용하면 CodeBridge와 효과적으로 작동합니다. 비용 대비 성능이 뛰어나며, 대부분의 일반적인 코드 수정 작업에 충분합니다. ### 핵심 요약 - 🔧 전처리기 필수 사용 - 📝 명확한 프롬프트 작성 - 💰 90% 비용 절감 - ⚡ 빠른 응답 속도 - ✅ 기본 작업에 충분한 성능