Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated it to take in q as arg! #1

Open
jamieduk opened this issue Jan 28, 2025 · 0 comments
Open

Updated it to take in q as arg! #1

jamieduk opened this issue Jan 28, 2025 · 0 comments

Comments

@jamieduk
Copy link

I updated it

from ollama import chat
import sys

# Check if a question is passed as an argument
if len(sys.argv) < 2:
    print("Please provide a question as an argument.")
    sys.exit(1)

# Get the question from command-line arguments
question=sys.argv[1]

# Set up the chat with the provided question
stream=chat(
    model='crewai-deepseek-r1:7b',
    messages=[{'role': 'user', 'content': question}],
    stream=True,
)

reasoning_content=""
content=""

# Process the stream and handle the content
for chunk in stream:
    if chunk and 'message' in chunk and chunk['message'].content:
        # Get the content from the chunk
        chunk_content=chunk['message'].content
        
        # Print the content immediately, without newline
        sys.stdout.write(chunk_content)
        sys.stdout.flush()
        
        # Store in appropriate buffer
        if chunk_content.startswith('<think>'):
            in_thinking=True
        elif chunk_content.startswith('</think>'):
            in_thinking=False
        else:
            if 'in_thinking' in locals() and in_thinking:
                reasoning_content += chunk_content
            else:
                content += chunk_content

# Output the reasoning and final answer
print("\n\nReasoning:", reasoning_content)
print("\nFinal Answer:", content)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant