[GH-ISSUE #353] Non-interactive CLI to prompt a model #25916

Closed
opened 2026-04-22 01:46:07 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @bhazzard on GitHub (Aug 15, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/353

Having a non-interactive CLI command would allow using ollama programmatically in other bash scripts without the need for a long running process to keep the server up for the api.

Something like...

ollama prompt "<prompt>" -m <model>

OR

ollama use <model>
ollama prompt
Originally created by @bhazzard on GitHub (Aug 15, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/353 Having a non-interactive CLI command would allow using ollama programmatically in other bash scripts without the need for a long running process to keep the server up for the api. Something like... `ollama prompt "<prompt>" -m <model>` OR ``` ollama use <model> ollama prompt ```
Author
Owner

@mchiang0610 commented on GitHub (Aug 15, 2023):

@bhazzard Hey! Thanks for sending this. You can currently submit the prompt like this:

mchiang@playground ~ % ollama run llama2 "tell me who's obama" 
 Barack Obama is the 44th President of the United States, serving two terms from 2009 to 2017. Einzeln die first African American to hold the office. Born in Hawaii and raised in Chicago, he attended Columbia University and Harvard Law School before moving to Springfield, Illinois to work as a community organizer.

Obama served in the Illinois State Senate from 1997 to 2004, and then in the United States Senate from 2005 to 2008. In 2008, he won the Democratic presidential nomination and defeated Republican candidate John McCain in the general election to become the first African American President of the United States.

During his presidency, Obama signed several notable pieces of legislation, including the Affordable Care Act (ACA), which expanded healthcare coverage to millions of Americans, and the Dodd-Frank Wall Street Reform and Consumer Protection Act, which aimed to regulate the financial industry and prevent future economic crises. He also ended the war in Iraq, increased support for renewable energy, and implemented a number of diplomatic initiatives, including the Joint Comprehensive Plan of Action (JCPOA) with Iran.

Obama was re-elected in 2012, defeating Republican candidate Mitt Romney, and continued to work on issues such as climate change, immigration reform, and civil rights. He also made significant progress in the area of nuclear non-proliferation, including the signing of the New Strategic Arms Reduction Treaty (New START) with Russia.

After leaving office, Obama established the Obama Foundation, which aims to promote civic engagement and leadership development around the world. He has also written several books, including his memoirs, "Dreams from My Father" and "The Audacity of Hope."

<!-- gh-comment-id:1679712695 --> @mchiang0610 commented on GitHub (Aug 15, 2023): @bhazzard Hey! Thanks for sending this. You can currently submit the prompt like this: ``` mchiang@playground ~ % ollama run llama2 "tell me who's obama" Barack Obama is the 44th President of the United States, serving two terms from 2009 to 2017. Einzeln die first African American to hold the office. Born in Hawaii and raised in Chicago, he attended Columbia University and Harvard Law School before moving to Springfield, Illinois to work as a community organizer. Obama served in the Illinois State Senate from 1997 to 2004, and then in the United States Senate from 2005 to 2008. In 2008, he won the Democratic presidential nomination and defeated Republican candidate John McCain in the general election to become the first African American President of the United States. During his presidency, Obama signed several notable pieces of legislation, including the Affordable Care Act (ACA), which expanded healthcare coverage to millions of Americans, and the Dodd-Frank Wall Street Reform and Consumer Protection Act, which aimed to regulate the financial industry and prevent future economic crises. He also ended the war in Iraq, increased support for renewable energy, and implemented a number of diplomatic initiatives, including the Joint Comprehensive Plan of Action (JCPOA) with Iran. Obama was re-elected in 2012, defeating Republican candidate Mitt Romney, and continued to work on issues such as climate change, immigration reform, and civil rights. He also made significant progress in the area of nuclear non-proliferation, including the signing of the New Strategic Arms Reduction Treaty (New START) with Russia. After leaving office, Obama established the Obama Foundation, which aims to promote civic engagement and leadership development around the world. He has also written several books, including his memoirs, "Dreams from My Father" and "The Audacity of Hope." ```
Author
Owner

@mchiang0610 commented on GitHub (Aug 22, 2023):

closing this for now. Thank you so much for submitting this. Happy to revisit this as well. Feel free to comment.

<!-- gh-comment-id:1687262633 --> @mchiang0610 commented on GitHub (Aug 22, 2023): closing this for now. Thank you so much for submitting this. Happy to revisit this as well. Feel free to comment.
Author
Owner

@bhazzard commented on GitHub (Aug 28, 2023):

Thanks for showing me how to do this. Super cool.

That said, this still has an "interactive" element in that it prints the "spinner" rather than waiting and eventually giving the response to standard out. This means:

  • The response can't be piped to other commands
  • The response can't be used in a shell script
<!-- gh-comment-id:1696033312 --> @bhazzard commented on GitHub (Aug 28, 2023): Thanks for showing me how to do this. Super cool. That said, this still has an "interactive" element in that it prints the "spinner" rather than waiting and eventually giving the response to standard out. This means: - The response can't be piped to other commands - The response can't be used in a shell script
Author
Owner

@rtrad89 commented on GitHub (Nov 7, 2024):

The spinning / waiting element is there, but at least I could redirect the response to a file or pipe it to wc -w for instance:

% ollama run llama3.1:8b "What is your knowledge cutoff date?" > test.txt
% cat test.txt
My knowledge cutoff date is December 2023, but I have access to more recent information via internet search. However, my responses are still limited to the understanding and context provided by my training data, which may not always reflect the most up-to-date developments or nuances on a particular topic. If you need the very latest news or details, I would be happy to try and find them for you through a web search!
% ollama run llama3.1:8b "What is your knowledge cutoff date?" | wc -w
      62

I can append [&&|;] ollama stop <model> so that the model is stopped after the response.

<!-- gh-comment-id:2462100411 --> @rtrad89 commented on GitHub (Nov 7, 2024): The spinning / waiting element is there, but at least I could redirect the response to a file or pipe it to `wc -w` for instance: ```bash % ollama run llama3.1:8b "What is your knowledge cutoff date?" > test.txt % cat test.txt My knowledge cutoff date is December 2023, but I have access to more recent information via internet search. However, my responses are still limited to the understanding and context provided by my training data, which may not always reflect the most up-to-date developments or nuances on a particular topic. If you need the very latest news or details, I would be happy to try and find them for you through a web search! % ollama run llama3.1:8b "What is your knowledge cutoff date?" | wc -w 62 ``` I can append `[&&|;] ollama stop <model>` so that the model is stopped after the response.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#25916