Skip to content

Commit 917f9f9

Browse files
committed
fix: Lyzr completions endpoint URL, remove x-api-key header (uses Bearer auth), add SDK example
1 parent 8f5cb7f commit 917f9f9

File tree

4 files changed

+93
-11
lines changed

4 files changed

+93
-11
lines changed

examples/lyzr-sdk.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Example: Using GitClaw SDK with Lyzr AI Studio
3+
*
4+
* Prerequisites:
5+
* 1. Set your Lyzr API key: export LYZR_API_KEY="sk-default-..."
6+
* 2. Set a dummy OpenAI key (needed by pi-ai): export OPENAI_API_KEY="dummy"
7+
* 3. Have an agent directory with agent.yaml: ~/assistant/
8+
*
9+
* Run:
10+
* npx tsx examples/lyzr-sdk.ts
11+
*/
12+
13+
import { query } from "../dist/exports.js";
14+
15+
const LYZR_API_KEY = process.env.LYZR_API_KEY;
16+
if (!LYZR_API_KEY) {
17+
console.error("Error: Set LYZR_API_KEY environment variable");
18+
process.exit(1);
19+
}
20+
21+
// Ensure pi-ai can find an API key (it checks OPENAI_API_KEY for openai-completions API)
22+
if (!process.env.OPENAI_API_KEY) {
23+
process.env.OPENAI_API_KEY = LYZR_API_KEY;
24+
}
25+
26+
// Your Lyzr agent ID (created via studio.lyzr.ai or the install.sh setup)
27+
const LYZR_AGENT_ID = process.env.GITCLAW_LYZR_AGENT_ID || "your-agent-id-here";
28+
29+
async function main() {
30+
console.log("Starting GitClaw with Lyzr backend...\n");
31+
32+
const result = query({
33+
prompt: "Hello! What can you help me with today?",
34+
dir: process.env.HOME + "/assistant",
35+
36+
// Model format: lyzr:<agent-id>@<base-url>
37+
// The OpenAI SDK appends /chat/completions to the base URL
38+
model: `lyzr:${LYZR_AGENT_ID}@https://agent-prod.studio.lyzr.ai/v4`,
39+
40+
// Optional: disable filesystem tools for a pure chat agent
41+
// replaceBuiltinTools: true,
42+
43+
// Optional: limit turns and temperature
44+
constraints: {
45+
temperature: 0.7,
46+
maxTokens: 2000,
47+
},
48+
maxTurns: 5,
49+
});
50+
51+
// Stream messages as they arrive
52+
for await (const msg of result) {
53+
switch (msg.type) {
54+
case "system":
55+
console.log(`[${msg.subtype}] ${msg.content}`);
56+
break;
57+
58+
case "delta":
59+
// Real-time text streaming
60+
process.stdout.write(msg.content);
61+
break;
62+
63+
case "assistant":
64+
// Final complete message
65+
console.log(`\n\nAgent: ${msg.content}`);
66+
if (msg.usage) {
67+
console.log(` Tokens: ${msg.usage.inputTokens} in / ${msg.usage.outputTokens} out`);
68+
}
69+
break;
70+
71+
case "tool_use":
72+
console.log(`\n[tool] ${msg.toolName}(${JSON.stringify(msg.args).slice(0, 100)})`);
73+
break;
74+
75+
case "tool_result":
76+
console.log(`[result] ${msg.toolName}: ${msg.content.slice(0, 200)}`);
77+
break;
78+
}
79+
}
80+
81+
// Print cost summary
82+
const costs = result.costs();
83+
console.log("\n--- Session Summary ---");
84+
console.log(`Total requests: ${costs.totalRequests}`);
85+
console.log(`Total tokens: ${costs.totalInputTokens} in / ${costs.totalOutputTokens} out`);
86+
console.log(`Total cost: $${costs.totalCostUsd.toFixed(4)}`);
87+
}
88+
89+
main().catch(console.error);

install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ if [ -d "$PROJECT_DIR" ] && [ -f "$PROJECT_DIR/agent.yaml" ]; then
187187

188188
# Set model — use Lyzr if configured, otherwise let loadAgent() read from agent.yaml
189189
if [ -n "${GITCLAW_LYZR_AGENT_ID:-}" ]; then
190-
MODEL="lyzr:${GITCLAW_LYZR_AGENT_ID}@https://agent-prod.studio.lyzr.ai/v4/chat"
190+
MODEL="lyzr:${GITCLAW_LYZR_AGENT_ID}@https://agent-prod.studio.lyzr.ai/v4"
191191
else
192192
MODEL=""
193193
fi
@@ -314,8 +314,8 @@ if [ "$SETUP_MODE" = "1" ]; then
314314
fi
315315

316316
# Set model to use Lyzr completions endpoint with agent ID as model
317-
MODEL="lyzr:${GITCLAW_LYZR_AGENT_ID}@https://agent-prod.studio.lyzr.ai/v4/chat"
318-
export GITCLAW_MODEL_BASE_URL="https://agent-prod.studio.lyzr.ai/v4/chat"
317+
MODEL="lyzr:${GITCLAW_LYZR_AGENT_ID}@https://agent-prod.studio.lyzr.ai/v4"
318+
export GITCLAW_MODEL_BASE_URL="https://agent-prod.studio.lyzr.ai/v4"
319319
ADAPTER_LABEL="${VOICE_ENABLED:+OpenAI Realtime}${VOICE_ENABLED:-Text Only}"
320320
if [ "$VOICE_ENABLED" = true ]; then
321321
ADAPTER_LABEL="OpenAI Realtime"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitclaw",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "A universal git-native multimodal always learning AI Agent (TinyHuman)",
55
"author": "shreyaskapale",
66
"license": "MIT",

src/loader.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ function parseModelString(modelStr: string): { provider: string; modelId: string
8383
* Used when model string contains @baseUrl or GITCLAW_MODEL_BASE_URL is set.
8484
*/
8585
function createCustomModel(provider: string, modelId: string, baseUrl: string): Model<any> {
86-
// Build custom headers for specific providers
87-
const headers: Record<string, string> = {};
88-
if (provider === "lyzr" && process.env.LYZR_API_KEY) {
89-
headers["x-api-key"] = process.env.LYZR_API_KEY;
90-
}
91-
9286
return {
9387
id: modelId,
9488
name: `${modelId} (${provider})`,
@@ -100,7 +94,6 @@ function createCustomModel(provider: string, modelId: string, baseUrl: string):
10094
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
10195
contextWindow: 128000,
10296
maxTokens: 32000,
103-
...(Object.keys(headers).length > 0 ? { headers } : {}),
10497
};
10598
}
10699

0 commit comments

Comments
 (0)