iTranslated by AI
Turning ChatGPT into a Web Framework: A Glimpse of the Future
I literally turned ChatGPT into a web framework.
You probably have no idea what I'm talking about, so take a look at the following code.
import { initChatGptGenerator } from "gpt-as-api";
import { Hono } from "hono";
import { cache } from "hono/cache";
const gpt = initChatGptGenerator(
"これからTODOアプリとしてふるまってください。\n今からリクエストを行うので、そのアプリレスポンスを次の指示に従って返却してください。\n\n{{Domain}}"
);
const app = new Hono();
app.get("/", gpt("TODOの管理ができるページをHTMLで適切に返してください。", "html"));
app.all("/api/*", gpt("TODOのAPIとしてレスポンスをJSONで返してください。", "json"));
export default app;
Believe it or not, I was able to create a completely new web framework by making ChatGPT itself function as a TODO app!! ()
While people out there are having ChatGPT write code, there's no need for such difficult tasks—you just have to let ChatGPT become the app?!
Deliverables
Everything I created this time is available at the links and repository below!! Please try out this "new era?" application.
The response time is quite poor, but I think it's interesting because a different page is generated every time!
*Note: API usage limits are in place. If the limit is reached, the app will become inaccessible.
Screenshots




The Mechanism
Have you ever seen tweets on Twitter or elsewhere where people make ChatGPT behave like a shell or a TODO app?
This "framework" automates that process to make it easy to use.
Specifically, it appends the incoming HTTP request to a configured prompt using code like the following and then calls ChatGPT.
const [path, query, body] = [c.req.path, c.req.query(), c.req.parseBody()];
const httpReqString = `
path:
${path}
method:
${c.req.method}
query:
${JSON.stringify(query, null, 2)}
body:
${JSON.stringify(body, null, 2)}`;
Note: Headers are omitted as they contain a lot of information unrelated to the app.
By calling ChatGPT with prompts generated in this way, I am creating applications that behave plausibly based on arbitrary natural language.
While I do some parsing of the responses from ChatGPT, this is the general flow.
Overwhelming Issues
I've been glossing over things with sheer momentum so far, but there are several fatal issues in its current state, which I'll introduce here.
Lack of Stability
I mentioned earlier that the response changes every time you access it, and frankly, this is a fatal flaw.
While you can constrain it to some extent with prompts, it is quite difficult to consistently get responses in the same format. Furthermore, as prompts get longer, the financial impact increases.
Slow Response
As you'll see if you actually try accessing it, the response time is very slow. Well, that's to be expected.
Expensive
This is also natural, as ChatGPT is called for every single request.
Data Cannot Be Persisted
I'll write more about this later, but even if you call the API to add a TODO, it won't be reflected.
Complex Tasks Are Impossible
The more complex the task, the slower and more expensive the response becomes.
Prompt Injection
If you build an entire application this way, someone might steal administrative privileges or other sensitive information using malicious prompts.
Data Persistence
In its current stage, what I've created cannot persist data. That's natural, as I'm not connecting to SQLite or persisting the chat history.
I believe there are the following solutions to this.
Connecting a DB in a way similar to Langchain
By using this method, I believe it would be possible to read and write data with a certain degree of accuracy.
But since it would require calling ChatGPT at least twice, the response time would also at least double, making it highly likely to be unusable at this stage.
However, if ChatGPT's response time improves significantly, there is a possibility of connecting various tools besides databases.
Persisting the Chat
This is a method of completing the application entirely within ChatGPT without even using a DB, by recording all previous interactions as a chat history.
I think this method is truly the future. Since databases and the like are designed for general purposes, the optimal DB structure actually varies depending on the requirements.
So, ultimately, ChatGPT might be able to store the optimal DB structure in the chat and handle data far more efficiently (lol).
Well, for now, it seems almost impossible to save much data, partly due to token limits.
These Issues and the Future
I've been listing nothing but problems so far, but this might only be the case for now.
Over the past few months, LLMs—no, humanity itself—has undergone significant evolution. If everything continues to evolve at this pace, the day may come when we can use LLMs as the application itself.
In fact, many of the issues will be resolved once ChatGPT becomes faster, cheaper, and more powerful.
Usage as of March
It might be somewhat useful as a mock server for casual APIs.
If you have any other innovative ideas for its use, please let me know in the comments!
Conclusion
Naturally, what I've written today isn't practical right now. However, when I thought of this, I felt there's a real possibility that future applications will take this form.
The programming languages you use today might be treated like assembly in the future.
Toward a new era and a new world, let's lead a ChatGPT life!!!
Discussion
あいかわらず、ぶっ飛んでいて良い感じ。
その才能は単純に羨ましい。今後とも期待しています。いいな〜
才能あるものが、きちんと認められる世の中になれば、もっといいな〜
( まあ、既に認められてはいるが、不充分だぜ!! )
高2!
すばらしいセンスですね・・
クローンしたけどts関連に疎くて動かせなかったw
これらのコードを貼り付けるところすら知らない。(おっさんです)
検索とか相性いいかも知れないですね。
app.get("/search", gpt("Googleのような検索エンジンとして検索結果を返してください。", "json"));
ThirdPartyPluginのサードパーティアプリケーション実装開放が予定されてるのでそれが本命でしょうね