본문 바로가기
프로그램

[A.I] 파이썬으로 ollama에 접속하기

by 오디세이99 2025. 4. 11.
728x90
반응형

다음과 같이 설치된 모델을 확인합니다.

llama3를 사용하려고 합니다.

코드에서 'model'에는 list에 나와있는 'NAME'을 사용합니다.

import ollama

def chat_with_ollama(model="llama3:latest", base_url="http://localhost:11434"):
    client = ollama.Client()

    while True:
        user_input = input("사용자: ")
        if user_input.lower() == "종료":
            break

        messages = [{"role": "user", "content": user_input}]
        response = client.chat(model=model, messages=messages)

        print("Ollama:", response['message']['content'])

if __name__ == "__main__":
    chat_with_ollama()

 

728x90
반응형

댓글