Skip to content

Commit feab58b

Browse files
committed
Add z.ai to /login command
1 parent ee1f896 commit feab58b

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- openrouter
88
- deepseek
99
- azure
10+
- z-ai
1011

1112
## 0.46.0
1213

README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,13 @@ Install the plugin for your editor and ECA server will be downloaded and started
6464

6565
### 2. Set up your first model
6666

67-
To use ECA, you need to configure at least one model with your API key (_tip: Github Copilot offer free models!_). See the [Models documentation](https://eca.dev/models#adding-and-configuring-models) for detailed instructions on:
67+
To use ECA, you need to configure at least one model / provider (_tip: Github Copilot offer free models!_). See the [Models documentation](https://eca.dev/models#adding-and-configuring-models) for detailed instructions:
6868

69-
- Setting up API keys for OpenAI, Anthropic, Copilot or Ollama
70-
- Adding and customizing models
71-
- Configuring custom providers
69+
1. Type in the chat `/login`.
70+
2. Chose your provider
71+
3. Follow the steps to configure the key or auth for your provider.
7272

73-
**Quick start**: Create a `~/.config/eca/config.json` file with your API key:
74-
75-
```javascript
76-
{
77-
"providers": {
78-
"openai": {"key": "your-openai-api-key-here"},
79-
"anthropic": {"key": "your-anthropic-api-key-here"}
80-
}
81-
}
82-
```
83-
84-
**Note**: For other providers or custom models, see the [custom providers documentation](https://eca.dev/models#setting-up-a-custom-provider).
73+
**Note**: For other providers or custom models, see the [custom providers documentation](https://eca.dev/models#custom-providers).
8574

8675
### 3. Start chatting
8776

docs/models.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ Only set this when your provider uses a different path or expects query paramete
243243

244244
=== "Z.ai"
245245

246+
1. Login via the chat command `/login`.
247+
2. Type 'azure' and send it.
248+
3. Specify your API key.
249+
4. Inform at least a model, ex: `GLM-4.5`
250+
5. Done, it should be saved to your global config.
251+
252+
or manually via config:
253+
246254
```javascript
247255
{
248256
"providers": {

src/eca/db.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"deepseek" {}
3636
"github-copilot" {}
3737
"openai" {}
38-
"openrouter" {}}})
38+
"openrouter" {}
39+
"z-ai" {}}})
3940

4041
(defonce db* (atom initial-db))
4142

src/eca/llm_api.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[eca.llm-providers.openai :as llm-providers.openai]
1212
[eca.llm-providers.openai-chat :as llm-providers.openai-chat]
1313
[eca.llm-providers.openrouter]
14+
[eca.llm-providers.z-ai]
1415
[eca.llm-util :as llm-util]
1516
[eca.logger :as logger]))
1617

src/eca/llm_providers/z_ai.clj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(ns eca.llm-providers.z-ai
2+
(:require
3+
[clojure.string :as string]
4+
[eca.config :as config]
5+
[eca.features.login :as f.login]))
6+
7+
(defmethod f.login/login-step ["z-ai" :login/start] [{:keys [db* chat-id provider send-msg!]}]
8+
(swap! db* assoc-in [:chats chat-id :login-provider] provider)
9+
(swap! db* assoc-in [:auth provider] {:step :login/waiting-api-key})
10+
(send-msg! "Paste your API Key"))
11+
12+
(defmethod f.login/login-step ["z-ai" :login/waiting-api-key] [{:keys [input db* provider send-msg!]}]
13+
(swap! db* assoc-in [:auth provider] {:step :login/waiting-models
14+
:api-key input})
15+
(send-msg! "Inform one or more models (separated by `,`):"))
16+
17+
(defmethod f.login/login-step ["z-ai" :login/waiting-models] [{:keys [input db* provider send-msg!] :as ctx}]
18+
(let [api-key (get-in @db* [:auth provider :api-key])]
19+
(config/update-global-config! {:providers {"z-ai" {:api "anthropic"
20+
:url "https://api.z.ai/api/anthropic"
21+
:models (reduce
22+
(fn [models model-str]
23+
(assoc models (string/trim model-str) {}))
24+
{}
25+
(string/split input #","))
26+
:key api-key}}}))
27+
(swap! db* assoc-in [:auth provider] nil)
28+
(send-msg! (format "API key and models saved to %s" (.getCanonicalPath (config/global-config-file))))
29+
(f.login/login-done! ctx))

0 commit comments

Comments
 (0)