Skip to content

Commit 0493cb8

Browse files
authored
cmd/starlet: remove Gemini API support, fully replace by llm (#350)
1 parent f48fe31 commit 0493cb8

24 files changed

Lines changed: 2 additions & 1010 deletions

cmd/starlet/doc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Starlet is a Telegram bot runner powered by Starlark.
88
It fetches bot logic written in Starlark from a specified GitHub Gist,
99
executes it within a Starlark interpreter, and handles incoming Telegram updates
1010
via webhooks. Starlet provides a sandboxed environment with pre-defined modules
11-
for interacting with Telegram, Gemini AI, key-value caching, and more.
11+
for interacting with Telegram, LLM, key-value caching, and more.
1212
1313
When a Telegram update arrives, Starlet parses it, converts the JSON payload
1414
into a Starlark dictionary, and invokes the handle function defined in the
@@ -71,7 +71,6 @@ Required:
7171
Optional:
7272
7373
- DATABASE_PATH: Path to a SQLite database file. If not provided, an in-memory store is used.
74-
- GEMINI_KEY: API key for Google Gemini (required to use the gemini module).
7574
- LLM_API_KEY: API key for an OpenAI-compatible gateway (required to use llm).
7675
- LLM_API_URL: API root URL for an OpenAI-compatible gateway, for example
7776
https://api.openai.com/v1 (required to use llm).

cmd/starlet/internal/bot/bot.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"go.astrophena.name/base/request"
2323
"go.astrophena.name/base/version"
2424
"go.astrophena.name/base/web"
25-
"go.astrophena.name/tools/internal/api/gemini"
2625
"go.astrophena.name/tools/internal/api/llm"
2726
"go.astrophena.name/tools/internal/starlark/go2star"
2827
"go.astrophena.name/tools/internal/starlark/interpreter"
@@ -66,7 +65,6 @@ type Bot struct {
6665
tgBotUsername string
6766

6867
httpc *http.Client
69-
geminic *gemini.Client
7068
llmc *llm.Client
7169
llmUsagePath string
7270
kvCache *starlarkstruct.Module
@@ -97,8 +95,6 @@ type Opts struct {
9795
BotUsername string
9896
// HTTPClient is the HTTP client to use for making requests.
9997
HTTPClient *http.Client
100-
// GeminiClient is the client for interacting with the Google Gemini API.
101-
GeminiClient *gemini.Client
10298
// LLMClient is the client for interacting with an OpenAI-compatible LLM API.
10399
LLMClient *llm.Client
104100
// LLMUsagePath is path to persistent usage stats JSON for llm module.
@@ -120,7 +116,6 @@ func New(opts Opts) *Bot {
120116
tgBotID: opts.BotID,
121117
tgBotUsername: opts.BotUsername,
122118
httpc: opts.HTTPClient,
123-
geminic: opts.GeminiClient,
124119
llmc: opts.LLMClient,
125120
llmUsagePath: opts.LLMUsagePath,
126121
kvCache: opts.KVCache,

cmd/starlet/internal/bot/doc.md

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,49 +46,6 @@ A module for accessing files provided to the bot.
4646

4747
Reads the content of a file.
4848

49-
## `gemini`
50-
51-
This module provides a single function, generate_content, which uses the
52-
Gemini API to generate text, optionally with an image as context.
53-
54-
It accepts the following keyword arguments:
55-
56-
- model (str): The name of the model to use for generation (e.g., "gemini-1.5-flash").
57-
- contents (list of (str, str) tuples): A list of (role, text) tuples representing
58-
the conversation history. Valid roles are typically "user" and "model".
59-
- image (bytes, optional): The raw bytes of an image to include. The image is
60-
inserted as a new part just before the last part of the 'contents'.
61-
This is useful for multimodal prompts (e.g., asking a question about an image).
62-
- system_instructions (str, optional): System instructions to guide Gemini's response.
63-
- unsafe (bool, optional): If set to true, disables all safety settings for the
64-
content generation, allowing potentially harmful content. Use with caution.
65-
66-
For example, for a text-only prompt:
67-
68-
responses = gemini.generate_content(
69-
model="gemini-1.5-flash",
70-
contents=[
71-
("user", "Once upon a time,"),
72-
("model", "there was a brave knight."),
73-
("user", "What happened next?")
74-
],
75-
system_instructions="You are a creative story writer. Write a short story based on the provided prompt."
76-
)
77-
78-
To ask a question about an image:
79-
80-
image_data = ... # read image file content as bytes
81-
responses = gemini.generate_content(
82-
model="gemini-1.5-flash",
83-
contents=[
84-
("user", "Describe this image in detail.")
85-
],
86-
image=image_data
87-
)
88-
89-
The responses variable will contain a list of generated responses, where each response
90-
is a list of strings representing the parts of the generated content.
91-
9249
## `llm`
9350

9451
LLM provider.

cmd/starlet/internal/bot/env.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212

1313
"go.astrophena.name/base/version"
14-
"go.astrophena.name/tools/internal/starlark/gemini"
1514
"go.astrophena.name/tools/internal/starlark/go2star"
1615
"go.astrophena.name/tools/internal/starlark/kvcache"
1716
"go.astrophena.name/tools/internal/starlark/llm"
@@ -163,11 +162,6 @@ func (b *Bot) environment() Environment {
163162
},
164163
},
165164
},
166-
{
167-
Name: "gemini",
168-
Doc: gemini.Documentation(),
169-
Value: gemini.Module(b.geminic),
170-
},
171165
{
172166
Name: "llm",
173167
Doc: llm.Documentation(),

cmd/starlet/main.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"go.astrophena.name/base/web"
2323
"go.astrophena.name/base/web/service"
2424
"go.astrophena.name/tools/cmd/starlet/internal/bot"
25-
"go.astrophena.name/tools/internal/api/gemini"
2625
"go.astrophena.name/tools/internal/api/gist"
2726
"go.astrophena.name/tools/internal/api/llm"
2827
"go.astrophena.name/tools/internal/starlark/kvcache"
@@ -48,7 +47,6 @@ type engine struct {
4847

4948
// configuration, read-only after initialization
5049
databasePath string
51-
geminiKey string
5250
llmAPIKey string
5351
llmAPIURL string
5452
llmUsagePath string
@@ -93,7 +91,6 @@ func (e *engine) doInit(ctx context.Context) error {
9391

9492
// Load configuration from environment variables.
9593
e.databasePath = cmp.Or(e.databasePath, env.Getenv("DATABASE_PATH"))
96-
e.geminiKey = cmp.Or(e.geminiKey, env.Getenv("GEMINI_KEY"))
9794
e.llmAPIKey = cmp.Or(e.llmAPIKey, env.Getenv("LLM_API_KEY"))
9895
e.llmAPIURL = cmp.Or(e.llmAPIURL, env.Getenv("LLM_API_URL"))
9996
e.llmUsagePath = cmp.Or(e.llmUsagePath, env.Getenv("LLM_USAGE_PATH"))
@@ -109,7 +106,7 @@ func (e *engine) doInit(ctx context.Context) error {
109106

110107
if e.httpc == nil {
111108
e.httpc = &http.Client{
112-
// Increase timeout to properly handle Gemini API response times.
109+
// Increase timeout to properly handle LLM API response times.
113110
Timeout: 60 * time.Second,
114111
}
115112
}
@@ -120,7 +117,6 @@ func (e *engine) doInit(ctx context.Context) error {
120117
e.gistID,
121118
e.tgSecret,
122119
e.tgToken,
123-
e.geminiKey,
124120
e.llmAPIKey,
125121
} {
126122
if val != "" {
@@ -163,14 +159,6 @@ func (e *engine) doInit(ctx context.Context) error {
163159
LLMUsagePath: e.llmUsagePath,
164160
}
165161

166-
if e.geminiKey != "" {
167-
opts.GeminiClient = &gemini.Client{
168-
APIKey: e.geminiKey,
169-
HTTPClient: e.httpc,
170-
Scrubber: e.scrubber,
171-
}
172-
}
173-
174162
if e.llmAPIKey != "" && e.llmAPIURL != "" {
175163
opts.LLMClient = &llm.Client{
176164
APIKey: e.llmAPIKey,

internal/api/gemini/gemini.go

Lines changed: 0 additions & 140 deletions
This file was deleted.

internal/api/gemini/gemini_test.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)