[GH-ISSUE #8429] How do we EXPORT ollama responses to file TXT/JSON ? #67473

Closed
opened 2026-05-04 10:29:09 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @GAC-Machine on GitHub (Jan 14, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8429

OS : Windows 11 Pro
Model: ollama 3.2

Want to create logregistry file (trivially a txt/JSON file).

I want a JSON structured file like:

{
 "Model"  : "name_of-model",
 "running environment" : "Win-MacOS-Linux", 
 "conversation": [
    "prompt1" : "my_input_text"
    "response1" : "ollama_output_text"
   },
   ... //so on
 ]
}

Alternatively it would be adequate a txt file like:

Model name_of_model
Running environment Win_MacOS_Linux
ConversationID Prompt-Input Response-Output
00000001 [my_input_text] [ollama_output_text]

Referencing this issue on Github https://github.com/ollama/ollama/issues/1710 dated #Dec, 25, 2023.

The command provided is for Unix-Like system (that is Linux, MacOS).
ollama run llama3.2 "prompt" >> response.txt

What about Windows ?
I tried it, but it doesn't work.

Originally created by @GAC-Machine on GitHub (Jan 14, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8429 OS : Windows 11 Pro Model: ollama 3.2 Want to create logregistry file (trivially a txt/JSON file). I want a JSON structured file like: ``` { "Model" : "name_of-model", "running environment" : "Win-MacOS-Linux", "conversation": [ "prompt1" : "my_input_text" "response1" : "ollama_output_text" }, ... //so on ] } ``` Alternatively it would be adequate a txt file like: ``` Model name_of_model Running environment Win_MacOS_Linux ConversationID Prompt-Input Response-Output 00000001 [my_input_text] [ollama_output_text] ``` Referencing this issue on Github https://github.com/ollama/ollama/issues/1710 dated #Dec, 25, 2023. The command provided is for Unix-Like system (that is Linux, MacOS). `ollama run llama3.2 "prompt" >> response.txt` What about Windows ? I tried it, but it doesn't work.
GiteaMirror added the feature requestneeds more info labels 2026-05-04 10:29:09 -05:00
Author
Owner

@rick-github commented on GitHub (Jan 15, 2025):

What doesn't work?

C:>\Users\bill>ollama run llama3.2 hello >> response.txt

C:>\Users\bill>ollama run llama3.2 goodbye >> response.txt

C:>\Users\bill>type response.txt
Hello! It's nice to meet you. Is there something I can help you with or would you like to chat?

Goodbye! It was nice chatting with you, even if it was just for a short time. If you even want to come back and chat again, I'll be here. Have a great day!

However, if you want to keep metadata, you could have a look at the integrations to find a client that offers more than the basic ollama CLI, or you could write a simple python client:

#!/usr/bin/env python3

import ollama
import readline
import argparse
import json
import platform

parser = argparse.ArgumentParser()
parser.add_argument("model", nargs="?", default="llama3.2")
args = parser.parse_args()

messages = []

while True:
  try:
    prompt = input(">>> ")
    if prompt == "/bye":
      break
  except:
    print()
    break

  messages.append({"role":"user", "content":prompt})
  response =  ollama.chat(
    args.model,
    messages=messages,
  )

  messages.append(dict(response.message))

  print(response.message.content)

with open("response.log", "a") as f:
  log = {
    "model": args.model,
    "environment": platform.platform(),
    "conversation": messages,
  }
  f.write(json.dumps(log, indent=4))
$ ./8429.py llama3.2
>>> hello
Hello! How can I assist you today?
>>> goodbye
It was nice chatting with you, even if it was brief. Goodbye for now!
>>> /bye
$ cat response.log 
{
    "model": "llama3.2",
    "environment": "Linux-6.2.0-39-generic-x86_64-with-glibc2.35",
    "conversation": [
        {
            "role": "user",
            "content": "hello"
        },
        {
            "role": "assistant",
            "content": "Hello! How can I assist you today?",
            "images": null,
            "tool_calls": null
        },
        {
            "role": "user",
            "content": "goodbye"
        },
        {
            "role": "assistant",
            "content": "It was nice chatting with you, even if it was brief. Goodbye for now!",
            "images": null,
            "tool_calls": null
        }
    ]
}
<!-- gh-comment-id:2591444637 --> @rick-github commented on GitHub (Jan 15, 2025): What doesn't work? ```console C:>\Users\bill>ollama run llama3.2 hello >> response.txt C:>\Users\bill>ollama run llama3.2 goodbye >> response.txt C:>\Users\bill>type response.txt Hello! It's nice to meet you. Is there something I can help you with or would you like to chat? Goodbye! It was nice chatting with you, even if it was just for a short time. If you even want to come back and chat again, I'll be here. Have a great day! ``` However, if you want to keep metadata, you could have a look at the [integrations](https://github.com/ollama/ollama?tab=readme-ov-file#community-integrations) to find a client that offers more than the basic ollama CLI, or you could write a simple python client: ```python #!/usr/bin/env python3 import ollama import readline import argparse import json import platform parser = argparse.ArgumentParser() parser.add_argument("model", nargs="?", default="llama3.2") args = parser.parse_args() messages = [] while True: try: prompt = input(">>> ") if prompt == "/bye": break except: print() break messages.append({"role":"user", "content":prompt}) response = ollama.chat( args.model, messages=messages, ) messages.append(dict(response.message)) print(response.message.content) with open("response.log", "a") as f: log = { "model": args.model, "environment": platform.platform(), "conversation": messages, } f.write(json.dumps(log, indent=4)) ``` ```console $ ./8429.py llama3.2 >>> hello Hello! How can I assist you today? >>> goodbye It was nice chatting with you, even if it was brief. Goodbye for now! >>> /bye $ cat response.log { "model": "llama3.2", "environment": "Linux-6.2.0-39-generic-x86_64-with-glibc2.35", "conversation": [ { "role": "user", "content": "hello" }, { "role": "assistant", "content": "Hello! How can I assist you today?", "images": null, "tool_calls": null }, { "role": "user", "content": "goodbye" }, { "role": "assistant", "content": "It was nice chatting with you, even if it was brief. Goodbye for now!", "images": null, "tool_calls": null } ] } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#67473