Skip to content

Instantly share code, notes, and snippets.

@chenasraf
Last active August 23, 2024 20:27
Show Gist options
  • Save chenasraf/12c3bc607a0d46d99e77c6538d20a424 to your computer and use it in GitHub Desktop.
Save chenasraf/12c3bc607a0d46d99e77c6538d20a424 to your computer and use it in GitHub Desktop.
Ollama CLI prompt
#!/usr/bin/env bash
ollama_prompt() {
prompt="$@"
endpoint="http://localhost:11434"
curl $endpoint/api/generate -XPOST \
--no-buffer \
-s \
-H 'Content-Type: application/json' \
-d '{"prompt":"'$prompt'","model":"llama3.1"}' | \
while IFS= read -r line; do
line="${line//$'\\n'/\\\\n}"
response="$(printf '%s\n' "$line" | jq -r '.response')"
echo -n "$response"
done
echo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment