-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/llm bugs empty extraction (#1533)
* Add llm singleton and check for empty extraction * Semver * Tests and spellcheck * Move the singletons to a proper place * Leftover print * Ruff
- Loading branch information
1 parent
f7cd155
commit cfe2082
Showing
4 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "patch", | ||
"description": "Manage llm instances inside a cached singleton. Check for empty dfs after entity/relationship extraction" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. | ||
# Licensed under the MIT License | ||
|
||
"""LLM Manager singleton.""" | ||
|
||
from functools import cache | ||
|
||
from fnllm import ChatLLM, EmbeddingsLLM | ||
|
||
|
||
@cache | ||
class ChatLLMSingleton: | ||
"""A singleton class for the chat LLM instances.""" | ||
|
||
def __init__(self): | ||
self.llm_dict = {} | ||
|
||
def set_llm(self, name, llm): | ||
"""Add an LLM to the dictionary.""" | ||
self.llm_dict[name] = llm | ||
|
||
def get_llm(self, name) -> ChatLLM | None: | ||
"""Get an LLM from the dictionary.""" | ||
return self.llm_dict.get(name) | ||
|
||
|
||
@cache | ||
class EmbeddingsLLMSingleton: | ||
"""A singleton class for the embeddings LLM instances.""" | ||
|
||
def __init__(self): | ||
self.llm_dict = {} | ||
|
||
def set_llm(self, name, llm): | ||
"""Add an LLM to the dictionary.""" | ||
self.llm_dict[name] = llm | ||
|
||
def get_llm(self, name) -> EmbeddingsLLM | None: | ||
"""Get an LLM from the dictionary.""" | ||
return self.llm_dict.get(name) |