Created
May 14, 2024 01:09
-
-
Save gh640/26f463e3eff9487377205f94c3860238 to your computer and use it in GitHub Desktop.
Sample: Change multiple OpenAI assistants models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Change multiple OpenAI Assistants' models""" | |
import click | |
from openai import OpenAI | |
EXCLUDED_IDS = [] | |
MODELS_MAP = { | |
"gpt-4-turbo-preview": "gpt-4o", | |
"gpt-4-turbo": "gpt-4o", | |
} | |
@click.command() | |
@click.option("--dry-run", is_flag=True) | |
def main(dry_run: bool): | |
client = OpenAI() | |
assistants = yield_all_assistants(client) | |
for a in assistants: | |
if a.id in EXCLUDED_IDS: | |
continue | |
if new_model := MODELS_MAP.get(a.model): | |
print(f"Changing model of {a.name} from {a.model} to {new_model}") | |
if dry_run: | |
continue | |
client.beta.assistants.update(assistant_id=a.id, model=new_model) | |
def yield_all_assistants(client): | |
assistants = [*client.beta.assistants.list()] | |
while assistants: | |
yield from assistants | |
after = assistants[-1].id | |
assistants = [*client.beta.assistants.list(after=after)] | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
list_assistants.py
: