File size: 444 Bytes
c25ce6b
 
c065ba1
c25ce6b
c065ba1
c25ce6b
 
 
efca194
c065ba1
c25ce6b
c065ba1
 
 
c25ce6b
 
c065ba1
c25ce6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os
from openai import OpenAI
import urllib

def init_llm_client(api_key, base_url=None):
    """
    Initialize the OpenAI client with the provided API key and model ID.
    """

    if base_url and len(base_url) > 0 and base_url.startswith("http"):
        os.environ["OPENAI_API_BASE"] = base_url
    else:
        base_url = None
    
    os.environ["OPENAI_API_KEY"] = api_key

    return OpenAI(api_key=api_key, base_url=base_url)