Build a cross-platform ChatGPT application using Rust + Tauri in two days
RustDesk
Posted on May 8, 2023
On the rare leisurely May Day holiday, with an itchy hand, I spent two days building a cross-platform ChatGPT application using Rust + Tauri.
I noticed that there are four open-source ChatGPT applications on GitHub with relatively high popularity, including a wrapped desktop version, a naive-ui web version, a nextjs version, and a pure HTML version without server dependencies. So I wanted to write a cross-platform version. The reason for choosing Rust as the backend instead of directly calling the client API is to expect greater scalability in the future and embed my own models.
The project is now online and included in awesome tauri. The front-end reuses web-chatgpt, while the backend is rewritten in Rust. It can currently run smoothly on desktops, the web, and mobile phones.
The official version of Tauri does not yet support mobile devices, so we use the latest version 2.0.0-alpha.8, and the documentation is available here: Guides | Tauri Apps. Tauri does not currently support using proxies in browsers, but this can be solved using native Rust.
Prerequisite
Directory structure
- src: the front-end part, modified from web-chatgpt
- server: the web backend, using axum. Here, in order to write stream, a lot of time was wasted mainly because there were few examples online, and also because it was the first time encountering the concept of stream and there were some misunderstandings.
- shared: Rust backend logic part, currently only implements the OpenAI API call. It has to be said that Rust's ecosystem is still slightly inferior to nodejs. The functionality of the OpenAI API SDK is slightly inferior. Here, combined with the async-openai crate and nodejs chatgpt-api, the context function is implemented, and our own model will be added here in the future.
- src-tauri : Tauri implementation, which is relatively simple because the main logic is in shared, which is shared with server.
Run desktop
pnpm tauri dev
Run web
Run iOS
pnpm tauri ios dev
Posted on May 8, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.