←新闻详情

OpenHands 官方博客更新于 10月12日 19:45

用 OpenHands 开源 AI 智能体构建前端应用

Building a Frontend App with Open Source AI Agents | Sep 10, 2024

AI 导读

All Hands AI 团队用开源 AI 智能体 OpenHands 构建了一个 GitHub PR 查看器前端,从零到可用约 30 分钟。作者用详细提示词指定 react + vite + typescript 技术栈,并让智能体自行测试;期间需人工反馈浏览器控制台报错、修复每仓库仅显示 10 个 PR 的分页限制,并追加暗色模式与 MIT 许可证。

正文

当前显示原文,中文全文译文尚未就绪。

I consider myself a pretty good Python programmer. I can architect systems, build backend servers, train models, etc. One thing that I'm not super-good at, though, is frontend development. Many times I've wanted to show off a project that includes a cool UI or build a tool that would be helpful for my own workflow, but I usually hesitate because it would take me too long to crank one out.

Luckily, with the help of recent AI tools, that barrier has significantly lowered, and it's now possible to build practical frontend apps, almost entirely automatically. In this post I'll demonstrate how I built a frontend for a GitHub Pull Request viewer using OpenHands, the open-source AI agent for software development that we're building at All Hands AI.

The GitHub PR viewer is an example of something that's simple but practical -- it allows me as a developer to view all open PRs across my team's GitHub repositories, and it would have been a pain to build manually, but with OpenHands it took around 30 minutes to go from nothing to something that actually worked and even had a few bells and whistles.

If you want to take a look at the code that the agent built, you can find it here.

Step 1: Setting the Foundation

I began by providing OpenHands with a detailed prompt, outlining the specific requirements for the app.

A few notes about this prompt:

This prompt was intentionally detailed. While AI agents have come a long way, they can sometimes make suboptimal implementation decisions. By breaking down the requirements, I ensured that OpenHands would choose the right path for our project, using the specific tech stack that I'm intereted in (react + vite + typescript); By default the agent doesn't have credentials to access the github api, so I added the token to the .env file, which gives it access. Fortunately, GitHub has very nice personal access tokens that make it easy to create a token with the right permissions so you don't have to give the agent access to repositories in ways that you don't want to. I put this token in a .env file in the OpenHands workspace directory, so the agent can access it; I asked the agent to do testing. This is important because agents have the ability to go back and check if the code is working properly, resolve library issues, etc. But they might not do it unless you ask them to

I let OpenHands do its thing and in a few minutes it had created the repo, initialized the git repo, and added the initial code. Tests passed, and I got something that looked like this:

Um yeah, that's a blank screen. Something is wrong, and unfortunately the agent didn't catch it so I'm going to have to give it a little help.

Step 2: Debugging with AI

While I'm not a huge fan of frontend development, I do know enough to open up the browser and see what's going on. So I fired up the repo (according to the instructions that OpenHands had kindly provided in the README.md), opened up Chrome, went to the developer console, and saw this:

Based on this, I reported this issue back to OpenHands by copying it in the chat window, and asked for a fix. This was enough to put the agent back on the right track, and it quickly came back with a fix. Let's try again and see what we get.

It's a functioning app! This is exactly what we wanted, pretty exciting to get this in just about 10 minutes of work (and drinking coffe while the agent does its thing).

Step 3: Fixing Bugs: API Pagination

However, on closer inspection I noticed that the app was only displaying 10 PRs per repo. This seemed like an API limitation, so I asked OpenHands to modify the backend to retrieve all PRs by default.

OpenHands managed to fix this pretty quickly, so I pushed the resulting code and the app was fully functional.

Step 4: Adding Functionality: Dark Mode

Already, the app looked decent -- it was simple and followed React best practices. But I also like having dark mode for when I'm working in dim places, with a simple prompt below.

The resulting code worked out of the box, and I was able to toggle dark mode on and off with no issues.

Step 5: Open-Sourcing the Project

Finally, I'm a firm believer in the power of open-source software, so I wanted to ensure our project was properly licensed. A simple prompt to OpenHands took care of this:

We can license this repo under the MIT license.

Conclusion

Overall, the resulting app was pretty simple, but it demonstrated how you can go through the steps of building a frontend app with open-source AI agents. Note that this was an iterative process -- there were hiccups that required debugging. And we also didn't get a perfect app out-of-the-box. But using an appropriate agent like OpenHands, you can quickly iterate on ideas and build something that works pretty well.

What's particularly exciting is the potential this holds for developers across all specializations. AI agents like OpenHands can help bridge skill gaps, allowing developers to venture into areas outside their comfort zones with greater confidence.

Acknowledgement: I'd like to thank Bryan Finster of Defense Unicorns for his original inspiration for the app featured here.

What Is An AI Dark Factory? What Lights-Out Manufacturing Teaches Us About Software

Insights and updates from the OpenHands team

Thank you for your submission!

OpenHands is the foundation for secure, transparent, model-agnostic coding agents - empowering every software team to build faster with full control.

来源

OpenHands 官方博客