ask-llm

Interact with any LLM service

MIT License

Stars
34
Committers
1

Ask LLM

This is a straightforward, zero-dependency CLI tool to interact with any LLM service.

It is available in several flavors:

  • Python version. Compatible with CPython or PyPy, v3.10 or higher.
  • JavaScript version. Compatible with Node.js (>= v18) or Bun (>= v1.0).
  • Clojure version. Compatible with Babashka (>= 1.3).
  • Swift version. Compatible with Swift, v5.10 or higher.
  • Go version. Compatible with Go, v1.19 or higher.

Ask LLM is compatible with either a cloud-based (managed) LLM service (e.g. OpenAI GPT model, Groq, OpenRouter, etc) or with a locally hosted LLM server (e.g. llama.cpp, LM Studio, Ollama, etc). Please continue reading for detailed instructions.

Interact with the LLM with:

./ask-llm.py         # for Python user
./ask-llm.js         # for Node.js user
./ask-llm.clj        # for Clojure user
./ask-llm.swift      # for Swift user
go run ask-llm.go    # for Go user

or pipe the question directly to get an immediate answer:

echo "Why is the sky blue?" | ./ask-llm.py

or request the LLM to perform a certain task:

echo "Translate into German: thank you" | ./ask-llm.py

Using Local LLM Servers

Supported local LLM servers include llama.cpp, Jan, Ollama, LocalAI, LM Studio, and Msty.

To utilize llama.cpp locally with its inference engine, load a quantized model like Llama-3.2 3B or Phi-3.5 Mini. Then set the LLM_API_BASE_URL environment variable:

/path/to/llama-server -m Llama-3.2-3B-Instruct-Q4_K_M.gguf
export LLM_API_BASE_URL=http://127.0.0.1:8080/v1

To use Jan with its local API server, refer to its documentation. Load a model like Llama-3.2 3B or Phi-3.5 Mini, and set the following environment variables:

export LLM_API_BASE_URL=http://127.0.0.1:1337/v1
export LLM_CHAT_MODEL='llama3-8b-instruct'

To use Ollama locally, load a model and configure the environment variable LLM_API_BASE_URL:

ollama pull llama3.2
export LLM_API_BASE_URL=http://127.0.0.1:11434/v1
export LLM_CHAT_MODEL='llama3.2'

For LocalAI, initiate its container and adjust the environment variable LLM_API_BASE_URL:

docker run -ti -p 8080:8080 localai/localai llama-3.2-3b-instruct:q4_k_m
export LLM_API_BASE_URL=http://localhost:3928/v1

For LM Studio, pick a model (e.g., Llama-3.2 3B). Next, go to the Developer tab, select the model to load, and click the Start Server button. Then, set the LLM_API_BASE_URL environment variable, noting that the server by default runs on port 1234:

export LLM_API_BASE_URL=http://127.0.0.1:1234/v1

For Msty, choose a model (e.g., Llama-3.2 3B) and ensure the local AI is running. Go to the Settings menu, under Local AI, and note the Service Endpoint (which defaults to port 10002). Then set the LLM_API_BASE_URL environment variable accordingly:

export LLM_API_BASE_URL=http://127.0.0.1:10002/v1

Using Managed LLM Services

Supported LLM services include AI21, Deep Infra, DeepSeek, Fireworks, Groq, Hyperbolic, Lepton, Mistral, Nebius, Novita, Octo, OpenAI, OpenRouter, and Together.

For configuration specifics, refer to the relevant section. The quality of answers can vary based on the model's performance.

export LLM_API_BASE_URL=https://api.ai21.com/studio/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL=jamba-1.5-mini
export LLM_API_BASE_URL=https://api.deepinfra.com/v1/openai
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="meta-llama/Meta-Llama-3.1-8B-Instruct"
export LLM_API_BASE_URL=https://api.deepseek.com/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="deepseek-chat"
export LLM_API_BASE_URL=https://api.fireworks.ai/inference/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="accounts/fireworks/models/llama-v3p1-8b-instruct"
export LLM_API_BASE_URL=https://api.groq.com/openai/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="llama-3.1-8b-instant"
export LLM_API_BASE_URL=https://api.hyperbolic.xyz/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="meta-llama/Meta-Llama-3.1-8B-Instruct"
export LLM_API_BASE_URL=https://llama3-1-8b.lepton.run/api/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="llama3-1-8b"
export LLM_API_BASE_URL=https://api.mistral.ai/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="open-mistral-7b"
export LLM_API_BASE_URL=https://api.studio.nebius.ai/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="meta-llama/Meta-Llama-3.1-8B-Instruct"
export LLM_API_BASE_URL=https://api.novita.ai/v3/openai
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="meta-llama/llama-3.1-8b-instruct"
export LLM_API_BASE_URL=https://text.octoai.run/v1/
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="meta-llama-3.1-8b-instruct"
export LLM_API_BASE_URL=https://api.openai.com/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="gpt-4o-mini"
export LLM_API_BASE_URL=https://openrouter.ai/api/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="meta-llama/llama-3.1-8b-instruct"
export LLM_API_BASE_URL=https://api.together.xyz/v1
export LLM_API_KEY="yourownapikey"
export LLM_CHAT_MODEL="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"
Badges
Extracted from project README
asciicast Test on AI21 Test on DeepInfra Test on DeepSeek Test on Fireworks Test on Groq Test on Hyperbolic Test on Lepton Test on Mistral Test on Nebius Test on Novita Test on Octo Test on OpenAI Test on OpenRouter Test on Together
Related Projects