run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
37.13k stars 5.33k forks source link

[Feature Request]: New OpenAI model `gpt-4-0125-preview` is not available #10287

Closed sasensi closed 10 months ago

sasensi commented 10 months ago

Feature Description

I would like to use the latest model from OpenAI: gpt-4-0125-preview, published yesterday. You can see it announced in this blog post and listed on this page.

Reason

Currently, if you run the following script:

import os
from dotenv import load_dotenv
from llama_index import Document, ServiceContext, VectorStoreIndex
from llama_index.llms import OpenAI

MODEL = "gpt-4-0125-preview"

load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
documents = [Document(text="my text")]
service_context = ServiceContext.from_defaults(llm=OpenAI(model=MODEL))
index = VectorStoreIndex.from_documents(documents, service_context=service_context)
query_engine = index.as_query_engine()
response = query_engine.query("What is this about ?")
print("response:", response)

You receive this error:

ValueError: Unknown model 'gpt-4-0125-preview'. Please provide a valid OpenAI model name in: gpt-4, gpt-4-32k, gpt-4-1106-preview, gpt-4-vision-preview, gpt-4-0613, gpt-4-32k-0613, gpt-4-0314, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-16k, gpt-3.5-turbo-1106, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k-0613, gpt-3.5-turbo-0301, text-davinci-003, text-davinci-002, gpt-3.5-turbo-instruct, text-ada-001, text-babbage-001, text-curie-001, ada, babbage, curie, davinci, gpt-35-turbo-16k, gpt-35-turbo, gpt-35-turbo-1106, gpt-35-turbo-0613, gpt-35-turbo-16k-0613

Value of Feature

The new model include a fix allowing to use other language than english in json output.

The change to make seems to be quite simple, I tried it by updating the venv/Lib/site-packages/llama_index/llms/openai_utils.py file locally as such: Update this piece of code from:

GPT4_MODELS: Dict[str, int] = {
    # stable model names:
    #   resolves to gpt-4-0314 before 2023-06-27,
    #   resolves to gpt-4-0613 after
    "gpt-4": 8192,
    "gpt-4-32k": 32768,
    # 1106 model (Turbo, JSON mode)
    "gpt-4-1106-preview": 128000,
    # multimodal model
    "gpt-4-vision-preview": 128000,
    # 0613 models (function calling):
    #   https://openai.com/blog/function-calling-and-other-api-updates
    "gpt-4-0613": 8192,
    "gpt-4-32k-0613": 32768,
    # 0314 models
    "gpt-4-0314": 8192,
    "gpt-4-32k-0314": 32768,
}

to

GPT4_MODELS: Dict[str, int] = {
    # stable model names:
    #   resolves to gpt-4-0314 before 2023-06-27,
    #   resolves to gpt-4-0613 after
    "gpt-4": 8192,
    "gpt-4-32k": 32768,
    # 0125 model (Turbo, JSON mode)
    "gpt-4-0125-preview": 128000,
    # 1106 model (Turbo, JSON mode)
    "gpt-4-1106-preview": 128000,
    # multimodal model
    "gpt-4-vision-preview": 128000,
    # 0613 models (function calling):
    #   https://openai.com/blog/function-calling-and-other-api-updates
    "gpt-4-0613": 8192,
    "gpt-4-32k-0613": 32768,
    # 0314 models
    "gpt-4-0314": 8192,
    "gpt-4-32k-0314": 32768,
}

Note that they also introduce a gpt-4-turbo-preview model, which could be added the same way and would be great to have also.

I can take care of the PR if this is the right change and if needed. Thank you in advance.

dosubot[bot] commented 10 months ago

šŸ¤–

Thank you for your detailed feature request! It's great to see your enthusiasm for incorporating the new OpenAI model gpt-4-0125-preview into the project. Your proposed solution looks promising, and it's wonderful that you're willing to take care of the PR if necessary. Your contribution would be highly appreciated. Keep up the great work!


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a šŸ‘ if this is helpful and šŸ‘Ž if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.