PublicAI

PublicAI

PublicAI가 제공하는 대규모 언어 모델(swiss-ai apertus 등)을 LiteLLM에서 사용하는 방법을 알아봐요.

출처: 문서

본문

개요

속성 내용
설명 PublicAI는 swiss-ai apertus 모델 등 필수 모델을 포함한 대규모 언어 모델을 제공해요
LiteLLM 라우트 publicai/
공식 문서 PublicAI ↗
Base URL https://platform.publicai.co/
지원 연산 /chat/completions

모든 PublicAI 모델을 지원하며, completion 요청을 보낼 때 publicai/를 접두사로 붙이면 돼요.

필수 변수

os.environ["PUBLICAI_API_KEY"] = ""  # your PublicAI API key

Base URL을 덮어쓸 수 있어요:

os.environ["PUBLICAI_API_BASE"] = "https://platform.publicai.co/v1"

LiteLLM Python SDK 사용법

비스트리밍

import os
import litellm
from litellm import completion

os.environ["PUBLICAI_API_KEY"] = ""  # your PublicAI API key

messages = [{"content": "Hello, how are you?", "role": "user"}]

# PublicAI call
response = completion(
    model="publicai/swiss-ai/apertus-8b-instruct",
    messages=messages
)

print(response)

스트리밍

import os
import litellm
from litellm import completion

os.environ["PUBLICAI_API_KEY"] = ""  # your PublicAI API key

messages = [{"content": "Hello, how are you?", "role": "user"}]

# PublicAI call with streaming
response = completion(
    model="publicai/swiss-ai/apertus-8b-instruct",
    messages=messages,
    stream=True
)

for chunk in response:
    print(chunk)

LiteLLM Proxy 사용법

LiteLLM Proxy 설정 파일에 다음을 추가해요.

config.yaml:

model_list:
  - model_name: swiss-ai-apertus-8b
    litellm_params:
      model: publicai/swiss-ai/apertus-8b-instruct
      api_key: os.environ/PUBLICAI_API_KEY

  - model_name: swiss-ai-apertus-70b
    litellm_params:
      model: publicai/swiss-ai/apertus-70b-instruct
      api_key: os.environ/PUBLICAI_API_KEY

LiteLLM Proxy 서버를 시작해요:

litellm --config config.yaml

# RUNNING on http://0.0.0.0:4000

Proxy를 통한 PublicAI - 비스트리밍 (OpenAI SDK)

from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
    base_url="http://localhost:4000",  # Your proxy URL
    api_key="your-proxy-api-key"       # Your proxy API key
)

# Non-streaming response
response = client.chat.completions.create(
    model="swiss-ai-apertus-8b",
    messages=[{"role": "user", "content": "hello from litellm"}]
)

print(response.choices[0].message.content)

Proxy를 통한 PublicAI - 스트리밍 (OpenAI SDK)

from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
    base_url="http://localhost:4000",  # Your proxy URL
    api_key="your-proxy-api-key"       # Your proxy API key
)

# Streaming response
response = client.chat.completions.create(
    model="swiss-ai-apertus-8b",
    messages=[{"role": "user", "content": "hello from litellm"}],
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

Proxy를 통한 PublicAI - LiteLLM SDK

import litellm

# Configure LiteLLM to use your proxy
response = litellm.completion(
    model="litellm_proxy/swiss-ai-apertus-8b",
    messages=[{"role": "user", "content": "hello from litellm"}],
    api_base="http://localhost:4000",
    api_key="your-proxy-api-key"
)

print(response.choices[0].message.content)

Proxy를 통한 PublicAI - LiteLLM SDK 스트리밍

import litellm

# Configure LiteLLM to use your proxy with streaming
response = litellm.completion(
    model="litellm_proxy/swiss-ai-apertus-8b",
    messages=[{"role": "user", "content": "hello from litellm"}],
    api_base="http://localhost:4000",
    api_key="your-proxy-api-key",
    stream=True
)

for chunk in response:
    if hasattr(chunk.choices[0], 'delta') and chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

Proxy를 통한 PublicAI - cURL

curl http://localhost:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-p...-key" \
  -d '{
    "model": "swiss-ai-apertus-8b",
    "messages": [{"role": "user", "content": "hello from litellm"}]
  }'

Proxy를 통한 PublicAI - cURL 스트리밍

curl http://localhost:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-p...-key" \
  -d '{
    "model": "swiss-ai-apertus-8b",
    "messages": [{"role": "user", "content": "hello from litellm"}],
    "stream": true
  }'

LiteLLM Proxy 사용에 대한 자세한 내용은 LiteLLM Proxy 문서를 참고해요.

더 알아보기 (Learn more)

  • PublicAI 공식 문서
  • LiteLLM Proxy 문서