This week's focus is on Lab 2, which involves contributing to a repository I do not own by creating a pull request (PR). I began by selecting a classmate's repository to work on. Given that JavaScript is my primary programming language, I opted for a JavaScript-based repo to streamline my workflow. While I’m open to exploring other languages, my choice of a JS project saved time and allowed me to work more comfortably. This decision proved beneficial, as the repository I selected had some issues preventing it from running locally. This gave me a head start in understanding the codebase and tackling its challenges. Here's a detailed breakdown of the process:
After reviewing several projects, I decided to contribute to a repository that aimed to convert web page content into a markdown file. After forking and cloning the repo to my local machine, I followed the setup instructions outlined in the README file. However, my classmate appears to be using macOS, which utilizes the ln command for symbolic linking. As I am on Windows, I had to replace this step with the npm link command.
While investigating the setup, I noticed that the package.json file was missing both the start and bin properties, which are necessary for setting up symlinks. I added these entries and advised my classmate to include instructions for Windows users in the documentation. More in details
Once I got the app running, I encountered additional issues. The first problem involved saving the API key that users input to configure Groq's API in a .env file. I wrote a few lines of code to handle the API key storage. Another issue was caused by incorrect code scope for processing the output file, which prevented the app from generating output as expected.
Before implementing the primary feature for this lab—tracking token usage for each request/response—I resolved these two initial problems. For each issue, I created a separate branch and submitted three distinct pull requests.
for await (const chunk of chatCompletion) { process.stdout.write(chunk.choices[0]?.delta?.content || ""); // process.stdout.write(chunk.choices[0]?.delta?.content || ""); response = chunk.choices[0]?.delta?.content || ""; console.log(chunk); if (chunk.x_groq?.usage) { promptTokens = chunk.x_groq?.usage?.prompt_tokens; responseTokens = chunk.x_groq?.usage?.completion_tokens; } }
Regarding my own repository, a classmate named Hyujin Shin contributed to it during Lab 1. Initially, I noticed he seemed to be working on an outdated version of my codebase, as I had since reorganized the structure for clarity and efficiency. He encountered issues related to setting up symlink again, and I provided guidance in Issue #7, suggesting that he pull the latest version before following the symlink setup instructions in the Usage section.
Another issue in my code pertained to output file processing, which stemmed from a mismatch between the option flag and its invocation in the code, preventing proper file processing. I provided a detailed response with visual aids in Issue #8.
For the main feature of this lab—tracking token usage, Hyujin implemented it efficiently without making significant changes to the codebase. Since I had already initialized Groq correctly, he simply needed to extract the usage data from the chatCompletion response:
javascript Copy code // Retrieve Token Usage from Response const promptToken = chatCompletion.usage.prompt_tokens; const completionToken = chatCompletion.usage.completion_tokens; const totalToken = chatCompletion.usage.total_tokens; const tokenInfo = { promptToken, completionToken, totalToken };
After reviewing his feature addition, I merged the PR and tested it, confirming that everything worked as expected.
This lab provided valuable insights into extracting token usage from LLMs (Groq), which I had previously calculated inaccurately by counting words. More importantly, this experience highlighted the significance of collaboration—creating pull requests, receiving code reviews, and merging contributions from others.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3