-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GenAI orchestrator] add reranking embedding and guardrail (#1721)
* versions * ajout guardrail et embedding bloomz * ajout compressor * petites modif * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/guardrail/guardrail_provider.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/contextual_compressor/compressor_setting.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/contextual_compressor/compressor_provider.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/guardrail/guardrail_setting.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/routers/em_providers_router.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/contextual_compressor/bloomz/bloomz_compressor_setting.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/contextual_compressor/bloomz/bloomz_compressor_setting.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/contextual_compressor/bloomz/bloomz_compressor_setting.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/contextual_compressor/bloomz_rerank.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/langchain_factory.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/langchain_factory.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/factories/langchain_factory.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/rag_chain.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/langchain/rag_chain.py Co-authored-by: Diverrez morgan <[email protected]> * modifications pour PR * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/models/guardrail/bloomz/bloomz_guardrail_setting.py Co-authored-by: Diverrez morgan <[email protected]> * Update gen-ai/orchestrator-server/src/main/python/server/src/gen_ai_orchestrator/services/contextual_compressor/bloomz_rerank.py Co-authored-by: assouktim <[email protected]> * Update guardrail error type * Remove dead code * gestion ereur label inconnu * modifications to solve conflicts * 📝 🐛 Fixing severeal stuff and adding documentation about guardrail / compressor (reranking) and embedding using Bloomz * ✏️ IAFMLOPS-516 Review fixes * ✏️ IAFMLOPS-516 Review fixes, missing max_documents * ✏️ IAFMLOPS-516 Peotry lock update --------- Co-authored-by: Diverrez morgan <[email protected]> Co-authored-by: Killian Mahé <[email protected]> Co-authored-by: assouktim <[email protected]> Co-authored-by: Killian Mahé <[email protected]> Co-authored-by: Benjamin BERNARD <[email protected]>
- Loading branch information
1 parent
0cb7765
commit 0c76ae7
Showing
46 changed files
with
2,816 additions
and
1,283 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
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
1,112 changes: 553 additions & 559 deletions
1,112
gen-ai/orchestrator-server/src/main/python/server/poetry.lock
Large diffs are not rendered by default.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
...r/src/main/python/server/src/gen_ai_orchestrator/models/contextual_compressor/__init__.py
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,14 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
14 changes: 14 additions & 0 deletions
14
...ain/python/server/src/gen_ai_orchestrator/models/contextual_compressor/bloomz/__init__.py
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,14 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
48 changes: 48 additions & 0 deletions
48
.../src/gen_ai_orchestrator/models/contextual_compressor/bloomz/bloomz_compressor_setting.py
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,48 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from typing import Literal, Optional | ||
|
||
from pydantic import Field | ||
|
||
from gen_ai_orchestrator.models.contextual_compressor.compressor_provider import ( | ||
ContextualCompressorProvider, | ||
) | ||
from gen_ai_orchestrator.models.contextual_compressor.compressor_setting import ( | ||
BaseCompressorSetting, | ||
) | ||
from gen_ai_orchestrator.services.contextual_compressor.bloomz_rerank import ( | ||
BloomzRerank, | ||
) | ||
|
||
|
||
class BloomzCompressorSetting(BaseCompressorSetting): | ||
provider: Literal[ContextualCompressorProvider.BLOOMZ] = Field( | ||
description='The contextual compressor provider.', | ||
examples=[ContextualCompressorProvider.BLOOMZ], | ||
default=ContextualCompressorProvider.BLOOMZ.value, | ||
) | ||
min_score: Optional[float] = Field( | ||
description='Minimum retailment score.', | ||
default=BloomzRerank.__fields__['min_score'].default, | ||
) | ||
endpoint: str = Field(description='Bloomz scoring endpoint.') | ||
max_documents: Optional[int] = Field( | ||
description='Maximum number of documents to return to avoid exceeding max tokens for text generation.', | ||
default=BloomzRerank.__fields__['max_documents'].default, | ||
) | ||
label: Optional[str] = Field( | ||
description='Label to use for reranking. The output label is usually documented on the huggingface model card ' | ||
'or in the model\'s config.json file (id2label..).', default='entailment' | ||
) |
24 changes: 24 additions & 0 deletions
24
...python/server/src/gen_ai_orchestrator/models/contextual_compressor/compressor_provider.py
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,24 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from enum import Enum, unique | ||
|
||
|
||
@unique | ||
class ContextualCompressorProvider(str, Enum): | ||
BLOOMZ = 'BloomzRerank' | ||
|
||
@classmethod | ||
def has_value(cls, value) -> bool: | ||
return value in cls._value2member_map_ |
26 changes: 26 additions & 0 deletions
26
.../python/server/src/gen_ai_orchestrator/models/contextual_compressor/compressor_setting.py
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,26 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from pydantic import BaseModel, Field | ||
|
||
from gen_ai_orchestrator.models.contextual_compressor.compressor_provider import ( | ||
ContextualCompressorProvider, | ||
) | ||
|
||
|
||
class BaseCompressorSetting(BaseModel): | ||
provider: ContextualCompressorProvider = Field( | ||
description='The contextual compressor provider.', | ||
examples=[ContextualCompressorProvider.BLOOMZ], | ||
) |
25 changes: 25 additions & 0 deletions
25
...in/python/server/src/gen_ai_orchestrator/models/contextual_compressor/compressor_types.py
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,25 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from typing import Annotated, Union | ||
|
||
from fastapi import Body | ||
|
||
from gen_ai_orchestrator.models.contextual_compressor.bloomz.bloomz_compressor_setting import ( | ||
BloomzCompressorSetting, | ||
) | ||
|
||
CompressorSetting = Annotated[ | ||
Union[BloomzCompressorSetting], Body(discriminator='provider') | ||
] |
14 changes: 14 additions & 0 deletions
14
...trator-server/src/main/python/server/src/gen_ai_orchestrator/models/em/bloomz/__init__.py
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,14 @@ | ||
# Copyright (C) 2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
38 changes: 38 additions & 0 deletions
38
...rver/src/main/python/server/src/gen_ai_orchestrator/models/em/bloomz/bloomz_em_setting.py
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,38 @@ | ||
# Copyright (C) 2023-2024 Credit Mutuel Arkea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
"""Model for creating BloomzEMSetting.""" | ||
|
||
from typing import Literal, Optional | ||
|
||
from pydantic import Field | ||
|
||
from gen_ai_orchestrator.models.em.em_provider import EMProvider | ||
from gen_ai_orchestrator.models.em.em_setting import BaseEMSetting | ||
|
||
|
||
class BloomzEMSetting(BaseEMSetting): | ||
"""A class for Bloomz Embedding Model Setting.""" | ||
|
||
provider: Literal[EMProvider.BLOOMZ] = Field( | ||
description='The Embedding Model provider.', examples=[EMProvider.BLOOMZ] | ||
) | ||
api_base: str = Field( | ||
description='The base url of the provider API.', examples=['http://doc.tock.ai'] | ||
) | ||
pooling: Optional[str] = Field( | ||
description='Pooling method.', | ||
default='last', | ||
examples=['mean', 'last'], | ||
) |
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
Oops, something went wrong.