Skip to main content

Oasis LLM Proxy Client

Project description

OASIS-SDK

1. Concept

OASIS-LLM-PROXY-CLIENT는 OpenAI, Azure OpenAI 등 다양한 LLM Provider의 공식 SDK 및 LangChain을 얇게 wrapping하여, 사내 규칙에 맞는 필드 입력과 프록시 서버를 통한 키 주입을 지원하는 Python 라이브러리입니다. 원본 라이브러리의 모든 기능을 그대로 사용할 수 있도록 설계되어, 기존 SDK와 LangChain의 확장성과 호환성을 최대한 보장합니다.

2. Usage

2.1 install

pip install oasis-sdk

2.2 example

0. parameters

[required]

  • user_id: 사용자의 id
  • workspace_id: 사용자의 workspace id
  • tenant_id: 사용자의 tenant id
  • proxy_url: Llm Proxy Server

[optional]

  • user_ip: 사용자의 ip (defualt=127.0.0.1)
  • plugin_name: 호출한 시스템 명 (ex, chatbot, mcp1, rag-mcp, ..., default=default-plugin)

[auto]

  • root_id: 클라이언트 생성시 발급
  • req_id: 요청시마다 발급

📍 주의

  • 1번의 연속적인 수행에서 root_id는 고정되어야 함
  • 연계되는 시스템에서는 클라이언트 생성시 초기 발급된 root_id를 주입하여 사용

2.2.1 SDK

1. openai

# 동기 클라이언트
client = OasisOpenAI(
    user_id="user_id",
    workspace_id="workspace_id",
    tenant_id="tenant_id",
    proxy_url="llm_proxy_server",
    user_ip="user_ip",
    plugin_name="your_system"
)

# 동기 호출
resp = client.chat.completions.create(
    model="model",
    messages=[{"role": "user", "content": "안녕?"}],
)

# 동기 스트림
stream = client.chat.completions.create(
    model="model",
    messages=[{"role": "user", "content": "안녕?"}],
    stream=True,
)

# 비동기 클라이언트
aync_client = OasisAsyncOpenAI(
    user_id="user_id",
    workspace_id="workspace_id",
    tenant_id="tenant_id",
    proxy_url="llm_proxy_server",
    user_ip="user_ip",
    plugin_name="your_system"
)

# 비동기 호출
resp = await aync_client.chat.completions.create(
    model="model",
    messages=[{"role": "user", "content": "안녕?"}],
)

# 비동기 스트림
stream = await aync_client.chat.completions.create(
    model="model",
    messages=[{"role": "user", "content": "안녕?"}],
    stream=True,
)

2. azure openai

# 동기 클라이언트
client = OasisAzureOpenAI(
    user_id="user_id",
    workspace_id="workspace_id",
    tenant_id="tenant_id",
    proxy_url="llm_proxy_server",
    user_ip="user_ip",
    plugin_name="your_system"
)

# 동기 호출
resp = client.chat.completions.create(
    model="deployment",
    messages=[{"role": "user", "content": "안녕?"}],
)

# 동기 스트림
stream = client.chat.completions.create(
    model="model",
    messages=[{"role": "user", "content": "안녕?"}],
    stream=True,
)

# 비동기 클라이언트
aync_client = OasisAsyncAzureOpenAI(
    user_id="user_id",
    workspace_id="workspace_id",
    tenant_id="tenant_id",
    proxy_url="llm_proxy_server",
    user_ip="user_ip",
    plugin_name="your_system"
)

# 비동기 호출
resp = await aync_client.chat.completions.create(
    model="model",
    messages=[{"role": "user", "content": "안녕?"}],
)

# 비동기 스트림
stream = await aync_client.chat.completions.create(
    model="model",
    messages=[{"role": "user", "content": "안녕?"}],
    stream=True,
)

2.2.2 Langchain

1. openai

llm = OasisChatOpenAI(
    user_id="user_id",
    workspace_id="workspace_id",
    tenant_id="tenant_id",
    proxy_url="llm_proxy_server",
    user_ip="user_ip",
    plugin_name="your_system"
)

# 동기 호출
resp = llm.invoke("안녕 Azure LangChain!")

# 비동기 호출
resp = await llm.ainvoke("안녕 Azure LangChain!")

# 동기 스트림
resp = llm.stream("안녕 Azure LangChain!")

# 비동기 스트림
resp = await llm.astream("안녕 Azure LangChain!")

2. azure openai

llm = OasisAzureChatOpenAI(
    user_id="user_id",
    workspace_id="workspace_id",
    tenant_id="tenant_id",
    proxy_url="llm_proxy_server",
    user_ip="user_ip",
    plugin_name="your_system"
)

# 동기 호출
resp = llm.invoke("안녕 Azure LangChain!")

# 비동기 호출
resp = await llm.ainvoke("안녕 Azure LangChain!")

# 동기 스트림
resp = llm.stream("안녕 Azure LangChain!")

# 비동기 스트림
resp = await llm.astream("안녕 Azure LangChain!")

3. Dependency

  • python 3.11.x
  • openai 1.97.0
  • langchain-openai 0.3.28

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oasis_sdk-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oasis_sdk-0.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file oasis_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: oasis_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for oasis_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b16e363fc3710e83a54ada99d10b8bfdf81e56227d52fb648c9d9352f1b73dd1
MD5 a2cfd0bfa1180695c8b76aacaf98630d
BLAKE2b-256 f415df70f997e95dde7c4770bb93f15e2e9855e9862f9fe02bc0160aeaf0ae38

See more details on using hashes here.

File details

Details for the file oasis_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oasis_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for oasis_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e385ab177bc8027de370c69424e2c7a2beaeec70122e1b7a2569e307571bbe1b
MD5 46e6887c84f30a9891323c9be79cb04e
BLAKE2b-256 a6bbd391ce074434e17be62c7e2e50bcb44a62ed1d41095e4bb3a7bbefb3055f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page