Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI API: new parameter to change model list behavior #6358

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion extensions/openai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@ def get_current_model_info():


def list_models():
return {'model_names': get_available_models()[1:]}
mode = shared.args.model_selection_mode

result = {
"object": "list",
"data": []
}

# Inclure les dummy models si le bit 0 est activé
if mode & 1:
dummy_models = ['gpt-3.5-turbo', 'text-embedding-ada-002']
for model in dummy_models:
result["data"].append(model_info_dict(model))

# Inclure les modèles locaux si le bit 1 est activé
if mode & 2:
if mode & 4:
# Ne renvoyer que le modèle actuellement chargé
result["data"].append(model_info_dict(shared.model_name))
else:
# Renvoyer tous les modèles disponibles
for model in get_available_models():
result["data"].append(model_info_dict(model))

return result


def list_dummy_models():
Expand Down
2 changes: 1 addition & 1 deletion extensions/openai/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def handle_models(request: Request):
is_list = request.url.path.split('?')[0].split('#')[0] == '/v1/models'

if is_list:
response = OAImodels.list_dummy_models()
response = OAImodels.list_models()
else:
model_name = path[len('/v1/models/'):]
response = OAImodels.model_info_dict(model_name)
Expand Down
1 change: 1 addition & 0 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
group.add_argument('--api-key', type=str, default='', help='API authentication key.')
group.add_argument('--admin-key', type=str, default='', help='API authentication key for admin tasks like loading and unloading models. If not set, will be the same as --api-key.')
group.add_argument('--nowebui', action='store_true', help='Do not launch the Gradio UI. Useful for launching the API in standalone mode.')
group.add_argument('--model-selection-mode', type=int, default=0, help='Model selection mode: bitwise flag. 1=Include dummy models, 2=Include local models, 4=Return only the currently loaded model if local models are included.')

# Multimodal
group = parser.add_argument_group('Multimodal')
Expand Down