MidAI is a cross-platform command-line AI assistant that interacts with Cloudflare's AI API, allowing users to send messages and receive responses in a conversational manner. It runs seamlessly on Windows, macOS, and Linux.
MidAI is a command-line AI assistant that interacts with Cloudflare's AI API, allowing users to send messages and receive responses in a conversational manner. The assistant maintains a short history of interactions and supports model selection from available AI models in your Cloudflare account.
- Authenticate using your Cloudflare API Token and Account ID.
- Retrieve a list of available AI models.
- Select a model dynamically.
- Maintain a short conversation history (up to 6 messages).
- Communicate with Cloudflare AI via API calls.
- Interactive CLI experience.
- Go 1.18 or later installed.
- A Cloudflare account with API access to AI models.
- Network connectivity to Cloudflare API.
git clone https://github.com/your-repo/MidAI.git
cd MidAIgo build -o midai./midaiOn first launch, the application prompts for:
- Cloudflare Account ID
- Cloudflare API Token
This information is stored securely in the user's home directory.
After startup, the application fetches available models from Cloudflare and presents them as a list. Users can select the model they wish to use.
Once configured, the user can send messages and receive responses in a conversational format:
Enter your message for the assistant: What is the capital of France?
Assistant's response:
The capital of France is Paris.main.go- Handles CLI interactions, configuration, and API calls.auth/- Manages API authentication and configuration.model/- Fetches and displays available AI models.
User configuration is stored at:
`~/.aiCFtoken.json` (Linux/macOS) or `%USERPROFILE%\.aiCFtoken.json` (Windows)
This file contains the API token and account ID for persistent authentication.
The application interacts with Cloudflare's AI API using JSON payloads:
{
"messages": [
{ "role": "system", "content": "You are a friendly assistant" },
{ "role": "user", "content": "Hello!" }
]
}{
"result": {
"response": "Hello! How can I help you today?"
}
}If authentication fails, the application prompts for valid credentials. If an API request fails, an error message is displayed, and the user is prompted to retry.
This project is licensed under the MIT License. See LICENSE for details.
Contributions are welcome! Please submit a pull request or open an issue for discussion.
This project consists of the following main components:
main.go: The main entry point handling user input, API communication, and conversation flow.auth/: Manages authentication, API tokens, and configuration persistence.model/: Handles AI model selection, fetching available models, and displaying them in a structured format.
To explore the full source code, check the corresponding files in this repository.