[PR #90] [CLOSED] Add an example using continuous dialogue #352

Closed
opened 2026-02-15 16:30:05 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama-python/pull/90
Author: @Gloridust
Created: 3/12/2024
Status: Closed

Base: mainHead: chat-continuous


📝 Commits (1)

📊 Changes

1 file changed (+25 additions, -0 deletions)

View changed files

examples/chat-continuous/main.py (+25 -0)

📄 Description

Add an example using continuous dialogue.

import ollama

def get_response(message_history):
    model_name = 'qwen:7b'
    try:
        response = ollama.chat(model=model_name, messages=message_history, stream=False)
        received_message = response['message']
        return received_message['content'], received_message
    except Exception as e:
        print(f"An error occurred: {e}")
        return "", {}

message_history = []
while True:
    user_input = input("Input (or type 'exit' to quit):")
    if user_input.lower() == 'exit':
        break
    message = {'role': 'user', 'content': user_input}
    message_history.append(message)
    output_text, received_message = get_response(message_history)
    if output_text:
        message_history.append(received_message)
        print(output_text)
    else:
        print("Failed to get response.")


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama-python/pull/90 **Author:** [@Gloridust](https://github.com/Gloridust) **Created:** 3/12/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `chat-continuous` --- ### 📝 Commits (1) - [`0446152`](https://github.com/ollama/ollama-python/commit/04461522b661fe3a50c8b253b2ef9bd01fadc7a4) add: example/main.py ### 📊 Changes **1 file changed** (+25 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `examples/chat-continuous/main.py` (+25 -0) </details> ### 📄 Description Add an example using continuous dialogue. ```pyhton import ollama def get_response(message_history): model_name = 'qwen:7b' try: response = ollama.chat(model=model_name, messages=message_history, stream=False) received_message = response['message'] return received_message['content'], received_message except Exception as e: print(f"An error occurred: {e}") return "", {} message_history = [] while True: user_input = input("Input (or type 'exit' to quit):") if user_input.lower() == 'exit': break message = {'role': 'user', 'content': user_input} message_history.append(message) output_text, received_message = get_response(message_history) if output_text: message_history.append(received_message) print(output_text) else: print("Failed to get response.") ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 16:30:05 -05:00
yindo closed this issue 2026-02-15 16:30:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#352