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

DH-4854/removing litellm and sending question id at timeouts #211

Merged
Merged
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
2 changes: 2 additions & 0 deletions dataherald/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def answer_question_with_timeout(
question=question_request.question,
db_connection_id=question_request.db_connection_id,
)
question_repository = QuestionRepository(self.storage)
user_question = question_repository.insert(user_question)
stop_event = threading.Event()

def run_and_catch_exceptions():
Expand Down
15 changes: 10 additions & 5 deletions dataherald/model/chat_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from typing import Any

from langchain.chat_models import ChatLiteLLM
from langchain.chat_models import ChatAnthropic, ChatCohere, ChatGooglePalm, ChatOpenAI
from overrides import override

from dataherald.model import LLMModel
Expand Down Expand Up @@ -34,7 +34,12 @@ def get_model(
os.environ["GOOGLE_API_KEY"] = api_key
elif model_family == "cohere":
os.environ["COHERE_API_KEY"] = api_key
try:
return ChatLiteLLM(model_name=self.model_name, **kwargs)
except Exception as e:
raise ValueError("No valid API key environment variable found") from e
if os.environ.get("OPENAI_API_KEY") is not None:
return ChatOpenAI(model_name=self.model_name, **kwargs)
if os.environ.get("ANTHROPIC_API_KEY") is not None:
return ChatAnthropic(model_name=self.model_name, **kwargs)
if os.environ.get("GOOGLE_API_KEY") is not None:
return ChatGooglePalm(model_name=self.model_name, **kwargs)
if os.environ.get("COHERE_API_KEY") is not None:
return ChatCohere(model_name=self.model_name, **kwargs)
raise ValueError("No valid API key environment variable found")
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ sphinx-book-theme==1.0.1
boto3==1.28.38
botocore==1.31.38
PyAthena==3.0.6
litellm==0.7.3