Quantcast
Channel: 丁才軒討論站
Viewing all articles
Browse latest Browse all 75

網路與網站知識 • DeepSeek + Python

$
0
0
參考:
https://medium.com/@Mert.A/install-deep ... 59de3c160d

安裝 ollama

CODE:

pip install ollama
範例程式:

CODE:

import ollamamodel = "deepseek-r1:1.5b"messages = []while True:    user_input = input("You: ")    # Exit Condition    if user_input.lower() == "exit":        break    # Response Initialization    response = [        {'role': 'user',         'content': user_input},        {'role': 'assistant',         'content': ""},    ]    # Generating AI Responses    for part in ollama.chat(model=model, messages=messages + [        {"role": "user", "content": user_input}    ], stream=True):        # Processing AI Response        print(part["message"]["content"], end='', flush=True)        response[1]["content"] += part.message.content    print()    # Add the response to the messages to maintain the history    messages += response

統計資料: 發表於 由 dtchang — 2025-02-06, 19:24



Viewing all articles
Browse latest Browse all 75

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>