File tree Expand file tree Collapse file tree 1 file changed +18
-12
lines changed
src/content/docs/ai-gateway/providers Expand file tree Collapse file tree 1 file changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -50,26 +50,32 @@ curl "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_name}/google-ai
5050 }'
5151```
5252
53- ### Use ` @google/generative-ai ` with JavaScript
53+ ### Use ` @google/genai ` with JavaScript
5454
55- If you are using the ` @google/generative-ai ` package, you can set your endpoint like this:
55+ If you are using the ` @google/genai ` package, you can set your endpoint like this:
5656
5757``` js title="JavaScript example"
58- import { GoogleGenerativeAI } from " @google/generative-ai " ;
58+ import { GoogleGenAI } from " @google/genai " ;
5959
6060const api_token = env .GOOGLE_AI_STUDIO_TOKEN ;
6161const account_id = " " ;
6262const gateway_name = " " ;
6363
64- const genAI = new GoogleGenerativeAI (api_token);
65- const model = genAI .getGenerativeModel (
66- { model: " gemini-1.5-flash" },
67- {
68- baseUrl: ` https://gateway.ai.cloudflare.com/v1/${ account_id} /${ gateway_name} /google-ai-studio` ,
69- },
70- );
71-
72- await model .generateContent ([" What is Cloudflare?" ]);
64+ const genAI = new GoogleGenAI ({
65+ apiKey: api_token,
66+ httpOptions: {
67+ baseUrl: ` https://gateway.ai.cloudflare.com/v1/${ account_id} /${ gateway_name} /google-ai-studio` ,
68+ },
69+ });
70+
71+ const model = " gemini-1.5-flash" ;
72+ const prompt = " What is Cloudflare?" ;
73+ const response = await genAI .models .generateContent ({
74+ model,
75+ contents: prompt,
76+ });
77+
78+ console .log (response .text );
7379```
7480
7581<Render
You can’t perform that action at this time.
0 commit comments