Skip to content

Instantly share code, notes, and snippets.

@calebdre
Created June 14, 2024 20:57
Show Gist options
  • Save calebdre/4441d4e21cd5880c80913408579714ce to your computer and use it in GitHub Desktop.
Save calebdre/4441d4e21cd5880c80913408579714ce to your computer and use it in GitHub Desktop.
export const getFunctionDescription = async (file: FileInfo, functionName: string, model: string = "llama3"): Promise<string | null> => {
const prompt = `given the following file ${file!.path}/${file!.filename}:
\`\`\`typescript
${file!.content}
\`\`\`
Provide a concise description for the function \`${functionName}\`. focusing on its specific role within the larger codebase.
The description should briefly explain:
- The purpose of the function
- The function's inputs, outputs, and any notable side effects or dependencies
- Any notable aspects or behavior of the function
Aim for a clear, concise, and technically accurate description that provides the necessary context, using around 2-3 sentences.
Respond ONLY with the description.`
try {
const response = await ollama.chat({
model: model,
messages: [{role: 'user', content: prompt}]
})
return response.message.content
} catch (e) {
console.error(e)
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment