Skip to content

Commit 6477491

Browse files
blog: add llm support blog
how to make ai
1 parent d3fe6f0 commit 6477491

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

website/blog/more-llm-support.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
author:
3+
- name: Herrington Darkholme
4+
search: false
5+
date: 2025-03-23
6+
head:
7+
- - meta
8+
- property: og:type
9+
content: website
10+
- - meta
11+
- property: og:title
12+
content: ast-grep gets more LLM support!
13+
- - meta
14+
- property: og:url
15+
content: https://ast-grep.github.io/blog/more-llm-support.html
16+
- - meta
17+
- property: og:description
18+
content: ast-grep is getting even better with enhanced Large Language Model (LLM) support. This exciting development opens up new possibilities for developers to analyze, understand, and transform code more efficiently. Let's dive into the details of these new features.
19+
---
20+
21+
# ast-grep Gets More LLM Support!
22+
23+
## Leveling Up Code Analysis with AI
24+
25+
ast-grep, the powerful tool for structural code search, is getting even better with enhanced Large Language Model (LLM) support. This exciting development opens up new possibilities for developers to analyze, understand, and transform code more efficiently. Let's dive into the details of these new features.
26+
27+
## `llms.txt` Support
28+
29+
ast-grep now supports a new file format, [`llms.txt`](https://llmstxt.org/), designed to work seamlessly with LLMs. It is also on [llmstxthub](https://llmstxthub.com/websites/ast-grep) for easy access to the latest files.
30+
31+
A key challenge for large language models is their limited ability to process extensive website content. They often struggle with the complexity of converting full HTML pages, which include navigation, advertisements, and JavaScript, into a simplified text format that LLMs can effectively use.
32+
33+
On the other hand, ast-grep faces challenges due to the limited training data available for LLMs. Because of this, LLMs often confuse ast-grep with other similar tools, even when provided with accurate prompts. Furthermore, despite ast-grep's comprehensive online documentation, LLM search capabilities don't guarantee accurate retrieval of information on rule writing. This hinders ast-grep's widespread adoption in the AI era.
34+
35+
`llms.txt` addresses this by providing models with comprehensive context, enhancing their [in-context learning](https://arxiv.org/abs/2301.00234) and improving the accuracy of their output. It is particularly effective with models that have large context windows, such as [Google’s Gemini](https://aistudio.google.com/).
36+
37+
![Example Usage with $GOOG Gemini](/image/blog/gemini.jpeg)
38+
<center><i><sub>Example llms.txt usage with Gemini. The full doc reduces model hallucination.</sub></i></center>
39+
40+
41+
The general usage of `llms.txt` is as follows:
42+
43+
1. Visit [https://ast-grep.github.io/llms-full.txt](https://ast-grep.github.io/llms-full.txt) and copy the full documentation text
44+
2. Paste these documents into your conversation with your preferred AI chatbot
45+
3. Ask AI questions about ast-grep
46+
47+
48+
## Codemod AI Studio
49+
50+
[Codemod.com](https://codemod.com/) is a long-time [supporter](https://github.com/ast-grep/ast-grep?tab=readme-ov-file#sponsor) of ast-grep and has recently introduced a new feature called [Codemod Studio](https://app.codemod.com/studio).
51+
52+
The studio introduces an AI assistant which is is a game-changer for writing ast-grep rules. This interactive environment allows you to use natural language to describe the code patterns you want to find, and then the AI will help you write the corresponding ast-grep rule. Here's how it works:
53+
54+
* **Describe your goal**: In plain English, explain what you want to achieve with your ast-grep rule (e.g., "Find all instances of `console.log`").
55+
* **AI assistance**: The AI analyzes your description and suggests an appropriate ast-grep pattern.
56+
* **Refine and test**: You can then refine the generated rule, test it against your codebase, and iterate until it meets your needs.
57+
58+
This innovative approach democratizes ast-grep rule creation, making it accessible to developers of all skill levels, even without previous experience with ast-grep.
59+
60+
## GenAI Script Support
61+
62+
Microsoft’s GenAI Script supports [ast-grep](https://microsoft.github.io/genaiscript/reference/scripts/ast-grep/)!
63+
64+
> [GenAIScript](https://microsoft.github.io/genaiscript/) is a scripting language that integrates LLMs into the scripting process using a simplified JavaScript syntax. Supported by our VS Code GenAIScript extension, it allows users to create, debug, and automate LLM-based scripts.
65+
66+
Notably, GenAIScript provides a wrapper around `ast-grep` to search for patterns within a script's AST and transform that AST. This enables the creation of highly efficient scripts that modify source code by precisely targeting specific code elements.
67+
68+
69+
## Upcoming MCP Support
70+
71+
Looking ahead, ast-grep has a plan to support [Model Context Protocol](https://modelcontextprotocol.io) (MCP). This upcoming feature will further enhance the integration of LLMs with ast-grep, enabling even more sophisticated code analysis and transformation.
72+
73+
MCP will provide a standardized interface for LLMs to interact with ast-grep, streamlining the process of analyzing and transforming code. Some of the key features of ast-grep MCP include:
74+
75+
* List all ast-grep's [resources](https://modelcontextprotocol.io/docs/concepts/resources) in the project: rules, utils, and test cases.
76+
* Orchestrate the LLM's actions by providing predefined [prompts](https://modelcontextprotocol.io/docs/concepts/prompts) and workflows.
77+
* Provide [tools](https://modelcontextprotocol.io/docs/concepts/tools) to create/validate rules and search the codebase.
78+
79+
See the tracking GitHub issue [here](https://github.com/ast-grep/ast-grep/issues/1895)
80+
81+
82+
## Conclusion
83+
84+
ast-grep's integration of LLMs, including `llms.txt`, Codemod AI Studio, and GenAI Script, represents a significant leap forward in code analysis. With the promise of MCP on the horizon, ast-grep is poised to become an indispensable tool for developers seeking to harness the power of AI to understand, transform, and elevate their code. The future of code analysis is here, and it's powered by ast-grep.

website/public/image/blog/gemini.jpeg

99.6 KB
Loading

0 commit comments

Comments
 (0)