어제 처음으로 다른 사람이 내 코드를 검토했습니다. 제가 수강하고 있는 오픈 소스 개발 과정의 과제 중 하나로서 우리는 서로의 코드를 검토해야 했습니다. 이 연습을 위해 나는 꽤 좋은 프로그래머이기도 한 내 친구 Vinh와 짝을 이루었습니다. 우리는 과정에서 각자 작업해 온 명령줄 도구에 대한 서로의 작업을 테스트하고 문제를 제출하는 임무를 맡았습니다.
우리는 텍스트에 대해 동기적으로, GitHub 문제에 대해 비동기적으로 코드 검토를 수행했습니다. 코드 작성자에게 코드를 작성할 때 특정 접근 방식을 취한 이유에 대해 문의하고 즉시 응답을 받을 수 있었기 때문에 동기식 접근 방식이 더 빠른 결과를 가져온다는 것을 알았습니다. 그러나 비동기식 접근 방식을 사용하면 작업을 완료하기 위해 두 사람의 일정에서 고정된 시간을 찾을 필요가 없습니다.
Vinh은 AI를 사용하여 텍스트 문구를 다른 언어로 번역하는 Barrierless라는 명령줄 도구를 만들었습니다. 저는 이것이 멋진 아이디어라고 생각했습니다. 제가 Vinh의 프로그램을 테스트하기 시작했을 때는 아직 초기 개발 단계였기 때문에 아직 README가 없었습니다(지금은 있습니다. 가서 확인해 보세요!).
Barrierless는 한 언어에서 다른 언어로 원활한 번역을 제공하여 언어 장벽을 허무도록 설계된 명령줄 도구입니다. GROQCloud에서 제공하는 이 도구를 사용하면 사용자는 텍스트를 원하는 대상 언어로 신속하게 번역하여 다양한 언어 간 의사소통을 쉽게 할 수 있습니다.
git clone git@github.com:vinhyan/barrierless.git
cd barrierless
npm install
Groq API 키를 저장할 .env 파일 생성
참고: Groq API 키를 얻고 저장하는 방법에 대한 지침은 .env.example을 참조하세요
3단계에서 npm install -g를 사용한 경우 이 단계를 생략하세요…
A feature I really liked is the colorful output text which makes the user experience a little bit more pleasant - something I neglected in my own program in trying to model it after CLI tools like git.
I read the package.json file to find out how the program should be run, and when it immediately crashed I realized I forgot to add the API key as an environment variable. After adding my API key, the program ran without errors, although I did find an interesting quirk - the program defaults the output language to English, so if you didn't specify one, and the input was in English, it seemed to choose a language to translate to on its own - either randomly, or based on context from the input.
I opened a few other issues, mostly to do with improving code quality:
index.js contains the following async function calls which are not wrapped in a try/catch block and may lead to an uncaught exception:
export async function main(text, targetLang) {
const chatCompletion = await getGroqChatCompletion(text, targetLang);
console.log(chatCompletion.choices[0]?.message?.content || '');
}
...
program
...
.action(async (text, options) => {
console.log(chalk.blue(`Translating <span class="pl-s1"><span class="pl-kos">${text}</span>...`</span>));
await main(text, options.language);
});
Some changes may be made to to the project make it easier to understand and work on:
The project uses both ES6 import and CommonJS require due to the chalk module requiring the use of import and using import for package.json leading to an error. It would be helpful to add a comment explaining this.
Next it was my turn to be reviewed. I wasn't sure what kind of issues would turn up, but Vinh ended up finding a bunch of issues I hadn't paid attention to:
The README.md file is missing instructions to run npm link, which is necessary for local development and testing of the CLI tool
index.js line 31: typo in variable name: reponseStream
I thought I'd done a pretty good job but goes to show there's always a bug that might've been missed or a feature that could be improved. It was great having a fresh pair of eyes scrutinize the code I wrote. For now, I fixed the typo and updated the README, but the other issues require testing and I plan on getting to those before I release version 0.1.
위 내용은 첫 번째 코드 검토의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!