Skip to content

Commit e18ec59

Browse files
committed
openai-compatible: add usage example
1 parent 944cc6a commit e18ec59

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Sample script demonstrating AI.generate_text usage with an openai-compatible api
2+
# Run from the elixir-ai-sdk root directory with:
3+
# mix run examples/openai_compatible_example.exs
4+
5+
# Make sure you've set the GOOGLE_API_KEY environment variable
6+
7+
defmodule OpenAICompatibleExample do
8+
def run do
9+
IO.puts("Starting generate_text example...\n")
10+
11+
api_key = System.get_env("GOOGLE_API_KEY")
12+
13+
if is_nil(api_key) do
14+
IO.puts("Error: GOOGLE_API_KEY environment variable not set")
15+
System.halt(1)
16+
end
17+
18+
{:ok, result} =
19+
AI.generate_text(%{
20+
prompt: "is elixir a statically typed programming language?",
21+
model:
22+
AI.openai_compatible(
23+
"gemini-2.5-flash",
24+
base_url: "https://generativelanguage.googleapis.com/v1beta/openai",
25+
api_key: api_key
26+
)
27+
})
28+
29+
IO.puts(result.text)
30+
end
31+
end
32+
33+
# Run the example
34+
OpenAICompatibleExample.run()

0 commit comments

Comments
 (0)