Skip to content

Commit 05de041

Browse files
committed
feat: add docs for gemini
1 parent fbc2c94 commit 05de041

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

docs/docs/ai/llm.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ It has the following fields:
2121
* `address` (optional): The address of the LLM API.
2222

2323

24-
## LLM API integrations
24+
## LLM API Integrations
2525

2626
CocoIndex integrates with various LLM APIs for these functions.
2727

@@ -77,3 +77,24 @@ cocoindex.LlmSpec(
7777
</TabItem>
7878
</Tabs>
7979

80+
### Google Gemini
81+
82+
To use the Gemini LLM API, you need to set the environment variable `GEMINI_API_KEY`.
83+
You can generate the API key from [Google AI Studio](https://aistudio.google.com/apikey).
84+
85+
A spec for Gemini looks like this:
86+
87+
<Tabs>
88+
<TabItem value="python" label="Python" default>
89+
90+
```python
91+
cocoindex.LlmSpec(
92+
api_type=cocoindex.LlmApiType.GEMINI,
93+
model="gemini-2.0-flash",
94+
)
95+
```
96+
97+
</TabItem>
98+
</Tabs>
99+
100+
You can find the full list of models supported by Gemini [here](https://ai.google.dev/gemini-api/docs/models).

src/llm/gemini.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::llm::{LlmGenerationClient, LlmSpec, LlmGenerateRequest, LlmGenerateRe
33
use anyhow::{Result, anyhow};
44
use serde_json;
55
use reqwest::Client as HttpClient;
6-
use serde_json::{json, Value};
6+
use serde_json::Value;
77

88
pub struct Client {
99
model: String,
@@ -45,7 +45,7 @@ impl LlmGenerationClient for Client {
4545
request: LlmGenerateRequest<'req>,
4646
) -> Result<LlmGenerateResponse> {
4747
// Compose the prompt/messages
48-
let mut contents = vec![serde_json::json!({
48+
let contents = vec![serde_json::json!({
4949
"role": "user",
5050
"parts": [{ "text": request.user_prompt }]
5151
})];
@@ -90,10 +90,6 @@ impl LlmGenerationClient for Client {
9090

9191
let resp_json: Value = resp.json().await.map_err(|e| anyhow!("Invalid JSON: {e}"))?;
9292

93-
// Debug log Gemini response
94-
println!("Gemini request payload: {:#}", payload);
95-
println!("Gemini response JSON: {:#}", resp_json);
96-
9793
if let Some(error) = resp_json.get("error") {
9894
return Err(anyhow!("Gemini API error: {:?}", error));
9995
}

0 commit comments

Comments
 (0)