"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Generating a JSDoc comment for your function using OpenAI.

Generating a JSDoc comment for your function using OpenAI.

Published on 2024-08-25
Browse:140

This article is inspired by Remotion’s internal package, ai-improvements. This internal package is used to improve/generate JSDoc comment and log in the console for a function in the Remotion’s source code.

This use case is quite different because you would normally use the source code and let OpenAI generate API documentation but instead in Remotion, this internal package uses the OpenAI API to generate JSDoc comment for a function using API documentation and the source code.

Generating a JSDoc comment for your function using OpenAI.

We will look at a high level how this package is configured:

  1. improve-docs.ts
  2. generate-jsdoc

Improve docs

import path from "path";
import { OpenAI } from "openai";
import { getApis } from "./map-over-api";
import { findMistakes } from "./tasks/find-mistakes";
import { generateJSDocTask } from "./tasks/generate-jsdoc";

improve-docs.ts has the above imports. generateJSDocTask is imported from ‘tasks’ folder.

Generating a JSDoc comment for your function using OpenAI.

depending on the task, you could either generate a JSDoc or find mistakes.

Generate JSDoc

Generating a JSDoc comment for your function using OpenAI.

generate-jsdoc.ts uses the openai API and has prompts as shown in the above image.

Generating a JSDoc comment for your function using OpenAI.

Please note that this will only write the generated JSDoc to the console. Would it be possible to write these JSDoc comments programatically in the file? Not sure, but it is worth reading the AST documentation to see if there’s any API available to add JSDoc comments just above the function or class name. ts-morph is known to be used in shadcn-ui/ui to manipulate the source code at AST level.

Generating a JSDoc comment for your function using OpenAI.

About us:

website: https://thinkthroo.com/

Github: https://github.com/thinkthroo/thinkthroo (Do give us a star!)

Build open source projects from scratch for free

Improve your team coding skills.

Need help with a project? Contact us at [email protected]

References:

https://github.com/remotion-dev/remotion/tree/main/packages/ai-improvements

https://github.com/remotion-dev/remotion/blob/main/packages/ai-improvements/improve-docs.ts

https://github.com/remotion-dev/remotion/blob/main/packages/ai-improvements/tasks/generate-jsdoc.ts

https://github.com/remotion-dev/remotion/blob/main/packages/ai-improvements/tasks/find-mistakes.ts

https://github.com/remotion-dev/remotion/blob/main/packages/ai-improvements/map-over-api.ts

https://github.com/remotion-dev/remotion/blob/main/packages/docs/src/data/articles.ts

Release Statement This article is reproduced at: https://dev.to/thinkthroo/generating-a-jsdoc-comment-for-your-function-using-openai-5215?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

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