From 56e95197c6d8b28b546a246ae6a3bb1cbfef9190 Mon Sep 17 00:00:00 2001 From: estill01 Date: Sat, 2 Dec 2023 19:50:18 -0800 Subject: [PATCH 1/3] Enable setting default `model` value for `Completions` add `model` arg to `Completions` class; if you provide a value, it will be used when you create new completions from an instance of the class. --- litellm/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/litellm/main.py b/litellm/main.py index 850d2567239..89bb27dd981 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -98,17 +98,23 @@ class Chat(): def __init__(self, params): self.params = params self.completions = Completions(self.params) - + class Completions(): - def __init__(self, params): + def __init__(self, model, params): self.params = params + self.model = model - def create(self, model, messages, **kwargs): + def create(self, messages, model=None, **kwargs): + if model is None: + if self.model is not None: + model = self.model + else: + raise ValueError("a value for `model` is required) for k, v in kwargs.items(): self.params[k] = v response = completion(model=model, messages=messages, **self.params) - return response + return response @client async def acompletion(*args, **kwargs): From 82fbbf67ca35bfac2b6b52b422d6647eb266eb68 Mon Sep 17 00:00:00 2001 From: estill01 Date: Sun, 3 Dec 2023 05:34:24 +0000 Subject: [PATCH 2/3] Fix; persistent 'model' default value --- litellm/main.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/litellm/main.py b/litellm/main.py index 89bb27dd981..ec5a8ce1c01 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -103,16 +103,11 @@ class Completions(): def __init__(self, model, params): self.params = params - self.model = model def create(self, messages, model=None, **kwargs): - if model is None: - if self.model is not None: - model = self.model - else: - raise ValueError("a value for `model` is required) for k, v in kwargs.items(): self.params[k] = v + model = model or self.params.get('model') response = completion(model=model, messages=messages, **self.params) return response From 737abbb0c1341439307d2ffe3ff6db1914e6e6ae Mon Sep 17 00:00:00 2001 From: estill01 Date: Sun, 3 Dec 2023 05:37:57 +0000 Subject: [PATCH 3/3] fix --- litellm/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/main.py b/litellm/main.py index ec5a8ce1c01..977f156ca3f 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -101,7 +101,7 @@ class Chat(): class Completions(): - def __init__(self, model, params): + def __init__(self, params): self.params = params def create(self, messages, model=None, **kwargs):