Hi all, admit I didn’t pay much attention to OpenAI’s dev day, so I got tripped up this evening when I did a virtual env refresh, and all my local LLM access code broke. Turns out they massively revved their API. This is mostly news for folks like me who either maintain an LLM-related project, or who just prefer to write their own API access clients. I think we probably have enough of us here to share some useful notes—I see ya’ll posting Python code now and then.

Anyway, the best news is that they deprecated the nasty old “hack this imported global resource approach” in favor of something more encapsulated.

Here’s a quick example of using the updated API with a local LLM (at localhost). Works with my llama-cpp-python hosted LLM. Their new API docs are a bit on the sparse side, so I had to do some spelunking in the upstream code to straighten it all out.

from openai import OpenAI
client = OpenAI(api_key='dummy', base_url='http://127.0.0.1:8000/v1/')
chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    # Just use whatever llama-cpp-python or whatever mounts for the model
    model="dummy",
)
print(chat_completion.choices[0].message.content)

Final line prints just the actual first choice response message text you might be familiar with from the underlying JSON structure.

I’ll continue to maintain notes in this ticket as I update OgbujiPT (open source client-side LLM toolkit), but I’ll also update this thread with any other really interesting bits I come across.

  • DreamGenX@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I have been using the Python API client 1.0 preview version (which was just released) for some time with vLLM OpenAI compatible server and it worked well – at least I did not notice any issues.

  • Ok_Kaleidoscope_9992@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Hi,

    Our working chatGPT 4 API calls stopped working after openAI updated library (keeps on updating)

    In our current setup we are using langchain == 0.0.312, openai == 0.27.8 .

    My basic question is to understand what is the ideal time and effort to update the current setup to support GPT4.

    My developer saying it will take 2 days of work and I am already doubting on that. TIA.

  • rpbmpn@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Just finding this thread a couple weeks later. Some of my old scripts somehow continue to work, but when I try to write new ones in the old style they don’t.

    Is it just me, or is OpenAI actually really terrible at almost everything except, for the time being, just creating the best AI models. Every productization and user interface update is just absolutely bungled.