기본 콘텐츠로 건너뛰기

2월, 2025의 게시물 표시
OpenAI API 대신 ollama API 서버 사용해보기 OPENAI는 경쟁자 대비 성능과 편의성에서 앞서 나가고 있기 때문에 후발주자는 OpenAI의 API형태를 산업표준처럼 지원하고 있다. 실제 서비스를 위해서는 성능 좋은 OpenAI API 서비스를 사용해야하지만 학습하는 입장에서API호출하는 방법을 연습하기 위해서 Ollama Server가 제공하는 호환 API로 동작테스트해본다. 일반적으로 설치한 Ollama 서버는 0.0.0.0:11434 port에서 통상 동작한다. 다르게 변경했다면 그에 맞게 수정필요하다. " v1/chat/completions" 이 부분은 OpenAI 가 제공한 API endpoint인데 후발주자들도 이 형식을 지원한다. Ollama 서버이용 import requests import json def classify_intent_llm ( text ):     system_prompt = f """You are a helpful assistant that classifies user intents based on a few examples. Examples: - User: 오늘 서울의 날씨는 어때? -> Intent: weather - User: 가까운 커피숍 어디 있어? -> Intent: location_search - User: 최근에 출시된 대출 상품에 대해 알려줘. -> Intent: product_info Consideration: Only outputs the name of intent. """     user_prompt = f """Classify the following user input: User: { text } -> Intent: """     # Ollama API 엔드포인트     url = "http://localhost:11434...