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

adding support for Claude, Cohere and PaLM + Model Fallback Strategy (prevent failed requests) #119

Open
wants to merge 3 commits into
base: master
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
24 changes: 15 additions & 9 deletions agent/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from fastapi import WebSocket
import time

from litellm import completion
import openai
from colorama import Fore, Style
from openai.error import APIError, RateLimitError
Expand Down Expand Up @@ -69,13 +69,19 @@ def send_chat_completion_request(
messages, model, temperature, max_tokens, stream, websocket
):
if not stream:
result = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature,
max_tokens=max_tokens,
)
return result.choices[0].message["content"]
model_fallback_list = ["claude-instant-1", "gpt-3.5-turbo", "gpt-3.5-turbo-16k"]
model_fallback_list = [model] + model_fallback_list
for model in model_fallback_list:
try:
result = completion(
model=model,
messages=messages,
temperature=temperature,
max_tokens=max_tokens,
)
return result.choices[0].message["content"]
except:
pass
else:
return stream_response(model, messages, temperature, max_tokens, websocket)

Expand Down Expand Up @@ -114,7 +120,7 @@ def choose_agent(task: str) -> str:
try:
configuration = choose_agent_configuration()

response = openai.ChatCompletion.create(
response = completion(
model=CFG.smart_llm_model,
messages=[
{"role": "user", "content": f"{task}"}],
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pydantic
fastapi
python-multipart
markdown
litellm==0.1.2291