Skip to content

Commit

Permalink
Remove unused Python API deps
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Jul 1, 2023
1 parent a88dc82 commit f51abd1
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 467 deletions.
2 changes: 1 addition & 1 deletion api-service/agent/smol_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def create(
# Use default openai api key
new_config.args["openai_api_key"] = default_openai_api_key

model = get_model(new_config, callback_manager)
model = get_model(new_config, callback_manager, streaming=False)

return cls(
new_config,
Expand Down
74 changes: 2 additions & 72 deletions api-service/models/base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
from typing import Dict, Any, List, Literal
from enum import Enum
from langchain.chat_models import ChatOpenAI, AzureChatOpenAI
from langchain.llms import Anthropic
from langchain.chat_models import ChatOpenAI
from langchain.schema import BaseLanguageModel
from langchain.callbacks.base import BaseCallbackManager
from pydantic import BaseModel

from .providers.replicate import ReplicateFix
from .providers.hugging_face import HuggingFaceHubFix, HuggingFaceEndpointFix
from .providers.banana import BananaFix


class ModelProvider(Enum):
OpenAI = "OpenAI"
AzureOpenAI = "AzureOpenAI"
Replicate = "Replicate"
Anthropic = "Anthropic"
HuggingFace = "HuggingFace"
Banana = "Banana"


class PromptPart(BaseModel):
Expand All @@ -39,74 +29,14 @@ def get_model(
streaming=True,
) -> BaseLanguageModel:
match config.provider:
case ModelProvider.Anthropic.value:
return Anthropic(
**config.args,
verbose=True,
streaming=True,
callback_manager=callback_manager,
)
case ModelProvider.OpenAI.value:
return ChatOpenAI(
**config.args,
request_timeout=3600,
verbose=True,
# The max time between retries is 1 minute so we set max_retries to 45
max_retries=45,
streaming=False,
callback_manager=callback_manager,
)
case ModelProvider.AzureOpenAI.value:
return AzureChatOpenAI(
**config.args,
request_timeout=3600,
verbose=True,
streaming=True,
callback_manager=callback_manager,
)
case ModelProvider.Replicate.value:
return ReplicateFix(
model=config.args["model"],
replicate_api_token=config.args["replicate_api_token"],
model_kwargs=config.args,
verbose=True,
callback_manager=callback_manager,
)
case ModelProvider.HuggingFace.value:
if config.args.get("endpoint_url"):
return HuggingFaceEndpointFix(
huggingfacehub_api_token=config.args["huggingfacehub_api_token"],
endpoint_url=config.args["endpoint_url"],
verbose=True,
model_kwargs={
**config.args,
"huggingfacehub_api_token": None,
"endpoint_url": None,
},
callback_manager=callback_manager,
task="text-generation",
)
elif config.args.get("repo_id"):
return HuggingFaceHubFix(
huggingfacehub_api_token=config.args["huggingfacehub_api_token"],
repo_id=config.args["repo_id"],
model_kwargs={
**config.args,
"huggingfacehub_api_token": None,
"repo_id": None,
},
verbose=True,
callback_manager=callback_manager,
) # type: ignore
raise ValueError(
f"Missing endpoint_url or repo_id for the HuggingFace integration."
)
case ModelProvider.Banana.value:
return BananaFix(
model_key=config.args["model_key"],
banana_api_key=config.args["banana_api_key"],
model_kwargs=config.args,
verbose=True,
streaming=streaming,
callback_manager=callback_manager,
)
case _:
Expand Down
Empty file.
27 changes: 0 additions & 27 deletions api-service/models/providers/banana.py

This file was deleted.

40 changes: 0 additions & 40 deletions api-service/models/providers/hugging_face.py

This file was deleted.

56 changes: 0 additions & 56 deletions api-service/models/providers/replicate.py

This file was deleted.

Loading

0 comments on commit f51abd1

Please sign in to comment.