간단 확인용 쳇

이우철·2025년 9월 21일

ollama llm(library) list 확인 : curl http://localhost:11434/api/tags

  • openai
from agents import Agent, Runner
from dotenv import load_dotenv
load_dotenv()
def main():

    agent = Agent(
        name='Assistant',
        instructions='You are a helpful assistant. Always maintain memory of the conversation history and remember the user\'s name is Dabid.',
        model="gpt-4o-mini", 
        )
    
    messages = []
    while True:
        user_input = input("\nYou: ")
        messages.append({"role": "user", "content": user_input})
        print("Assistant: ", end="")
        result = Runner.run_sync(
            agent, 
            input=messages
        )
        assistant_response = str(result.final_output)
        print(assistant_response)
        messages.append({"role": "assistant", "content": assistant_response})

# Run it
if __name__ == "__main__":
    main()
  • ollama (in local docker)
import requests
from dotenv import load_dotenv
load_dotenv()

OLLAMA_URL = "http://localhost:11434/api/chat"

def main():
    system_prompt = {
        "role": "system",
        "content": "You are a helpful assistant. Always maintain memory of the conversation history and remember the user's name is Dabid."
    }

    messages = [system_prompt]

    while True:
        user_input = input("\nYou: ")
        messages.append({"role": "user", "content": user_input})

        payload = {
            "model": "qwen2.5:7b-instruct", 
            "messages": messages,
            "stream": False
        }

        response = requests.post(OLLAMA_URL, json=payload)
        response.raise_for_status()
        assistant_response = response.json()["message"]["content"]

        print("Assistant:", assistant_response)
        messages.append({"role": "assistant", "content": assistant_response})

if __name__ == "__main__":
    main()
profile
개발 정리 공간 - 업무일때도 있고, 공부일때도 있고...

0개의 댓글