Skip to content

Improve LLMs and Embedding models resources experience #21

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

Merged
merged 2 commits into from
Apr 11, 2024
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
11 changes: 7 additions & 4 deletions libs/kotaemon/kotaemon/embeddings/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BaseOpenAIEmbeddings(BaseEmbeddings):

_dependencies = ["openai"]

api_key: str = Param(help="API key", required=True)
api_key: str = Param(None, help="API key", required=True)
timeout: Optional[float] = Param(None, help="Timeout for the API request.")
max_retries: Optional[int] = Param(
None, help="Maximum number of retries for the API request."
Expand Down Expand Up @@ -88,6 +88,7 @@ class OpenAIEmbeddings(BaseOpenAIEmbeddings):
base_url: Optional[str] = Param(None, help="OpenAI base URL")
organization: Optional[str] = Param(None, help="OpenAI organization")
model: str = Param(
None,
help=(
"ID of the model to use. You can go to [Model overview](https://platform."
"openai.com/docs/models/overview) to see the available models."
Expand Down Expand Up @@ -131,14 +132,16 @@ def openai_response(self, client, **kwargs):

class AzureOpenAIEmbeddings(BaseOpenAIEmbeddings):
azure_endpoint: str = Param(
None,
help=(
"HTTPS endpoint for the Azure OpenAI model. The azure_endpoint, "
"azure_deployment, and api_version parameters are used to construct "
"the full URL for the Azure OpenAI model."
)
),
required=True,
)
azure_deployment: str = Param(help="Azure deployment name", required=True)
api_version: str = Param(help="Azure model version", required=True)
azure_deployment: str = Param(None, help="Azure deployment name", required=True)
api_version: str = Param(None, help="Azure model version", required=True)
azure_ad_token: Optional[str] = Param(None, help="Azure AD token")
azure_ad_token_provider: Optional[str] = Param(None, help="Azure AD token provider")

Expand Down
12 changes: 12 additions & 0 deletions libs/ktem/ktem/llms/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,17 @@ def info(self) -> dict:

def add(self, name: str, spec: dict, default: bool):
"""Add a new model to the pool"""
if not name:
raise ValueError("Name must not be empty")

try:
with Session(engine) as session:

if default:
# turn all models to non-default
session.query(LLMTable).update({"default": False})
session.commit()

item = LLMTable(name=name, spec=spec, default=default)
session.add(item)
session.commit()
Expand All @@ -164,6 +173,9 @@ def delete(self, name: str):

def update(self, name: str, spec: dict, default: bool):
"""Update a model in the pool"""
if not name:
raise ValueError("Name must not be empty")

try:
with Session(engine) as session:

Expand Down
4 changes: 2 additions & 2 deletions libs/ktem/ktem/llms/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def on_register_events(self):
self.create_llm,
inputs=[self.name, self.llm_choices, self.spec, self.default],
outputs=None,
).then(self.list_llms, inputs=None, outputs=[self.llm_list],).then(
).success(self.list_llms, inputs=None, outputs=[self.llm_list]).success(
lambda: ("", None, "", False, self.spec_desc_default),
outputs=[
self.name,
Expand Down Expand Up @@ -229,7 +229,7 @@ def create_llm(self, name, choices, spec, default):
llms.add(name, spec=spec, default=default)
gr.Info(f"LLM {name} created successfully")
except Exception as e:
gr.Error(f"Failed to create LLM {name}: {e}")
raise gr.Error(f"Failed to create LLM {name}: {e}")

def list_llms(self):
"""List the LLMs"""
Expand Down