forked from phoenix/litellm-mirror
update context window exception tutorial
This commit is contained in:
parent
879f97f620
commit
33cc1e2cab
1 changed files with 12 additions and 5 deletions
|
@ -52,9 +52,16 @@ context_window_fallback_list = ["gpt-3.5-turbo-16k", "gpt-4", "claude-instant-1"
|
||||||
user_message = "Hello, how are you?"
|
user_message = "Hello, how are you?"
|
||||||
messages = [{ "content": user_message,"role": "user"}]
|
messages = [{ "content": user_message,"role": "user"}]
|
||||||
|
|
||||||
for model in context_window_fallback_list:
|
initial_model = "gpt-3.5-turbo"
|
||||||
try:
|
try:
|
||||||
response = completion(model=model, messages=messages)
|
response = completion(model=initial_model, messages=messages)
|
||||||
except ContextWindowExceededError as e:
|
except ContextWindowExceededError as e:
|
||||||
completion_with_fallbacks(model=context_window_fallback_list[0], messages=messages, fallbacks=context_window_fallback_list[1:])
|
for model in context_window_fallback_list:
|
||||||
|
try:
|
||||||
|
response = completion(model=model, messages=messages)
|
||||||
|
return response
|
||||||
|
except ContextWindowExceededError as e:
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(response)
|
||||||
```
|
```
|
Loading…
Add table
Add a link
Reference in a new issue