How to create an AI Powered Cover Letter Generator
Howto & Style
How to Create an AI Powered Cover Letter Generator
Welcome to this tutorial from AI Innovate 360 on creating an automated cover letter using the power of generative AI. This can easily be done by integrating Chat GPT into a Word document and creating a job application cover letter generator. In this step-by-step tutorial, I will guide you through the steps for setting up an AI cover letter generator inside Microsoft Word, including the VBA macro code invoking the OpenAI API and generating the customized cover letter for each job you are applying for. If you are not familiar with the term VBA, it stands for Visual Basic for Applications, which is a programming language that you can use inside of Word documents.
As the job market becomes increasingly competitive, finding ways to stand out is crucial. One effective way to do this is by creating a personalized cover letter highlighting your skills and experiences. However, writing cover letters can be time-consuming and repetitive. This is where the innovation of AI cover letter automation comes into play, streamlining the task and saving you valuable time.
You may already be familiar with the ChatGPT chat interface, but there is also the ability to use ChatGPT features through a programmatic approach by having code called the APIs. An API is an Application Programming Interface. Many applications provide APIs to allow for another program or application to use their features. The ChatGPT API allows you to incorporate the model's capabilities into an application, such as Word, enabling programmatic text generation. We will be exploiting this API approach to provide you with a way to invoke ChatGPT without having to log into the UI.
ChatGPT's capabilities are based on its ability to predict the next word or phrase given a prompt. By leveraging this capability, we can provide ChatGPT with a cover letter prompt and let it generate a coherent and personalized response. With a few tweaks, we can transform these responses into professional cover letters tailored to specific job opportunities.
To be able to create this cover letter generator, you will need a few different prerequisites. Let me take you through what is required for this generator:
OpenAI API Account: This account allows you to use the API and call them directly from Word macros. This is not the usual ChatGPT account; it uses the OpenAI API plan. You can find the link to the website to create your OpenAI API plan account in the description below. Be sure to create this account before you begin the remaining steps in this document.
Access to Microsoft Word: To be able to call the APIs, you could create your own UI to invoke the APIs, but this is a much more involved task. Since I also needed a place to put the created cover letter text, I decided I could take advantage of using the Word document as the place to call the APIs and also place the generated text. I used Microsoft Word for Microsoft 365 in these step-by-step instructions. If you have a different version of Word, the steps may vary a bit since Microsoft sometimes does change the interface between different versions, but be assured the general approach will still apply.
Familiarity with Programming: A familiarity with programming with Visual Basic macros in Microsoft Word would be very helpful in the event you have any problems or difficulties. I've attempted to give you as much detail as possible in this video, but you may run into new problems; therefore, some familiarity with programming would be helpful to ensure you can set up the environment correctly and copy the code that calls ChatGPT.
Macro-Enabled Word Document: You will be required to use a macro-enabled Word document. For security reasons, the default Word document type does not allow macros to be invoked. Therefore, you will be required to change the default to a Microsoft Word macro-enabled document, which allows you to create and add macros.
Now that you have a basic understanding of what tools are involved, let's dive into the step-by-step tutorial on how to generate cover letter content programmatically in Word. The input to the generated cover letter is your resume and a job description. Having both as input results in a better overall cover letter as it can generate a cover letter that matches your skills and experience and customizes the letter to target the requirements of the job posting. You will end up with a cover letter tailored to your skills and the specific job description for the role you are applying for.
For this approach, I've decided to use the Word document as the place to get the input and to place the generated text output. Therefore, I've defined a format in the Word document for you to use for inserting your resume and the job description. The format that I defined allows the VBA macro to search for and find the input text. It uses a set of delimiters in the document that indicate where the resume and job description start and end. The text in green indicates the delimiters in the Word document so that the VBA code can find the input. The VBA code will search and find the resume start and end markers of "Resume" and "Resume End," respectively. It will also search and find the job description markers of "Job Description" and "Job Description End." Any text between these delimiters will be considered input to the resume and the job description. The color of the text does not matter; I've just shown it in green here to indicate the delimiters.
Therefore, create a Word document that has this basic format and replace the text in red with the appropriate input text for your cover letter generation. Once you have everything set up and are creating cover letters, I would also suggest you add additional skills or experiences to the input text that you may not have in your resume, but you want to have considered as part of the cover letter generation.
Now let's set up a Word document with macro support to be able to interact with the API. A Word macro is a set of instructions that automates tasks in Word. In this case, we will use the macro programmed in Visual Basic to invoke the API and retrieve the generated cover letter content. To set up the Visual Basic Word macro, you should open Word and navigate to the Developer tab. If you do not see the Developer tab in Word, add it to your view; by default, it is not shown. To add the Developer tab, navigate to File -> Options -> Customize Ribbon -> check the Developer Tab box -> and click OK. Now you should see the Developer tab on your Ribbon. With the Developer tab now in place, we can integrate the OpenAI API in the subsequent steps of our setup.
Let's get into the steps of integrating the VBA code into the Word document. In Word, navigate to the Developer tab and click on Visual Basic to open the Microsoft VBA editor. This will open the VBA editor and allow you to create the macro needed to call the API. On the top toolbar of the VBA editor, select Insert -> Module to open an empty module creation window. You will want to copy the VBA code into this empty module window. I provide the VBA code you need in the link as shown. Follow the link for the code and copy and paste all the Visual Basic code into the new module. I'd suggest renaming the module in the editor window by choosing View -> Properties Window, which will open the properties for this new module. You'll notice it is initially named "Module1." In the properties window, choose a more meaningful name; you can see I have chosen "GenCoverLetter."
On the README for the cover letter generation module, you can see the list of dependencies. The JSON converter and the dictionary modules are also used in this code and must be inserted and referenced for the macro code to run properly. It is used to parse the response returned from the API. If you do not import these modules, you will receive a runtime error indicating that the modules cannot be found. The instructions for installing these modules can be found on the README page of those modules’ GitHub URLs. You will find the link for these JSON converter and dictionary modules either in the README for the cover letter generation module or as shown. Import them using File -> Import File on the VBA editor toolbar. Once you have the modules imported, you will see them listed in the editor window.
Before moving on, there are a few things I'd like to point out in the VBA macro. The default language model used in the text generation is GPT-3.5 Turbo. You can change this to use other models of your choice. The API called to generate the text is the Chat Completions API. This API is compatible with a specific list of language models, which changes over time. I recommend checking the OpenAI website to ensure you use a compatible model. The crucial line of code that instructs OpenAI on the desired behavior is the code that sets the systemPrompt variable. This directive is a key part of the ChatGPT cover letter prompt, and I found it to be effective in guiding OpenAI in producing the type of cover letter I desired. There is error handling in the code to ensure the resume and job description text are found. If something is missing in the document and the text delimiters cannot be found, messages will be sent to the Word UI.
We are getting close to being able to try your first call to OpenAI. Just a few more steps need to be done, and you will be ready to try it out. To be able to call the API, you need to use something called an API key. Think of this as any other key that locks and unlocks the ability to use something. In this case, it provides you with the key to unlock your OpenAI API account. Log into your OpenAI API account that you created in the prerequisite step and access the API key tab. I have provided the link to the API key page as shown. In the API keys UI, click Create New Secret Key to create a new API key. Once the API key is created, make sure to copy the API key into the indicated line of macro code shown. Carefully replace the placeholder with your unique key to ensure secure access to the OpenAI API from your personal account. Remember, this key is confidential and should not be shared as it serves as your exclusive access to your account.
Now that you have the VBA macro created and using your API key, you can test the macro and ensure it is set up properly. Make sure you have copied a resume and job description between the delimiters in the document. You can see the example resume and job description shown. If the document is ready, go to the Quick Access Toolbar and click Macros. If you do not see the View Macros on the Quick Access Toolbar, you will need to add it. Choose File -> Options -> Quick Access Toolbar and add Macros.
Once you can view the macros, a window with the macros in your document will open. Select Run for the View Macros "GenCoverLetter" to run the macro on the currently open document. If the macro call to ChatGPT is successful, a cover letter will be generated and inserted into the Word document after the existing text as seen here. If no cover letter is inserted, check if an error message indicates possible problems. If there are errors, check the earlier steps to ensure that all actions have been implemented properly.
You can rerun the cover letter generator multiple times, and the new text will always be appended to the end of the document. Due to the nature of the generative AI, each time you run the generator, it will produce different results. The advantage of this is it allows you to run it a few times and select the text you prefer.
Automated cover letter writing offers several advantages, such as saving time and effort, ensuring consistency, and providing a starting point for customization. However, it's important to be aware of its limitations as well. This AI cover letter generator provides a solid starting point, but it's important to customize and format the letter to suit your needs and add a personal touch. AI can sometimes create incorrect information, so carefully check that the skills and experience are correct and that the AI did not add skills that you do not have.
Hopefully, this automated cover letter generator is helpful, and you found this video provided you with the guidance to be able to create your own AI tool. If you do encounter problems or errors as you run the code, I'd suggest you check out my blog post where it lists some potential errors you may encounter and how to resolve them.
Keywords
- AI Cover Letter Generator
- Generative AI
- ChatGPT
- OpenAI API
- Visual Basic for Applications (VBA)
- Microsoft Word Macros
- API Integration
- Automated Writing
- Personalized Cover Letters
FAQ
Q: What is VBA? A: VBA stands for Visual Basic for Applications, a programming language used inside Microsoft Word documents to automate tasks.
Q: Why do I need an OpenAI API account? A: The OpenAI API account is required to use the ChatGPT API, which will generate the cover letter text programmatically.
Q: Can I use older versions of Microsoft Word? A: Yes, but steps may vary slightly due to interface changes between different versions of Word.
Q: What are the required delimiters in the Word document? A: The delimiters are "Resume," "Resume End," "Job Description," and "Job Description End." These help the VBA code identify input text within the document.
Q: How do I add the Developer tab in Word? A: Navigate to File -> Options -> Customize Ribbon -> check the Developer Tab box -> click OK.
Q: Where do I place my OpenAI API key? A: Place your API key in the specified line of the VBA macro code, replacing the placeholder.
Q: Can I customize the language model used? A: Yes, the default language model is GPT-3.5 Turbo, but you can change it to use other compatible models.
Q: What should I do if I encounter a runtime error? A: Ensure all dependencies, such as the JSON converter and dictionary modules, are imported and referenced properly in the VBA editor.
Q: Will the generated cover letter include errors? A: AI-generated text can sometimes include incorrect information. Always proofread and customize the generated cover letter to ensure accuracy.