AI standard library for EZ — call OpenAI, Anthropic, and Gemini with one line
ez install ai
| Package | Range |
|---|---|
| No dependencies. | |
Call OpenAI, Anthropic, and Gemini from your EZ scripts with one line.
ez install ai
Or manually copy the ai/ folder into C:/ezlib/.
use "ai"
# One-liner (auto-detects provider from API key)
response = ask("What is the capital of France?", "sk-YOUR-OPENAI-KEY")
out response
ask(prompt, apiKey) → StringAuto-detects provider from key prefix:
sk-... → OpenAIAIza... → Geminiask_with_system(prompt, apiKey, systemPrompt) → String
Same as ask() but with a system prompt.
response = openai("Hello!", apiKey)
response = openai_model("Hello!", apiKey, "gpt-4o")
response = openai_full("Hello!", apiKey, "gpt-4o", "You are helpful")
| Task | Parameters | Default Model |
|---|---|---|
openai(prompt, key) | prompt, apiKey | gpt-4o-mini |
openai_model(prompt, key, model) | prompt, apiKey, model | — |
openai_full(prompt, key, model, system) | prompt, apiKey, model, systemPrompt | — |
response = anthropic("Hello!", apiKey)
response = anthropic_model("Hello!", apiKey, "claude-3-haiku-20240307")
response = anthropic_full("Hello!", apiKey, "claude-3-5-sonnet-20241022", "Be concise")
| Task | Parameters | Default Model |
|---|---|---|
anthropic(prompt, key) | prompt, apiKey | claude-3-5-sonnet-20241022 |
anthropic_model(prompt, key, model) | prompt, apiKey, model | — |
anthropic_full(prompt, key, model, system) | prompt, apiKey, model, systemPrompt | — |
response = gemini("Hello!", apiKey)
response = gemini_model("Hello!", apiKey, "gemini-1.5-pro")
response = gemini_full("Hello!", apiKey, "gemini-1.5-flash", "Be brief")
| Task | Parameters | Default Model |
|---|---|---|
gemini(prompt, key) | prompt, apiKey | gemini-1.5-flash |
gemini_model(prompt, key, model) | prompt, apiKey, model | — |
gemini_full(prompt, key, model, system) | prompt, apiKey, model, systemPrompt | — |
use "ai"
# Create a chat
chat = new_chat("openai", apiKey)
# Or with a system prompt
chat = new_chat_with_system("openai", apiKey, "You are a pirate")
# Send messages (history is tracked automatically)
r1 = chat_send(chat, "Hello!")
out r1
r2 = chat_send(chat, "Tell me more")
out r2
# Change model mid-conversation
chat = chat_set_model(chat, "gpt-4o")
| Task | Description |
|---|---|
new_chat(provider, key) | Create chat session ("openai", "anthropic", "gemini") |
new_chat_with_system(provider, key, system) | Chat with system prompt |
chat_send(chat, message) | Send message, get response |
chat_set_model(chat, model) | Change model |
All tasks return nil on failure and print an error message prefixed with [ez-ai]. Wrap calls in try/catch for safety:
try {
response = ask("Hello", apiKey)
when response != nil {
out response
}
} catch e {
out "Something went wrong: " + str(e)
}
MIT
| Version | Size | Downloads | Published |
|---|---|---|---|
1.0.0 |
3.3 KB | 0 | 1 hour ago |
sha256 0170702cfbbdd9acf1aba101c171c5265ca259bc1b0d3b3b3bdfda4b8cba51c1