diff --git a/src/intelligence_layer/connectors/limited_concurrency_client.py b/src/intelligence_layer/connectors/limited_concurrency_client.py index 00a3b2446..f34aca49e 100644 --- a/src/intelligence_layer/connectors/limited_concurrency_client.py +++ b/src/intelligence_layer/connectors/limited_concurrency_client.py @@ -1,3 +1,4 @@ +from functools import lru_cache from os import getenv from threading import Semaphore from typing import Any, Mapping, Optional, Protocol, Sequence @@ -111,6 +112,7 @@ def __init__( self._concurrency_limit_semaphore = Semaphore(max_concurrency) @classmethod + @lru_cache(maxsize=1) def from_token( cls, token: Optional[str] = None, host: str = "https://api.aleph-alpha.com" ) -> "LimitedConcurrencyClient": diff --git a/src/intelligence_layer/core/__init__.py b/src/intelligence_layer/core/__init__.py index 5626fa9bf..39742bbc5 100644 --- a/src/intelligence_layer/core/__init__.py +++ b/src/intelligence_layer/core/__init__.py @@ -11,9 +11,6 @@ from .complete import Complete as Complete from .complete import CompleteInput as CompleteInput from .complete import CompleteOutput as CompleteOutput -from .complete import Instruct as Instruct -from .complete import InstructInput as InstructInput -from .complete import PromptOutput as PromptOutput from .detect_language import DetectLanguage as DetectLanguage from .detect_language import DetectLanguageInput as DetectLanguageInput from .detect_language import DetectLanguageOutput as DetectLanguageOutput diff --git a/src/intelligence_layer/core/chunk.py b/src/intelligence_layer/core/chunk.py index e84bc759c..7e0b6fdb4 100644 --- a/src/intelligence_layer/core/chunk.py +++ b/src/intelligence_layer/core/chunk.py @@ -6,6 +6,7 @@ from intelligence_layer.connectors.limited_concurrency_client import ( AlephAlphaClientProtocol, ) +from intelligence_layer.core.model import AlephAlphaModel from intelligence_layer.core.task import Task from intelligence_layer.core.tracer import TaskSpan @@ -52,12 +53,9 @@ class ChunkTask(Task[ChunkInput, ChunkOutput]): max_tokens_per_chunk: The maximum number of tokens to fit into one chunk. """ - def __init__( - self, client: AlephAlphaClientProtocol, model: str, max_tokens_per_chunk: int - ): + def __init__(self, model: AlephAlphaModel, max_tokens_per_chunk: int): super().__init__() - tokenizer = client.tokenizer(model) - self._splitter = HuggingFaceTextSplitter(tokenizer) + self._splitter = HuggingFaceTextSplitter(model.get_tokenizer()) self._max_tokens_per_chunk = max_tokens_per_chunk def do_run(self, input: ChunkInput, task_span: TaskSpan) -> ChunkOutput: @@ -84,8 +82,7 @@ class ChunkOverlapTask(Task[ChunkInput, ChunkOutput]): def __init__( self, - client: AlephAlphaClientProtocol, - model: str, + model: AlephAlphaModel, max_tokens_per_chunk: int, overlap_length_tokens: int, ): @@ -96,8 +93,8 @@ def __init__( overlap_length_tokens, max_tokens_per_chunk ) ) - self.chunk_task = ChunkTask(client, model, overlap_length_tokens // 2) - self.tokenizer = client.tokenizer(model) + self.chunk_task = ChunkTask(model, overlap_length_tokens // 2) + self.tokenizer = model.get_tokenizer() self.max_tokens_per_chunk = max_tokens_per_chunk self.overlap_length_tokens = overlap_length_tokens diff --git a/src/intelligence_layer/core/complete.py b/src/intelligence_layer/core/complete.py index 96e232361..6d539d87d 100644 --- a/src/intelligence_layer/core/complete.py +++ b/src/intelligence_layer/core/complete.py @@ -64,244 +64,3 @@ def do_run(self, input: CompleteInput, task_span: TaskSpan) -> CompleteOutput: model=input.model, ) return CompleteOutput(response=response) - - -class InstructInput(BaseModel): - """The input for an `Instruct`. - - Attributes: - instruction: A textual instruction for the model. - Could be a directive to answer a question or to translate something. - input: The text input for the instruction, e.g. a text to be translated. - response_prefix: A string that is provided to the LLM as a prefix of the response. - This can steer the model completion. - maximum_response_tokens: The maximum number of tokens to be generated in the answer. - The default corresponds to roughly one short paragraph. - """ - - instruction: str - input: Optional[str] - response_prefix: str = "" - maximum_response_tokens: int = 64 - - -class PromptOutput(CompleteOutput): - """The output of an `Instruct` or `FewShot` task. - - Attributes: - response: The generated response to the instruction. - rich_prompt: To handle the instruction, a `PromptTemplate` is used. - The template defines two `PromptRange` instances: - - "instruction": covering the instruction text. - - "input": covering the input text. - These can for example be used for downstream `TextHighlight` tasks. - """ - - rich_prompt: RichPrompt - - -class Instruct(Task[InstructInput, PromptOutput]): - """Runs zero-shot instruction completions on a model. - - Can be used for various types of instructions a LLM could handle, like QA, summarization, - translation and more. - - Args: - client: Aleph Alpha client instance for running model related API calls. - model: The name of the model that should handle the instruction. - Certain models are optimized for handling such instruction tasks. - Typically their name contains 'control', e.g. 'luminous-extended-control'. - - Attributes: - INSTRUCTION_PROMPT_TEMPLATE: The prompt-template used to build the actual `Prompt` sent - to the inference API. - - Example: - >>> import os - - >>> from intelligence_layer.connectors import LimitedConcurrencyClient - >>> from intelligence_layer.core import InMemoryTracer, Instruct, InstructInput - - >>> client = LimitedConcurrencyClient.from_token(os.getenv("AA_TOKEN")) - >>> task = Instruct(client, model="luminous-base-control") - >>> input = InstructInput( - ... instruction="Translate the following to text to German.", - ... input="An apple a day keeps the doctor away.", - ... ) - >>> tracer = InMemoryTracer() - >>> output = task.run(input, tracer) - """ - - INSTRUCTION_PROMPT_TEMPLATE = """### Instruction: -{% promptrange instruction %}{{instruction}}{% endpromptrange %} -{% if input %} -### Input: -{% promptrange input %}{{input}}{% endpromptrange %} -{% endif %} -### Response:{{response_prefix}}""" - - def __init__(self, client: AlephAlphaClientProtocol, model: str) -> None: - super().__init__() - self._client = client - self._completion = Complete(client) - self._model = model - - def do_run(self, input: InstructInput, task_span: TaskSpan) -> PromptOutput: - prompt = PromptTemplate(self.INSTRUCTION_PROMPT_TEMPLATE).to_rich_prompt( - input=input.input, - instruction=input.instruction, - response_prefix=input.response_prefix, - ) - response = self._complete( - prompt, - input.maximum_response_tokens, - self._model, - task_span, - ) - return PromptOutput(response=response, rich_prompt=prompt) - - def _complete( - self, prompt: Prompt, maximum_tokens: int, model: str, task_span: TaskSpan - ) -> CompletionResponse: - request = CompletionRequest(prompt, maximum_tokens=maximum_tokens) - return self._completion.run( - CompleteInput(request=request, model=model), - task_span, - ).response - - -class FewShotExample(BaseModel): - input: str - response: str - - -class FewShotConfig(BaseModel): - """Config for a few-shot prompt without dynamic input. - - Attributes: - instruction: A textual instruction for the model. - Could be a directive to answer a question or to translate something. - examples: A number of few shot examples to prime the model. - input_prefix: The prefix for each `FewShotExample.input` as well as the final input. - response_prefix: The prefix for each `FewShotExample.response` as well as the completion. - """ - - instruction: str - examples: Sequence[FewShotExample] - input_prefix: str - response_prefix: str - additional_stop_sequences: Sequence[str] = Field(default_factory=list) - - -class FewShotInput(BaseModel): - """The input for a `FewShot` task. - - Attributes: - few_shot_config: The configuration to be used for generating a response. - input: The text input for the prompt, e.g. a text to be translated. - maximum_response_tokens: The maximum number of tokens to be generated in the answer. - The default corresponds to roughly one short paragraph. - """ - - few_shot_config: FewShotConfig - input: str - maximum_response_tokens: int = 64 - - -class FewShot(Task[FewShotInput, PromptOutput]): - """Runs few-shot completions on a model. - - Vanilla models work best with a show-don't-tell approach. Few-shot prompts illustrate - the output that is expected from the model. - - Args: - client: Aleph Alpha client instance for running model related API calls. - model: The name of the model that should handle the prompt. - Vanilla models work best with few-shot promptung. - These include 'luminous-base', 'extended' & 'supreme'. - - Attributes: - FEW_SHOT_PROMPT_TEMPLATE: The prompt-template used to build the actual `Prompt` sent - to the inference API. - - Example: - >>> import os - - >>> from intelligence_layer.connectors import LimitedConcurrencyClient - >>> from intelligence_layer.core import ( - ... FewShot, - ... FewShotConfig, - ... FewShotExample, - ... FewShotInput, - ... InMemoryTracer, - ... ) - - >>> client = LimitedConcurrencyClient.from_token(os.getenv("AA_TOKEN")) - >>> task = FewShot(client) - >>> input = FewShotInput( - ... input="What is the capital of Germany?", - ... model="luminous-base", - ... few_shot_config=FewShotConfig( - ... instruction="Answer each question.", - ... examples=[ - ... FewShotExample(input="How high is Mount Everest?", response="8848 metres."), - ... FewShotExample(input="When was Caesar killed?", response="44 AD."), - ... ], - ... input_prefix="Question", - ... response_prefix="Answer", - ... model="luminous-base", - ... ), - ... ) - >>> output = task.run(input, InMemoryTracer()) - """ - - FEW_SHOT_PROMPT_TEMPLATE = """{% promptrange instruction %}{{instruction}} -{% for example in few_shot_examples %}### -{{input_prefix}}: {{ example.input }} -{{response_prefix}}: {{ example.response }} -{% endfor %}{% endpromptrange %}### -{{input_prefix}}: {% promptrange input %}{{input}}{% endpromptrange %} -{{response_prefix}}:""" - - def __init__(self, client: AlephAlphaClientProtocol, model: str) -> None: - super().__init__() - self._client = client - self._completion = Complete(client) - self._model = model - - def do_run(self, input: FewShotInput, task_span: TaskSpan) -> PromptOutput: - prompt = PromptTemplate(self.FEW_SHOT_PROMPT_TEMPLATE).to_rich_prompt( - instruction=input.few_shot_config.instruction, - input=input.input, - few_shot_examples=[ - e.model_dump() for e in input.few_shot_config.examples - ], # liquid can't handle classes, thus serializing - input_prefix=input.few_shot_config.input_prefix, - response_prefix=input.few_shot_config.response_prefix, - ) - response = self._complete( - prompt, - input.maximum_response_tokens, - input.few_shot_config.additional_stop_sequences, - self._model, - task_span, - ) - return PromptOutput(response=response, rich_prompt=prompt) - - def _complete( - self, - prompt: Prompt, - maximum_tokens: int, - additional_stop_sequences: Sequence[str], - model: str, - task_span: TaskSpan, - ) -> CompletionResponse: - request = CompletionRequest( - prompt, - maximum_tokens=maximum_tokens, - stop_sequences=["###"] + list(additional_stop_sequences), - ) - return self._completion.run( - CompleteInput(request=request, model=model), - task_span, - ).response diff --git a/src/intelligence_layer/core/echo.py b/src/intelligence_layer/core/echo.py index 1035cc634..34ea62135 100644 --- a/src/intelligence_layer/core/echo.py +++ b/src/intelligence_layer/core/echo.py @@ -8,7 +8,6 @@ from intelligence_layer.connectors.limited_concurrency_client import ( AlephAlphaClientProtocol, ) -from intelligence_layer.core.complete import Complete, CompleteInput from intelligence_layer.core.prompt_template import PromptTemplate from intelligence_layer.core.task import Task, Token from intelligence_layer.core.tracer import TaskSpan diff --git a/src/intelligence_layer/core/explain.py b/src/intelligence_layer/core/explain.py index 401d4b2e2..94ada1fe4 100644 --- a/src/intelligence_layer/core/explain.py +++ b/src/intelligence_layer/core/explain.py @@ -4,6 +4,7 @@ from intelligence_layer.connectors.limited_concurrency_client import ( AlephAlphaClientProtocol, ) +from intelligence_layer.core.model import AlephAlphaModel from intelligence_layer.core.task import Task from intelligence_layer.core.tracer import TaskSpan @@ -18,7 +19,6 @@ class ExplainInput(BaseModel): """ request: ExplanationRequest - model: str class ExplainOutput(BaseModel): @@ -42,10 +42,10 @@ class Explain(Task[ExplainInput, ExplainOutput]): client: Aleph Alpha client instance for running model related API calls. """ - def __init__(self, client: AlephAlphaClientProtocol) -> None: + def __init__(self, model: AlephAlphaModel) -> None: super().__init__() - self._client = client + self._model = model def do_run(self, input: ExplainInput, task_span: TaskSpan) -> ExplainOutput: - response = self._client.explain(input.request, input.model) + response = self._model._client.explain(input.request, self._model.name) return ExplainOutput(response=response) diff --git a/src/intelligence_layer/core/model.py b/src/intelligence_layer/core/model.py index b68a2e04a..f53d981df 100644 --- a/src/intelligence_layer/core/model.py +++ b/src/intelligence_layer/core/model.py @@ -1,47 +1,46 @@ from abc import ABC, abstractmethod +from dataclasses import asdict from functools import lru_cache -from typing import Optional +from typing import Literal, Optional from aleph_alpha_client import CompletionRequest, CompletionResponse -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from tokenizers import Encoding, Tokenizer # type: ignore from intelligence_layer.connectors.limited_concurrency_client import ( AlephAlphaClientProtocol, + LimitedConcurrencyClient, ) from intelligence_layer.core.prompt_template import PromptTemplate, RichPrompt from intelligence_layer.core.task import Task from intelligence_layer.core.tracer import TaskSpan, Tracer -class CompleteInput(BaseModel): - """The input for a `Complete` task. +class CompleteInput(BaseModel, CompletionRequest, frozen=True): + """The input for a `Complete` task.""" - Attributes: - request: Aleph Alpha `Client`'s `CompletionRequest`. This gives fine grained control - over all completion parameters that are supported by Aleph Alpha's inference API. - """ - - request: CompletionRequest + pass -class CompleteOutput(BaseModel): - """The output of a `Complete` task. +class CompleteOutput(BaseModel, CompletionResponse, frozen=True): + """The output of a `Complete` task.""" - Attributes: - response: Aleph Alpha `Client`'s `CompletionResponse` containing all details - provided by Aleph Alpha's inference API. - """ + # Base model protects namespace model_ but this is a field in the completion response + model_config = ConfigDict(protected_namespaces=()) - response: CompletionResponse + @staticmethod + def from_completion_response( + completion_response: CompletionResponse, + ) -> "CompleteOutput": + return CompleteOutput(**asdict(completion_response)) @property def completion(self) -> str: - return self.response.completions[0].completion or "" + return self.completions[0].completion or "" @property def generated_tokens(self) -> int: - return self.response.num_tokens_generated + return self.num_tokens_generated class _Complete(Task[CompleteInput, CompleteOutput]): @@ -61,18 +60,23 @@ def __init__(self, client: AlephAlphaClientProtocol, model: str) -> None: self._model = model def do_run(self, input: CompleteInput, task_span: TaskSpan) -> CompleteOutput: - response = self._client.complete( - input.request, - model=self._model, + return CompleteOutput.from_completion_response( + self._client.complete( + request=input, + model=self._model, + ) ) - return CompleteOutput(response=response) class AlephAlphaModel(ABC): - def __init__(self, model: str, client: AlephAlphaClientProtocol) -> None: + def __init__( + self, + model_name: str, + client: AlephAlphaClientProtocol = LimitedConcurrencyClient.from_token(), + ) -> None: self._client = client - self._complete = _Complete(self._client, model) - self._model = model + self._complete = _Complete(self._client, model_name) + self.name = model_name def get_complete_task(self) -> Task[CompleteInput, CompleteOutput]: return self._complete @@ -90,14 +94,14 @@ def to_instruct_prompt( ... @lru_cache(maxsize=1) - def _get_tokenizer(self) -> Tokenizer: - return self._client.tokenizer(self._model) + def get_tokenizer(self) -> Tokenizer: + return self._client.tokenizer(self.name) def tokenize(self, text: str) -> Encoding: - return self._get_tokenizer().encode(text) + return self.get_tokenizer().encode(text) -class ControlModel(AlephAlphaModel): +class LuminousControlModel(AlephAlphaModel): INSTRUCTION_PROMPT_TEMPLATE = PromptTemplate( """{% promptrange instruction %}{{instruction}}{% endpromptrange %} {% if input %} @@ -106,6 +110,20 @@ class ControlModel(AlephAlphaModel): ### Response:{{response_prefix}}""" ) + def __init__( + self, + model: Literal[ + "luminous-base-control", + "luminous-extended-control", + "luminous-supreme-control", + "luminous-base-control-20240215", + "luminous-extended-control-20240215", + "luminous-supreme-control-20240215", + ], + client: AlephAlphaClientProtocol = LimitedConcurrencyClient.from_token(), + ) -> None: + super().__init__(model, client) + def to_instruct_prompt( self, instruction: str, diff --git a/src/intelligence_layer/core/text_highlight.py b/src/intelligence_layer/core/text_highlight.py index c2dfdd96c..f35bb4cb2 100644 --- a/src/intelligence_layer/core/text_highlight.py +++ b/src/intelligence_layer/core/text_highlight.py @@ -13,8 +13,10 @@ from intelligence_layer.connectors.limited_concurrency_client import ( AlephAlphaClientProtocol, + LimitedConcurrencyClient, ) from intelligence_layer.core.explain import Explain, ExplainInput +from intelligence_layer.core.model import AlephAlphaModel from intelligence_layer.core.prompt_template import ( Cursor, PromptRange, @@ -32,7 +34,6 @@ class TextHighlightInput(BaseModel): rich_prompt: From client's PromptTemplate. Includes both the actual 'Prompt' as well as text range information. Supports liquid-template-language-style {% promptrange range_name %}/{% endpromptrange %} for range. target: The target that should be explained. Expected to follow the prompt. - model: A valid Aleph Alpha model name. focus_ranges: The ranges contained in `rich_prompt` the returned highlights stem from. That means that each returned highlight overlaps with at least one character with one of the ranges listed here. If this set is empty highlights of the entire prompt are returned. @@ -40,7 +41,6 @@ class TextHighlightInput(BaseModel): rich_prompt: RichPrompt target: str - model: str focus_ranges: frozenset[str] = frozenset() @@ -104,12 +104,12 @@ class TextHighlight(Task[TextHighlightInput, TextHighlightOutput]): def __init__( self, - client: AlephAlphaClientProtocol, + model: AlephAlphaModel, granularity: PromptGranularity = PromptGranularity.Sentence, ) -> None: super().__init__() - self._client = client - self._explain_task = Explain(client) + self._model = model + self._explain_task = Explain(model) self._granularity = granularity def do_run( @@ -119,7 +119,6 @@ def do_run( explanation = self._explain( prompt=input.rich_prompt, target=input.target, - model=input.model, task_span=task_span, ) prompt_ranges = self._flatten_prompt_ranges( @@ -145,16 +144,14 @@ def _raise_on_invalid_focus_range(self, input: TextHighlightInput) -> None: raise ValueError(f"Unknown focus ranges: {', '.join(unknown_focus_ranges)}") def _explain( - self, prompt: Prompt, target: str, model: str, task_span: TaskSpan + self, prompt: Prompt, target: str, task_span: TaskSpan ) -> ExplanationResponse: request = ExplanationRequest( prompt, target, prompt_granularity=self._granularity, ) - output = self._explain_task.run( - ExplainInput(request=request, model=model), task_span - ) + output = self._explain_task.run(ExplainInput(request=request), task_span) return output.response def _flatten_prompt_ranges( diff --git a/src/intelligence_layer/evaluation/instruct_comparison_argilla_evaluator.py b/src/intelligence_layer/evaluation/instruct_comparison_argilla_evaluator.py index 05174d07b..8990359fb 100644 --- a/src/intelligence_layer/evaluation/instruct_comparison_argilla_evaluator.py +++ b/src/intelligence_layer/evaluation/instruct_comparison_argilla_evaluator.py @@ -10,7 +10,6 @@ Question, RecordData, ) -from intelligence_layer.core.complete import InstructInput, PromptOutput from intelligence_layer.evaluation import ( ArgillaEvaluationRepository, DatasetRepository, diff --git a/src/intelligence_layer/use_cases/__init__.py b/src/intelligence_layer/use_cases/__init__.py index 0e4bffe61..ca323ba2d 100644 --- a/src/intelligence_layer/use_cases/__init__.py +++ b/src/intelligence_layer/use_cases/__init__.py @@ -46,34 +46,29 @@ from .qa.single_chunk_qa import SingleChunkQaOutput as SingleChunkQaOutput from .search.search import Search as Search from .search.search import SearchInput as SearchInput -from .summarize.long_context_few_shot_summarize import ( - LongContextFewShotSummarize as LongContextFewShotSummarize, -) -from .summarize.long_context_high_compression_summarize import ( - LongContextHighCompressionSummarize as LongContextHighCompressionSummarize, -) -from .summarize.long_context_low_compression_summarize import ( - LongContextLowCompressionSummarize as LongContextLowCompressionSummarize, -) -from .summarize.long_context_medium_compression_summarize import ( - LongContextMediumCompressionSummarize as LongContextMediumCompressionSummarize, -) from .summarize.recursive_summarize import RecursiveSummarize as RecursiveSummarize -from .summarize.single_chunk_few_shot_summarize import ( - SingleChunkFewShotSummarize as SingleChunkFewShotSummarize, -) from .summarize.steerable_long_context_summarize import ( SteerableLongContextSummarize as SteerableLongContextSummarize, ) from .summarize.steerable_single_chunk_summarize import ( SteerableSingleChunkSummarize as SteerableSingleChunkSummarize, ) +from .summarize.summarize import ( + AggregatedSummarizeEvaluation as AggregatedSummarizeEvaluation, +) +from .summarize.summarize import ( + LongContextSummarizeEvaluator as LongContextSummarizeEvaluator, +) from .summarize.summarize import LongContextSummarizeInput as LongContextSummarizeInput from .summarize.summarize import ( LongContextSummarizeOutput as LongContextSummarizeOutput, ) from .summarize.summarize import PartialSummary as PartialSummary +from .summarize.summarize import ( + SingleChunkSummarizeEvaluator as SingleChunkSummarizeEvaluator, +) from .summarize.summarize import SingleChunkSummarizeInput as SingleChunkSummarizeInput +from .summarize.summarize import SummarizeEvaluation as SummarizeEvaluation from .summarize.summarize import SummarizeOutput as SummarizeOutput __all__ = [symbol for symbol in dir() if symbol and symbol[0].isupper()] diff --git a/src/intelligence_layer/use_cases/classify/keyword_extract.py b/src/intelligence_layer/use_cases/classify/keyword_extract.py index b301e6ab6..ff33bfcdf 100644 --- a/src/intelligence_layer/use_cases/classify/keyword_extract.py +++ b/src/intelligence_layer/use_cases/classify/keyword_extract.py @@ -2,136 +2,32 @@ from pydantic import BaseModel -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) from intelligence_layer.core.chunk import Chunk -from intelligence_layer.core.complete import ( - FewShot, - FewShotConfig, - FewShotExample, - FewShotInput, -) from intelligence_layer.core.detect_language import Language, language_config +from intelligence_layer.core.model import ( + AlephAlphaModel, + CompleteInput, + LuminousControlModel, +) from intelligence_layer.core.task import Task -from intelligence_layer.core.tracer import TaskSpan +from intelligence_layer.core.tracer import NoOpTracer, TaskSpan -FEW_SHOT_CONFIGS = { - Language("de"): FewShotConfig( - instruction="Erkenne das Thema des Texts.", - examples=[ - FewShotExample( - input="Das Gruppenspiel der deutschen Nationalmannschaft gegen Costa Rica hat in Deutschland die bislang höchste TV-Zuschauerzahl erreicht. Den bisherigen Einschaltquoten-Rekord der DFB-Frauen bei der EM 2022 gegen England knackten die Männer allerdings nicht.", - response="Fußball, Fernsehen, Nationalmannschaft", - ), - FewShotExample( - input="Machine Learning und Deep Learning sind nicht immer die beste Wahl um ein Vorhersageproblem zu lösen. Oft mal kann ein simples lineares Modell schon ausreichen.", - response="KI, Technolgie, Machine Learning", - ), - FewShotExample( - input='Das Restaurant hat fünf Köche und sechs Servicekräfte, braucht aber ein oder zwei weitere Köche und zwei weitere Servicekräfte. Es ist nicht das einzige Restaurant, das von einer "existenziellen Bedrohung" für das Gastgewerbe betroffen ist.', - response="Restaurant, Personalmangel, Gastgewerbe", - ), - FewShotExample( - input="Es ist das natürliche Verhalten von Tieren, ihren Instinkten zu folgen. So gehen sie beispielsweise auf die Jagd obwohl sie nicht mal Hunger haben.", - response="Biologie, Natur, Tiere", - ), - ], - input_prefix="Text", - response_prefix="Thema", - ), - Language("en"): FewShotConfig( - instruction="Identify the theme of the text.", - examples=[ - FewShotExample( - input="The German national team's group match against Costa Rica achieved the highest TV viewership to date in Germany. However, the men did not break the previous ratings record set by the DFB women against England at the 2022 European Championship.", - response="soccer, television, national team", - ), - FewShotExample( - input="Machine learning and deep learning are not always the best choice to solve a prediction problem. Often times, a simple linear model can suffice.", - response="AI, Technology, Machine Learning", - ), - FewShotExample( - input='The restaurant has five cooks and six servers, but needs one or two more cooks and two more servers. It\'s not the only restaurant facing an "existential threat" to the hospitality industry.', - response="restaurant, staff shortage, hospitality industry", - ), - FewShotExample( - input="It is the natural behavior of animals to follow their instincts. For example, they go hunting even though they are not even hungry.", - response="Biology, Nature, Animals", - ), - ], - input_prefix="Text", - response_prefix="Topic", - ), - Language("es"): FewShotConfig( - instruction="Identificar el tema del texto.", - examples=[ - FewShotExample( - input="El partido de grupo de la selección alemana contra Costa Rica ha alcanzado la mayor audiencia televisiva en Alemania hasta la fecha. Sin embargo, los hombres no batieron el anterior récord de audiencia establecido por las mujeres de la DFB contra Inglaterra en la Eurocopa de 2022.", - response="Fútbol, Televisión, Selección Nacional", - ), - FewShotExample( - input="El aprendizaje automático y el aprendizaje profundo no siempre son la mejor opción para resolver un problema de predicción. A menudo basta con un modelo lineal simple.", - response="IA, Tecnología, Aprendizaje automático", - ), - FewShotExample( - input='El restaurante tiene cinco cocineros y seis camareros, pero necesita uno o dos cocineros y dos camareros más. No es el único restaurante afectado por una "amenaza existencial" para la hostelería.', - response="restaurante, escasez de personal, hostelería", - ), - FewShotExample( - input="El comportamiento natural de los animales es seguir sus instintos. Por ejemplo, salen a cazar aunque ni siquiera tengan hambre.", - response="Biología, Naturaleza, Animales", - ), - ], - input_prefix="Texto", - response_prefix="Tema", - ), - Language("fr"): FewShotConfig( - instruction="Identifie le thème du texte.", - examples=[ - FewShotExample( - input="Le match de groupe de l'équipe nationale allemande contre le Costa Rica a atteint en Allemagne le plus grand nombre de téléspectateurs à ce jour. Les hommes n'ont toutefois pas battu le record d'audience détenu jusqu'à présent par les femmes de la DFB lors de l'Euro 2022 contre l'Angleterre.", - response="Football, Télévision, Équipe nationale", - ), - FewShotExample( - input="Le Machine Learning et le Deep Learning ne sont pas toujours le meilleur choix pour résoudre un problème de prédiction. Souvent, un simple modèle linéaire peut suffire.", - response="IA, Technologie, Machine Learning", - ), - FewShotExample( - input="Le restaurant compte cinq cuisiniers et six serveurs, mais il a besoin d'un ou deux cuisiniers et de deux serveurs supplémentaires. Ce n'est pas le seul restaurant touché par une \"menace existentielle\" pour le secteur de la restauration.", - response="restaurant, manque de personnel, hôtellerie et restauration", - ), - FewShotExample( - input="C'est le comportement naturel des animaux de suivre leurs instincts. Ils partent par exemple à la chasse alors qu'ils n'ont même pas faim.", - response="Biologie, Nature, Animaux", - ), - ], - input_prefix="Texte", - response_prefix="Thème", - ), - Language("it"): FewShotConfig( - instruction="Identificare il tema del testo.", - examples=[ - FewShotExample( - input="La partita di girone della nazionale tedesca contro la Costa Rica ha raggiunto il più alto numero di spettatori televisivi in Germania fino ad ora. Tuttavia, gli uomini non hanno superato il precedente record di valutazione stabilito dalle donne della DFB contro l'Inghilterra agli Europei del 2022.", - response="Calcio, Televisione, Squadra nazionale", - ), - FewShotExample( - input="L'apprendimento automatico e l'apprendimento profondo non sono sempre la scelta migliore per risolvere un problema di previsione. Spesso può bastare un semplice modello lineare.", - response="AI, Tecnologia, Apprendimento automatico", - ), - FewShotExample( - input="Il ristorante ha cinque cuochi e sei camerieri, ma ha bisogno di uno o due cuochi e due camerieri in più. Non è l'unico ristorante colpito da una \"minaccia esistenziale\" per l'industria dell'ospitalità.", - response="ristorante, carenza di personale, industria dell'ospitalità", - ), - FewShotExample( - input="Seguire l'istinto è il comportamento naturale degli animali. Per esempio, vanno a caccia anche se non hanno nemmeno fame.", - response="Biologia, Natura, Animali", - ), - ], - input_prefix="Testo", - response_prefix="Argomento", - ), +INSTRUCT_CONFIGS = { + Language( + "de" + ): "Worum geht es in dem Text? Extrahiere ein paar Stichwörter in Form einer Komma-separierten Liste.", + Language( + "en" + ): "What is the text about? Extract a few keywords in form of a comma-separated list.", + Language( + "es" + ): "¿De qué trata el texto? Extrae algunas palabras clave en forma de una lista separada por comas.", + Language( + "fr" + ): "De quoi parle le texte? Extraire quelques mots-clés sous forme d'une liste séparée par des virgules.", + Language( + "it" + ): "Di cosa tratta il testo? Estrai alcune parole chiave sotto forma di una lista separata da virgole.", } @@ -147,25 +43,24 @@ class KeywordExtractOutput(BaseModel): class KeywordExtract(Task[KeywordExtractInput, KeywordExtractOutput]): def __init__( self, - client: AlephAlphaClientProtocol, - few_shot_configs: Mapping[Language, FewShotConfig] = FEW_SHOT_CONFIGS, - model: str = "luminous-base", + model: AlephAlphaModel = LuminousControlModel("luminous-base-control-20240215"), + instruct_configs: Mapping[Language, str] = INSTRUCT_CONFIGS, maximum_tokens: int = 32, ) -> None: - self._few_shot_configs = few_shot_configs - self._few_shot = FewShot(client, model) + self._instruct_configs = instruct_configs self._model = model self._maximum_tokens = maximum_tokens def do_run( self, input: KeywordExtractInput, task_span: TaskSpan ) -> KeywordExtractOutput: - config = language_config(input.language, self._few_shot_configs) - result = self._few_shot.run( - FewShotInput( - few_shot_config=config, - input=input.chunk, - maximum_response_tokens=self._maximum_tokens, + instruction = language_config(input.language, self._instruct_configs) + result = self._model.complete( + CompleteInput( + prompt=self._model.to_instruct_prompt( + instruction=instruction, input=str(input.chunk) + ), + maximum_tokens=self._maximum_tokens, ), task_span, ) diff --git a/src/intelligence_layer/use_cases/intelligence_starter_app.py b/src/intelligence_layer/use_cases/intelligence_starter_app.py index f245a8908..e5507beba 100644 --- a/src/intelligence_layer/use_cases/intelligence_starter_app.py +++ b/src/intelligence_layer/use_cases/intelligence_starter_app.py @@ -17,8 +17,8 @@ LongContextQa, LongContextQaInput, ) -from intelligence_layer.use_cases.summarize.long_context_high_compression_summarize import ( - LongContextHighCompressionSummarize, +from intelligence_layer.use_cases.summarize.steerable_long_context_summarize import ( + SteerableLongContextSummarize, ) from intelligence_layer.use_cases.summarize.summarize import LongContextSummarizeInput @@ -30,7 +30,9 @@ def __init__(self, fast_api_app: FastAPI, client: AlephAlphaClientProtocol) -> N self.register_task(prompt_based_classify, ClassifyInput, "/classify") long_chunk_qa = LongContextQa(client) self.register_task(long_chunk_qa, LongContextQaInput, "/qa") - summarize = LongContextHighCompressionSummarize(client) + summarize = SteerableLongContextSummarize( + client, max_generated_tokens=128, max_tokens_per_chunk=512 + ) self.register_task(summarize, LongContextSummarizeInput, "/summarize") diff --git a/src/intelligence_layer/use_cases/qa/long_context_qa.py b/src/intelligence_layer/use_cases/qa/long_context_qa.py index 2df554ee2..b3b3bc952 100644 --- a/src/intelligence_layer/use_cases/qa/long_context_qa.py +++ b/src/intelligence_layer/use_cases/qa/long_context_qa.py @@ -9,6 +9,7 @@ ) from intelligence_layer.core.chunk import Chunk, ChunkInput, ChunkTask from intelligence_layer.core.detect_language import DetectLanguage, Language +from intelligence_layer.core.model import AlephAlphaModel, LuminousControlModel from intelligence_layer.core.task import Task from intelligence_layer.core.tracer import TaskSpan from intelligence_layer.use_cases.qa.multiple_chunk_qa import ( @@ -71,16 +72,16 @@ class LongContextQa(Task[LongContextQaInput, MultipleChunkQaOutput]): def __init__( self, - client: AlephAlphaClientProtocol, max_tokens_per_chunk: int = 512, k: int = 4, - model: str = "luminous-supreme-control", + model: AlephAlphaModel = LuminousControlModel( + "luminous-supreme-control-20240215" + ), ): super().__init__() - self._client = client self._model = model - self._chunk_task = ChunkTask(client, model, max_tokens_per_chunk) - self._multi_chunk_qa = MultipleChunkQa(self._client, self._model) + self._chunk_task = ChunkTask(model, max_tokens_per_chunk) + self._multi_chunk_qa = MultipleChunkQa(model) self._k = k self._language_detector = DetectLanguage(threshold=0.5) @@ -89,7 +90,7 @@ def do_run( ) -> MultipleChunkQaOutput: chunk_output = self._chunk_task.run(ChunkInput(text=input.text), task_span) retriever = QdrantInMemoryRetriever( - self._client, + self._model._client, documents=[ Document( text=c, diff --git a/src/intelligence_layer/use_cases/qa/multiple_chunk_qa.py b/src/intelligence_layer/use_cases/qa/multiple_chunk_qa.py index 306c2d836..85dccc792 100644 --- a/src/intelligence_layer/use_cases/qa/multiple_chunk_qa.py +++ b/src/intelligence_layer/use_cases/qa/multiple_chunk_qa.py @@ -6,8 +6,13 @@ AlephAlphaClientProtocol, ) from intelligence_layer.core.chunk import Chunk -from intelligence_layer.core.complete import Instruct, InstructInput, PromptOutput from intelligence_layer.core.detect_language import Language, language_config +from intelligence_layer.core.model import ( + AlephAlphaModel, + CompleteInput, + CompleteOutput, + LuminousControlModel, +) from intelligence_layer.core.task import Task from intelligence_layer.core.tracer import TaskSpan from intelligence_layer.use_cases.qa.single_chunk_qa import ( @@ -64,51 +69,40 @@ class MergeAnswersInstructConfig(BaseModel): question_label: str answers_label: str final_answer_label: str + maximum_tokens: int = 128 MERGE_ANSWERS_INSTRUCT_CONFIGS = { Language("en"): MergeAnswersInstructConfig( - instruction="You will be given a number of Answers to a Question. Based on them, generate a single final answer. " - "Condense multiple answers into a single answer. Rely only on the provided answers. Don't use the world's knowledge. " - "The answer should combine the individual answers. If the answers contradict each other, e.g., one saying that the colour is green " - "and the other saying that the colour is black, say that there are contradicting answers saying the colour is green or the colour is black.", + instruction="You are tasked with combining multiple answers into a single answer. " + "If conflicting answers arise, acknowledge the discrepancies by presenting them collectively", question_label="Question", answers_label="Answers", final_answer_label="Final answer:", ), Language("it"): MergeAnswersInstructConfig( - instruction="Vi verranno fornite diverse risposte a una domanda. Sulla base di queste, generate una singola risposta finale. " - "Riunire più risposte in un'unica risposta. Basatevi solo sulle risposte fornite. Non utilizzate le conoscenze del mondo. " - "La risposta deve combinare le singole risposte. Se le risposte si contraddicono, ad esempio una dice che il colore è verde e " - "l'altra dice che il colore è nero, dire che ci sono risposte contraddittorie che dicono che il colore è verde o che il colore è nero.", + instruction="Il compito è quello di combinare più risposte in un'unica risposta. " + "Se emergono risposte contrastanti, riconoscete le discrepanze presentandole collettivamente.", question_label="Domanda", answers_label="Risposte", final_answer_label="Risposta finale:", ), Language("fr"): MergeAnswersInstructConfig( - instruction="Vous recevrez un certain nombre de réponses à une question. Sur la base de ces réponses, générez une seule réponse finale. " - "Condenser plusieurs réponses en une seule. Ne vous fiez qu'aux réponses fournies. N'utilisez pas les connaissances du monde entier. " - "La réponse doit combiner les différentes réponses. Si les réponses se contredisent, par exemple si l'une dit que la couleur est verte et " - "l'autre que la couleur est noire, dites qu'il y a des réponses contradictoires disant que la couleur est verte ou que la couleur est noire.", + instruction="Vous devez combiner plusieurs réponses en une seule. " + "Si des réponses contradictoires apparaissent, reconnaissez les divergences en les présentant collectivement", question_label="Question", answers_label="Réponses", final_answer_label="Réponse finale:", ), Language("de"): MergeAnswersInstructConfig( - instruction="Sie erhalten eine Reihe von Antworten auf eine Frage. Erstellen Sie auf dieser Grundlage eine einzige endgültige Antwort. " - "Fassen Sie mehrere Antworten zu einer einzigen Antwort zusammen. Verlassen Sie sich nur auf die vorgegebenen Antworten. " - "Verwenden Sie nicht das Wissen der Welt. Die Antwort sollte die einzelnen Antworten kombinieren. Wenn sich die Antworten widersprechen, " - "z. B. wenn eine Antwort besagt, dass die Farbe grün ist, und die andere, dass die Farbe schwarz ist, sagen Sie, " - "dass es widersprüchliche Antworten gibt, die besagen, dass die Farbe grün oder die Farbe schwarz ist.", + instruction="Fasse alle Antworten zu einer einzigen Antwort zusammen. Falls es Widersprüche gibt, präsentiere diese.", question_label="Frage", answers_label="Antworten", final_answer_label="Endgültige Antwort:", ), Language("es"): MergeAnswersInstructConfig( - instruction="Se le darán varias respuestas a una pregunta. A partir de ellas, genere una única respuesta final. " - "Condensar varias respuestas en una sola. Apóyate únicamente en las respuestas proporcionadas. No utilice el conocimiento del mundo. " - "La respuesta debe combinar las respuestas individuales. Si las respuestas se contradicen, por ejemplo, una dice que el color es verde " - "y la otra que el color es negro, di que hay respuestas contradictorias que dicen que el color es verde o que el color es negro.", + instruction="Su tarea consiste en combinar varias respuestas en una sola. " + "Si surgen respuestas contradictorias, reconozca las discrepancias presentándolas colectivamente", question_label="Pregunta", answers_label="Respuestas", final_answer_label="Respuesta final:", @@ -162,25 +156,19 @@ class MultipleChunkQa(Task[MultipleChunkQaInput, MultipleChunkQaOutput]): Mike likes pizza. """ - MERGE_ANSWERS_INSTRUCTION = """You will be given a number of Answers to a Question. Based on them, generate a single final answer. -Condense multiple answers into a single answer. Rely only on the provided answers. Don't use the world's knowledge. The answer should combine the individual answers. If the answers contradict each other, e.g., one saying that the colour is green and the other saying that the colour is black, say that there are contradicting answers saying the colour is green or the colour is black.""" - def __init__( self, - client: AlephAlphaClientProtocol, - model: str = "luminous-supreme-control", - merge_answers_instruct_configs: Optional[ - Mapping[Language, MergeAnswersInstructConfig] - ] = None, + model: AlephAlphaModel = LuminousControlModel( + "luminous-supreme-control-20240215" + ), + merge_answers_instruct_configs: Mapping[ + Language, MergeAnswersInstructConfig + ] = MERGE_ANSWERS_INSTRUCT_CONFIGS, ): super().__init__() - self._client = client - self._instruction = Instruct(client, model) - self._single_chunk_qa = SingleChunkQa(client, model) + self._single_chunk_qa = SingleChunkQa(model) self._model = model - self._merge_answers_instruct_configs = ( - merge_answers_instruct_configs or MERGE_ANSWERS_INSTRUCT_CONFIGS - ) + self._merge_answers_instruct_configs = merge_answers_instruct_configs def do_run( self, input: MultipleChunkQaInput, task_span: TaskSpan @@ -243,12 +231,15 @@ def _instruct( input: str, instruction_config: MergeAnswersInstructConfig, task_span: TaskSpan, - ) -> PromptOutput: - return self._instruction.run( - InstructInput( - instruction=instruction_config.instruction, - input=input, - response_prefix=f"\n{instruction_config.final_answer_label}", + ) -> CompleteOutput: + prompt = self._model.to_instruct_prompt( + instruction_config.instruction, + input=input, + response_prefix=f" {instruction_config.final_answer_label}", + ) + return self._model.complete( + CompleteInput( + prompt=prompt, maximum_tokens=instruction_config.maximum_tokens ), task_span, ) diff --git a/src/intelligence_layer/use_cases/qa/single_chunk_qa.py b/src/intelligence_layer/use_cases/qa/single_chunk_qa.py index 55e9142c3..f1718930e 100644 --- a/src/intelligence_layer/use_cases/qa/single_chunk_qa.py +++ b/src/intelligence_layer/use_cases/qa/single_chunk_qa.py @@ -3,37 +3,48 @@ from liquid import Template from pydantic import BaseModel -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) from intelligence_layer.core.chunk import Chunk -from intelligence_layer.core.complete import Instruct, InstructInput, PromptOutput from intelligence_layer.core.detect_language import Language, language_config +from intelligence_layer.core.model import ( + AlephAlphaModel, + CompleteInput, + CompleteOutput, + LuminousControlModel, +) from intelligence_layer.core.prompt_template import RichPrompt from intelligence_layer.core.task import Task from intelligence_layer.core.text_highlight import TextHighlight, TextHighlightInput from intelligence_layer.core.tracer import TaskSpan + +class QaSetup(BaseModel): + unformatted_instruction: str + no_answer_str: str + + QA_INSTRUCTIONS = { - Language( - "en" - ): "{{question}} If there's no answer, say {{no_answer_text}}. Only answer the question based on the text.", - Language( - "de" - ): "{{question}} Wenn es keine Antwort gibt, gib {{no_answer_text}} aus. Beantworte die Frage nur anhand des Textes.", - Language( - "fr" - ): "{{question}} S'il n'y a pas de réponse, dites {{no_answer_text}}. Ne répondez à la question qu'en vous basant sur le texte.", - Language( - "es" - ): "{{question}} Si no hay respuesta, di {{no_answer_text}}. Responde sólo a la pregunta basándote en el texto.", - Language( - "it" - ): "{{question}} Se non c'è risposta, dire {{no_answer_text}}. Rispondere alla domanda solo in base al testo.", + Language("en"): QaSetup( + unformatted_instruction='{{question}}\nIf there\'s no answer, say "{{no_answer_text}}". Only answer the question based on the text.', + no_answer_str="no answer in text", + ), + Language("de"): QaSetup( + unformatted_instruction='{{question}}\nWenn es keine Antwort gibt, gib "{{no_answer_text}}" aus. Beantworte die Frage nur anhand des Textes.', + no_answer_str="keine Antwort im Text", + ), + Language("fr"): QaSetup( + unformatted_instruction="{{question}}\nS'il n'y a pas de réponse, dites \"{{no_answer_text}}\". Ne répondez à la question qu'en vous basant sur le texte.", + no_answer_str="pas de réponse dans le texte", + ), + Language("es"): QaSetup( + unformatted_instruction='{{question}}\nSi no hay respuesta, di "{{no_answer_text}}". Responde sólo a la pregunta basándote en el texto.', + no_answer_str="no hay respuesta en el texto", + ), + Language("it"): QaSetup( + unformatted_instruction='{{question}}\nSe non c\'è risposta, dire "{{no_answer_text}}". Rispondere alla domanda solo in base al testo.', + no_answer_str="nessuna risposta nel testo", + ), } -NO_ANSWER_STR = "NO_ANSWER_IN_TEXT" - class SingleChunkQaInput(BaseModel): """The input for a `SingleChunkQa` task. @@ -83,14 +94,12 @@ class SingleChunkQa(Task[SingleChunkQaInput, SingleChunkQaOutput]): Example: >>> import os - >>> from intelligence_layer.connectors import LimitedConcurrencyClient >>> from intelligence_layer.core import Language >>> from intelligence_layer.core import InMemoryTracer >>> from intelligence_layer.core import Chunk >>> from intelligence_layer.use_cases import SingleChunkQa, SingleChunkQaInput >>> - >>> client = LimitedConcurrencyClient.from_token(os.getenv("AA_TOKEN")) - >>> task = SingleChunkQa(client) + >>> task = SingleChunkQa() >>> input = SingleChunkQaInput( ... chunk=Chunk("Tina does not like pizza. However, Mike does."), ... question="Who likes pizza?", @@ -102,37 +111,39 @@ class SingleChunkQa(Task[SingleChunkQaInput, SingleChunkQaOutput]): def __init__( self, - client: AlephAlphaClientProtocol, - model: str = "luminous-supreme-control", - instruction_config: Mapping[Language, str] = QA_INSTRUCTIONS, + model: AlephAlphaModel = LuminousControlModel( + "luminous-supreme-control-20240215" + ), + text_highlight: TextHighlight = TextHighlight( + LuminousControlModel("luminous-base-control-20240215") + ), + instruction_config: Mapping[Language, QaSetup] = QA_INSTRUCTIONS, maximum_tokens: int = 64, - no_answer_str: str = NO_ANSWER_STR, ): super().__init__() - self._client = client self._model = model - self._instruction = Instruct(client, model) - self._text_highlight = TextHighlight(client) + self._text_highlight = text_highlight self._instruction_config = instruction_config self._maximum_tokens = maximum_tokens - self._no_answer_str = no_answer_str def do_run( self, input: SingleChunkQaInput, task_span: TaskSpan ) -> SingleChunkQaOutput: - instruction_text = language_config(input.language, self._instruction_config) + qa_setup = language_config(input.language, self._instruction_config) - output = self._generate_answer( - Template(instruction_text).render( - question=input.question, no_answer_text=self._no_answer_str + output, prompt = self._generate_answer( + Template(qa_setup.unformatted_instruction).render( + question=input.question, no_answer_text=qa_setup.no_answer_str ), input.chunk, task_span, ) - answer = self._no_answer_to_none(output.completion.strip()) + answer = self._no_answer_to_none( + output.completion.strip(), qa_setup.no_answer_str + ) highlights = ( self._get_highlights( - output.rich_prompt, + prompt, output.completion, task_span, ) @@ -146,14 +157,17 @@ def do_run( def _generate_answer( self, instruction: str, input: str, task_span: TaskSpan - ) -> PromptOutput: - return self._instruction.run( - InstructInput( - instruction=instruction, - input=input, - maximum_response_tokens=self._maximum_tokens, + ) -> tuple[CompleteOutput, RichPrompt]: + prompt = self._model.to_instruct_prompt(instruction, input) + return ( + self._model.complete( + CompleteInput( + prompt=prompt, + maximum_tokens=self._maximum_tokens, + ), + task_span, ), - task_span, + prompt, ) def _get_highlights( @@ -165,11 +179,10 @@ def _get_highlights( highlight_input = TextHighlightInput( rich_prompt=prompt_with_metadata, target=completion, - model=self._model, focus_ranges=frozenset({"input"}), ) highlight_output = self._text_highlight.run(highlight_input, task_span) return [h.text for h in highlight_output.highlights if h.score > 0] - def _no_answer_to_none(self, completion: str) -> Optional[str]: - return completion if completion != self._no_answer_str else None + def _no_answer_to_none(self, completion: str, no_answer_str: str) -> Optional[str]: + return completion if no_answer_str in completion else None diff --git a/src/intelligence_layer/use_cases/summarize/long_context_few_shot_summarize.py b/src/intelligence_layer/use_cases/summarize/long_context_few_shot_summarize.py deleted file mode 100644 index 845df02f7..000000000 --- a/src/intelligence_layer/use_cases/summarize/long_context_few_shot_summarize.py +++ /dev/null @@ -1,77 +0,0 @@ -from typing import Mapping - -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) -from intelligence_layer.core.chunk import ChunkInput, ChunkTask -from intelligence_layer.core.complete import FewShotConfig -from intelligence_layer.core.detect_language import Language -from intelligence_layer.core.task import Task -from intelligence_layer.core.tracer import TaskSpan -from intelligence_layer.use_cases.summarize.single_chunk_few_shot_summarize import ( - SingleChunkFewShotSummarize, -) -from intelligence_layer.use_cases.summarize.summarize import ( - LongContextSummarizeInput, - LongContextSummarizeOutput, - PartialSummary, - SingleChunkSummarizeInput, -) - - -class LongContextFewShotSummarize( - Task[LongContextSummarizeInput, LongContextSummarizeOutput] -): - """Condenses a long text into a summary. - - Generate a summary given a few-shot setup. - - Note: - - `model` provided should be a vanilla model, such as "luminous-base". - - Args: - client: Aleph Alpha client instance for running model related API calls. - few_shot_configs: A mapping of valid `Language` to `FewShotConfig` for each - supported language. - model: A valid Aleph Alpha model name. - max_generated_tokens: The maximum number of tokens per sub-summary. - max_tokens_per_chunk: The maximum number of tokens per chunk that the long text - is divided into. - allowed_languages: List of languages to which the language detection is limited (ISO619). - fallback_language: The default language of the output. - """ - - def __init__( - self, - client: AlephAlphaClientProtocol, - few_shot_configs: Mapping[Language, FewShotConfig], - model: str, - max_generated_tokens: int, - max_tokens_per_chunk: int, - ) -> None: - self._single_chunk_summarize = SingleChunkFewShotSummarize( - client, model, max_generated_tokens, few_shot_configs - ) - self._chunk = ChunkTask(client, model, max_tokens_per_chunk) - - def do_run( - self, input: LongContextSummarizeInput, task_span: TaskSpan - ) -> LongContextSummarizeOutput: - chunk_output = self._chunk.run(ChunkInput(text=input.text), task_span) - summary_outputs = self._single_chunk_summarize.run_concurrently( - [ - SingleChunkSummarizeInput(chunk=chunk, language=input.language) - for chunk in chunk_output.chunks - ], - task_span, - ) - return LongContextSummarizeOutput( - partial_summaries=[ - PartialSummary( - summary=summary_output.summary, - chunk=chunk, - generated_tokens=summary_output.generated_tokens, - ) - for summary_output, chunk in zip(summary_outputs, chunk_output.chunks) - ] - ) diff --git a/src/intelligence_layer/use_cases/summarize/long_context_high_compression_summarize.py b/src/intelligence_layer/use_cases/summarize/long_context_high_compression_summarize.py deleted file mode 100644 index ec9105234..000000000 --- a/src/intelligence_layer/use_cases/summarize/long_context_high_compression_summarize.py +++ /dev/null @@ -1,153 +0,0 @@ -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) -from intelligence_layer.core.complete import FewShotConfig, FewShotExample -from intelligence_layer.core.detect_language import Language -from intelligence_layer.use_cases.summarize.long_context_few_shot_summarize import ( - LongContextFewShotSummarize, -) - -FEW_SHOT_CONFIGS = { - Language("en"): FewShotConfig( - instruction="Summarize each text in one to three sentences.", - examples=[ - FewShotExample( - input="The startup ecosystem also represents a key success factor for Baden-Württemberg as a business location. It is currently characterized above all by a large number of very active locations such as Mannheim, Karlsruhe and Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). However, in Baden-Württemberg in particular, traditional industries still account for around 30% of gross domestic product, which means that, like other regions, it is massively threatened by structural change (Statistisches Landesamt Baden-Württemberg 2021).", - response="Startups are gaining importance in Baden-Württemberg.", - ), - FewShotExample( - input="For political reasons, the study avoids the terms country or state, but breaks down by national economies. In 185 economies, the authors were able to survey prices for a pure data mobile product that meets the minimum requirements mentioned for 2020 as well as 2021. The results show that the global average price has fallen by two percent to USD 9.30 per month. The development varies greatly from region to region. In the Commonwealth of Independent States, the average price has risen by almost half in just one year, to the equivalent of 5.70 US dollars. In the Americas, prices have risen by ten percent to an average of $14.70. While consumers in wealthy economies enjoyed an average price reduction of 13 percent to USD 15.40, there was no cost reduction for consumers in less wealthy countries.", - response="While mobile prices are falling globally, they are rising regionally, in some cases sharply.", - ), - FewShotExample( - input="Huawei suffered a 29 percent drop in sales in 2021. No wonder, since the Chinese company is subject to U.S. sanctions and cannot obtain new hardware or software from the U.S. and some other Western countries. Exports are also restricted. Nevertheless, the company's headquarters in Shenzhen reported a lower debt ratio, a 68 percent increase in operating profit and even a 76 percent increase in net profit for 2021. Will Huawei's record profit go down in the history books as the Miracle of Shenzhen despite the slump in sales? Will the brave Chinese be able to outsmart the tech-hungry Americans? Are export bans proving to be a boomerang, hurting the U.S. export business while Huawei prints more money than ever before?", - response="In 2021, Huawei's sales fell, but it made more profit.", - ), - ], - input_prefix="Text", - response_prefix="Summary", - additional_stop_sequences=["\n"], - ), - Language("de"): FewShotConfig( - instruction="Fasse jeden Text in ein bis drei Sätzen zusammen.", - examples=[ - FewShotExample( - input="Auch für den Wirtschaftsstandort Baden-Württemberg stellt das Start-up-Ökosystem einen zentralen Erfolgsfaktor dar. Es zeichnet sich aktuell vor allem durch eine Vielzahl von sehr aktiven Standorten wie Mannheim, Karlsruhe und Stuttgart aus (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Allerdings entfallen gerade in Baden-Württemberg noch immer rund 30 % des Bruttoinlandsprodukts auf traditionelle Industrien, womit es wie auch andere Regionen massiv durch den Strukturwandel bedroht ist (Statistisches Landesamt Baden-Württemberg 2021).", - response="Startups gewinnen in Baden-Württemberg an Bedeutung.", - ), - FewShotExample( - input="Aus politischen Gründen vermeidet die Studie die Begriffe Land oder Staat, sondern gliedert nach Volkswirtschaften. In 185 Volkswirtschaften konnten die Autoren für 2020 sowie 2021 Preise für ein reines Daten-Mobilfunkprodukt erheben, das die genannten Minimalvoraussetzungen erfüllt. Dabei zeigt sich, dass der globale Durchschnittspreis um zwei Prozent auf 9,30 US-Dollar pro Monat gesunken ist. Die Entwicklung ist regional höchst unterschiedlich. In der Gemeinschaft Unabhängiger Staaten ist der Durchschnittspreis in nur einem Jahr um fast die Hälfte gestiegen, auf umgerechnet 5,70 US-Dollar. Auf den Amerika-Kontinenten gab es einen Preisanstieg um immerhin zehn Prozent auf durchschnittlich 14,70 US-Dollar. Während Verbraucher in wohlhabenden Volkswirtschaften sich über eine durchschnittliche Preissenkung von 13 Prozent auf 15,40 US-Dollar freuen durften, gab es für Konsumenten in weniger wohlhabenden Ländern keine Kostensenkung.", - response="Während Mobilfunkpreise global sinken, steigen sie regionals teils stark an.", - ), - FewShotExample( - input="Einen Umsatzeinbruch von 29 Prozent musste Huawei 2021 hinnehmen. Kein Wunder, ist der chinesische Konzern doch US-Sanktionen ausgesetzt und kann keine neue Hard- noch Software aus den USA und einigen anderen westlichen Ländern beziehen. Auch die Exporte sind eingeschränkt. Dennoch meldet die Konzernzentrale in Shenzhen eine geringere Schuldenquote, um 68 Prozent gestiegenen Betriebsgewinn und gar um 76 Prozent höheren Reingewinn für 2021. Geht Huaweis Rekordgewinn trotz Umsatzeinbruchs als Wunder von Shenzhen in die Geschichtsbücher ein? Schlagen die wackeren Chinesen den technik-geizigen Amis ein Schnippchen? Erweisen sich die Exportverbote als Bumerang, der das US-Exportgeschäft schädigt, während Huawei gleichzeitig mehr Geld druckt als je zuvor?", - response="Im Jahr 2021 fiel Huaweis Umsatz, doch es wurde mehr Gewinn gemacht.", - ), - ], - input_prefix="Text", - response_prefix="Zusammenfassung", - additional_stop_sequences=["\n"], - ), - Language("es"): FewShotConfig( - instruction="Resuma cada texto en una o tres frases.", - examples=[ - FewShotExample( - input="El ecosistema de las start-ups es también un factor clave para el éxito de Baden-Württemberg como lugar de negocios. Actualmente se caracteriza sobre todo por un gran número de localidades muy activas como Mannheim, Karlsruhe y Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Sin embargo, en Baden-Württemberg, en particular, las industrias tradicionales siguen representando alrededor del 30% del producto interior bruto, lo que significa que, al igual que otras regiones, está muy amenazada por el cambio estructural (Statistisches Landesamt Baden-Württemberg 2021).", - response="Las start-ups están ganando importancia en Baden-Württemberg.", - ), - FewShotExample( - input="Por razones políticas, el estudio evita los términos país o estado, sino que se desglosa por economías nacionales. En 185 economías, los autores pudieron estudiar los precios de un producto móvil de datos puros para 2020 y 2021 que cumple los requisitos mínimos mencionados. Los resultados muestran que el precio medio global ha bajado un 2%, hasta los 9,30 dólares mensuales. El desarrollo varía mucho de una región a otra. En la Comunidad de Estados Independientes, el precio medio ha subido casi la mitad en sólo un año, hasta el equivalente a 5,70 dólares estadounidenses. En el continente americano, el precio subió un diez por ciento, hasta una media de 14,70 dólares. Mientras que los consumidores de las economías ricas disfrutaron de una reducción media de precios del 13%, hasta los 15,40 dólares, los consumidores de los países menos ricos no vieron ninguna reducción de costes.", - response="Aunque los precios de los móviles están bajando a nivel mundial, están subiendo a nivel regional, en algunos casos de forma pronunciada.", - ), - FewShotExample( - input="Huawei sufrió una caída del 29% en sus ventas en 2021. No es de extrañar, ya que la empresa china está sometida a sanciones estadounidenses y no puede obtener nuevo hardware o software de EE.UU. y algunos otros países occidentales. Las exportaciones también están restringidas. Sin embargo, la sede central de la empresa en Shenzhen informó de un menor ratio de endeudamiento, un aumento del 68% en el beneficio operativo e incluso un incremento del 76% en el beneficio neto para 2021. ¿Pasará el récord de beneficios de Huawei a los libros de historia como el Milagro de Shenzhen a pesar del desplome de las ventas? ¿Serán los valientes chinos capaces de burlar a los expertos en tecnología estadounidenses? ¿Las prohibiciones a las exportaciones están siendo un bumerán, perjudicando al negocio de las exportaciones estadounidenses, mientras que al mismo tiempo Huawei está imprimiendo más dinero que nunca?", - response="En 2021, las ventas de Huawei cayeron, pero obtuvo más beneficios.", - ), - ], - input_prefix="Texto", - response_prefix="Resumen", - additional_stop_sequences=["\n"], - ), - Language("fr"): FewShotConfig( - instruction="Résume chaque texte en une à trois phrases.", - examples=[ - FewShotExample( - input="L'écosystème des start-ups représente également un facteur de succès central pour le site économique du Bade-Wurtemberg. Il se caractérise actuellement surtout par un grand nombre de sites très actifs comme Mannheim, Karlsruhe et Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Cependant, dans le Bade-Wurtemberg en particulier, les industries traditionnelles représentent encore environ 30 % du produit intérieur brut, ce qui fait que le Bade-Wurtemberg, comme d'autres régions, est massivement menacé par le changement structurel (Statistisches Landesamt Baden-Württemberg 2021).", - response="Les startups gagnent en importance dans le Bade-Wurtemberg.", - ), - FewShotExample( - input="Pour des raisons politiques, l'étude évite les termes de pays ou d'État, mais s'articule autour des économies nationales. Dans 185 économies, les auteurs ont pu relever les prix pour 2020 et 2021 d'un produit de téléphonie mobile de données pur qui remplit les conditions minimales mentionnées. Il en ressort que le prix moyen mondial a baissé de 2 % pour atteindre 9,30 dollars US par mois. L'évolution varie fortement d'une région à l'autre. Dans la Communauté des États indépendants, le prix moyen a augmenté de près de moitié en un an seulement, pour atteindre l'équivalent de 5,70 dollars américains. Sur le continent américain, les prix ont augmenté de 10 % pour atteindre 14,70 dollars en moyenne. Alors que les consommateurs des économies prospères ont pu se réjouir d'une baisse moyenne des prix de 13% à 15,40 dollars US, les consommateurs des pays moins prospères n'ont pas connu de baisse des coûts.", - response="Alors que les prix de la téléphonie mobile baissent au niveau mondial, ils augmentent parfois fortement au niveau régional.", - ), - FewShotExample( - input="Huawei a subi une chute de 29 pour cent de son chiffre d'affaires en 2021. Rien d'étonnant à cela, puisque le groupe chinois est soumis à des sanctions américaines et ne peut plus acheter de nouveaux matériels ou logiciels aux États-Unis et dans certains autres pays occidentaux. Les exportations sont également limitées. Malgré cela, le siège du groupe à Shenzhen annonce un taux d'endettement plus faible, un bénéfice d'exploitation en hausse de 68 pour cent et même un bénéfice net en hausse de 76 pour cent pour 2021. Le bénéfice record de Huawei malgré la chute du chiffre d'affaires entrera-t-il dans les livres d'histoire comme le miracle de Shenzhen ? Les braves Chinois déjouent-ils les ambitions technologiques des Américains ? Les interdictions d'exportation se révèlent-elles être un boomerang qui nuit au commerce d'exportation américain, alors que dans le même temps Huawei imprime plus d'argent que jamais ?", - response="En 2021, le chiffre d'affaires de Huawei a chuté, mais les bénéfices ont augmenté.", - ), - ], - input_prefix="Texte", - response_prefix="Résumé", - additional_stop_sequences=["\n"], - ), - Language("it"): FewShotConfig( - instruction="Riassumete ogni testo in una o tre frasi.", - examples=[ - FewShotExample( - input="Anche l'ecosistema delle start-up è un fattore chiave di successo per il Baden-Württemberg come sede d'affari. Attualmente è caratterizzata soprattutto da un gran numero di località molto attive come Mannheim, Karlsruhe e Stoccarda (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Tuttavia, nel Baden-Württemberg in particolare, le industrie tradizionali rappresentano ancora circa il 30% del prodotto interno lordo, il che significa che, come altre regioni, è fortemente minacciato dal cambiamento strutturale (Statistisches Landesamt Baden-Württemberg 2021).", - response="Le start-up stanno acquisendo importanza nel Baden-Württemberg.", - ), - FewShotExample( - input="Per ragioni politiche, lo studio evita i termini paese o stato, ma suddivide per economie nazionali. In 185 economie, gli autori sono stati in grado di rilevare i prezzi di un prodotto mobile di dati puro per il 2020 e il 2021 che soddisfa i requisiti minimi citati. I risultati mostrano che il prezzo medio globale è sceso del 2% a 9,30 dollari USA al mese. Lo sviluppo varia notevolmente da regione a regione. Nella Comunità degli Stati Indipendenti, il prezzo medio è aumentato di quasi la metà in un solo anno, fino all'equivalente di 5,70 dollari USA. Nelle Americhe, i prezzi sono aumentati fino al 10%, raggiungendo una media di 14,70 dollari USA. Mentre i consumatori delle economie ricche hanno beneficiato di una riduzione media dei prezzi del 13%, passando a 15,40 dollari USA, i consumatori dei Paesi meno ricchi non hanno registrato alcuna riduzione dei costi.", - response="Mentre i prezzi della telefonia mobile sono in calo a livello globale, aumentano a livello regionale, in alcuni casi in modo marcato.", - ), - FewShotExample( - input="Huawei ha subito un crollo delle vendite del 29% nel 2021. Non c'è da stupirsi, visto che l'azienda cinese è soggetta a sanzioni statunitensi e non può ottenere nuovo hardware o software dagli Stati Uniti e da alcuni altri Paesi occidentali. Anche le esportazioni sono limitate. Ciononostante, la sede centrale dell'azienda a Shenzhen ha registrato un rapporto di indebitamento più basso, un aumento del 68% dell'utile operativo e addirittura un aumento del 76% dell'utile netto per il 2021. Il profitto record di Huawei entrerà nei libri di storia come il miracolo di Shenzhen nonostante il crollo delle vendite? Riusciranno i coraggiosi cinesi a superare in astuzia gli americani esperti di tecnologia? I divieti all'esportazione si stanno rivelando un boomerang, danneggiando l'attività di esportazione degli Stati Uniti, mentre allo stesso tempo Huawei sta stampando più denaro che mai?", - response="Nel 2021 le vendite di Huawei sono diminuite, ma i profitti sono aumentati.", - ), - ], - input_prefix="Testo", - response_prefix="Sintesi", - additional_stop_sequences=["\n"], - ), -} - - -class LongContextHighCompressionSummarize(LongContextFewShotSummarize): - """Condenses a text into a short summary. - - Leverages few-shot prompting to generate a summary. - - Args: - client: Aleph Alpha client instance for running model related API calls. - fallback_language: The default language of the output. - - Example: - >>> import os - >>> from intelligence_layer.connectors import ( - ... LimitedConcurrencyClient, - ... ) - >>> from intelligence_layer.core import InMemoryTracer - >>> from intelligence_layer.use_cases import ( - ... LongContextHighCompressionSummarize, - ... ) - >>> from intelligence_layer.use_cases import LongContextSummarizeInput - - - >>> client = LimitedConcurrencyClient.from_token(os.getenv("AA_TOKEN")) - >>> task = LongContextHighCompressionSummarize(client) - >>> input = LongContextSummarizeInput( - ... text="This is a story about pizza. Tina hates pizza. However, Mike likes it. Pete strongly believes that pizza is the best thing to exist." - ... ) - >>> tracer = InMemoryTracer() - >>> output = task.run(input, tracer) - """ - - def __init__( - self, client: AlephAlphaClientProtocol, model: str = "luminous-extended" - ) -> None: - super().__init__( - client=client, - few_shot_configs=FEW_SHOT_CONFIGS, - model=model, - max_generated_tokens=96, - max_tokens_per_chunk=400, - ) diff --git a/src/intelligence_layer/use_cases/summarize/long_context_low_compression_summarize.py b/src/intelligence_layer/use_cases/summarize/long_context_low_compression_summarize.py deleted file mode 100644 index 6a07eb66a..000000000 --- a/src/intelligence_layer/use_cases/summarize/long_context_low_compression_summarize.py +++ /dev/null @@ -1,154 +0,0 @@ -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) -from intelligence_layer.core.complete import FewShotConfig, FewShotExample -from intelligence_layer.core.detect_language import Language -from intelligence_layer.use_cases.summarize.long_context_few_shot_summarize import ( - LongContextFewShotSummarize, -) - -FEW_SHOT_CONFIGS = { - Language("en"): FewShotConfig( - instruction="Summarize each text in one to three sentences.", - examples=[ - FewShotExample( - input="The startup ecosystem also represents a key success factor for Baden-Württemberg as a business location. It is currently characterized above all by a large number of very active locations such as Mannheim, Karlsruhe and Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). However, in Baden-Württemberg in particular, traditional industries still account for around 30% of gross domestic product, which means that, like other regions, it is massively threatened by structural change (Statistisches Landesamt Baden-Württemberg 2021).", - response="Since Baden-Württemberg is heavily dependent on traditional industries, startups are all the more important. Although startups are very active in Mannheim, Karlsruhe and Stuttgart in particular, traditional industries still account for 30% of the gross domestic product.", - ), - FewShotExample( - input="For political reasons, the study avoids the terms country or state, but breaks down by national economies. In 185 economies, the authors were able to survey prices for a pure data mobile product that meets the minimum requirements mentioned for 2020 as well as 2021. The results show that the global average price has fallen by two percent to USD 9.30 per month. The development varies greatly from region to region. In the Commonwealth of Independent States, the average price has risen by almost half in just one year, to the equivalent of 5.70 US dollars. In the Americas, prices have risen by ten percent to an average of $14.70. While consumers in wealthy economies enjoyed an average price reduction of 13 percent to USD 15.40, there was no cost reduction for consumers in less wealthy countries.", - response="Prices for data-only mobile products fell by an average of two percent globally to USD 9.30 in 2021. However, developments differed, sometimes significantly, by region. For example, prices in the Americas increased by 10%. Affluent regions benefited the most (13% savings). On average, there was no cost reduction in poorer regions.", - ), - FewShotExample( - input="Huawei suffered a 29 percent drop in sales in 2021. No wonder, since the Chinese company is subject to U.S. sanctions and cannot obtain new hardware or software from the U.S. and some other Western countries. Exports are also restricted. Nevertheless, the company's headquarters in Shenzhen reported a lower debt ratio, a 68 percent increase in operating profit and even a 76 percent increase in net profit for 2021. Will Huawei's record profit go down in the history books as the Miracle of Shenzhen despite the slump in sales? Will the brave Chinese be able to outsmart the tech-hungry Americans? Are export bans proving to be a boomerang, hurting the U.S. export business while Huawei prints more money than ever before?", - response="Although Huawei suffered a 29% drop in revenue in 2021, net profit rose 76% and its debt ratio fell. The likely reason is believed to be U.S. sanctions that restrict the Chinese group's trade and exports. However, the sanctions could now prove to be a boomerang.", - ), - ], - input_prefix="Text", - response_prefix="Summary", - additional_stop_sequences=["\n"], - ), - Language("de"): FewShotConfig( - instruction="Fasse jeden Text in ein bis drei Sätzen zusammen.", - examples=[ - FewShotExample( - input="Auch für den Wirtschaftsstandort Baden-Württemberg stellt das Start-up-Ökosystem einen zentralen Erfolgsfaktor dar. Es zeichnet sich aktuell vor allem durch eine Vielzahl von sehr aktiven Standorten wie Mannheim, Karlsruhe und Stuttgart aus (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Allerdings entfallen gerade in Baden-Württemberg noch immer rund 30 % des Bruttoinlandsprodukts auf traditionelle Industrien, womit es wie auch andere Regionen massiv durch den Strukturwandel bedroht ist (Statistisches Landesamt Baden-Württemberg 2021).", - response="Da Baden-Württemberg stark von traditionellen Industrien abhängig ist, sind Start-Ups umso wichtiger. Obwohl Startups gerade in Mannheim, Karlsruhe und Stuttgart sehr aktiv sind, entfallen 30% des Bruttoinlandsprodukts weiterhin auf traditionelle Industrien.", - ), - FewShotExample( - input="Aus politischen Gründen vermeidet die Studie die Begriffe Land oder Staat, sondern gliedert nach Volkswirtschaften. In 185 Volkswirtschaften konnten die Autoren für 2020 sowie 2021 Preise für ein reines Daten-Mobilfunkprodukt erheben, das die genannten Minimalvoraussetzungen erfüllt. Dabei zeigt sich, dass der globale Durchschnittspreis um zwei Prozent auf 9,30 US-Dollar pro Monat gesunken ist. Die Entwicklung ist regional höchst unterschiedlich. In der Gemeinschaft Unabhängiger Staaten ist der Durchschnittspreis in nur einem Jahr um fast die Hälfte gestiegen, auf umgerechnet 5,70 US-Dollar. Auf den Amerika-Kontinenten gab es einen Preisanstieg um immerhin zehn Prozent auf durchschnittlich 14,70 US-Dollar. Während Verbraucher in wohlhabenden Volkswirtschaften sich über eine durchschnittliche Preissenkung von 13 Prozent auf 15,40 US-Dollar freuen durften, gab es für Konsumenten in weniger wohlhabenden Ländern keine Kostensenkung.", - response="Die Preise für reine Daten-Mobilfunkprodukte sind im Jahr 2021 weltweit um durchschnittlich zwei Prozent auf 9,30 USD gefallen. Jedoch unterscheiden sich die Entwicklungen regional teils stark. Beispielsweise stiegen die Preise auf den amerikanischen Kontinenten um 10% an. Am stärksten profitieren wohlhabende Regionen (13% Ersparnis). In ärmeren Regionen gab es im Durchschnitt keine Kostensenkung.", - ), - FewShotExample( - input="Einen Umsatzeinbruch von 29 Prozent musste Huawei 2021 hinnehmen. Kein Wunder, ist der chinesische Konzern doch US-Sanktionen ausgesetzt und kann keine neue Hard- noch Software aus den USA und einigen anderen westlichen Ländern beziehen. Auch die Exporte sind eingeschränkt. Dennoch meldet die Konzernzentrale in Shenzhen eine geringere Schuldenquote, um 68 Prozent gestiegenen Betriebsgewinn und gar um 76 Prozent höheren Reingewinn für 2021. Geht Huaweis Rekordgewinn trotz Umsatzeinbruchs als Wunder von Shenzhen in die Geschichtsbücher ein? Schlagen die wackeren Chinesen den technik-geizigen Amis ein Schnippchen? Erweisen sich die Exportverbote als Bumerang, der das US-Exportgeschäft schädigt, während Huawei gleichzeitig mehr Geld druckt als je zuvor?", - response="Obwohl Huawei im Jahr 2021 einen Umsatzrückgang von 29 Prozent hinnehmen musste, stieg der Reingewinn um 76% und die Schuldenquote sank. Als Grund gelten wahrscheinlich die US-Sanktionen, die Handel und Exporte des chinesischen Konzerns einschränken. Die Sanktionen könnten sich nun jedoch als Bumerang erweisen.", - ), - ], - input_prefix="Text", - response_prefix="Zusammenfassung", - additional_stop_sequences=["\n"], - ), - Language("es"): FewShotConfig( - instruction="Resuma cada texto en una o tres frases.", - examples=[ - FewShotExample( - input="El ecosistema de las start-ups es también un factor clave para el éxito de Baden-Württemberg como lugar de negocios. Actualmente se caracteriza sobre todo por un gran número de localidades muy activas como Mannheim, Karlsruhe y Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Sin embargo, en Baden-Württemberg, en particular, las industrias tradicionales siguen representando alrededor del 30% del producto interior bruto, lo que significa que, al igual que otras regiones, está muy amenazada por el cambio estructural (Statistisches Landesamt Baden-Württemberg 2021).", - response="Dado que Baden-Württemberg depende en gran medida de las industrias tradicionales, las empresas de nueva creación son aún más importantes. Aunque las start-ups son muy activas en Mannheim, Karlsruhe y Stuttgart en particular, las industrias tradicionales siguen representando el 30% del producto interior bruto.", - ), - FewShotExample( - input="Por razones políticas, el estudio evita los términos país o estado, sino que se desglosa por economías nacionales. En 185 economías, los autores pudieron estudiar los precios de un producto móvil de datos puros para 2020 y 2021 que cumple los requisitos mínimos mencionados. Los resultados muestran que el precio medio global ha bajado un 2%, hasta los 9,30 dólares mensuales. El desarrollo varía mucho de una región a otra. En la Comunidad de Estados Independientes, el precio medio ha subido casi la mitad en sólo un año, hasta el equivalente a 5,70 dólares estadounidenses. En el continente americano, el precio subió un diez por ciento, hasta una media de 14,70 dólares. Mientras que los consumidores de las economías ricas disfrutaron de una reducción media de precios del 13%, hasta los 15,40 dólares, los consumidores de los países menos ricos no vieron ninguna reducción de costes.", - response="Los precios de los productos de telefonía móvil de sólo datos bajaron en todo el mundo una media del 2%, hasta los 9,30 dólares en 2021. Sin embargo, la evolución difiere a nivel regional, a veces de forma significativa. Por ejemplo, los precios en América aumentaron un 10%. Las regiones ricas son las más beneficiadas (13% de ahorro). Por término medio, no hubo reducción de costes en las regiones más pobres.", - ), - FewShotExample( - input="Huawei sufrió una caída del 29% en sus ventas en 2021. No es de extrañar, ya que la empresa china está sometida a sanciones estadounidenses y no puede obtener nuevo hardware o software de EE.UU. y algunos otros países occidentales. Las exportaciones también están restringidas. Sin embargo, la sede central de la empresa en Shenzhen informó de un menor ratio de endeudamiento, un aumento del 68% en el beneficio operativo e incluso un incremento del 76% en el beneficio neto para 2021. ¿Pasará el récord de beneficios de Huawei a los libros de historia como el Milagro de Shenzhen a pesar del desplome de las ventas? ¿Serán los valientes chinos capaces de burlar a los expertos en tecnología estadounidenses? ¿Las prohibiciones a las exportaciones están siendo un bumerán, perjudicando al negocio de las exportaciones estadounidenses, mientras que al mismo tiempo Huawei está imprimiendo más dinero que nunca?", - response="Aunque Huawei sufrió un descenso del 29% en sus ingresos en 2021, el beneficio neto aumentó un 76% y su ratio de endeudamiento se redujo. La razón es probablemente las sanciones de Estados Unidos, que restringen el comercio y las exportaciones del grupo chino. Sin embargo, las sanciones podrían resultar ahora un bumerán.", - ), - ], - input_prefix="Texto", - response_prefix="Resumen", - additional_stop_sequences=["\n"], - ), - Language("fr"): FewShotConfig( - instruction="Résume chaque texte en une à trois phrases.", - examples=[ - FewShotExample( - input="L'écosystème des start-ups représente également un facteur de succès central pour le site économique du Bade-Wurtemberg. Il se caractérise actuellement surtout par un grand nombre de sites très actifs comme Mannheim, Karlsruhe et Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Cependant, dans le Bade-Wurtemberg en particulier, les industries traditionnelles représentent encore environ 30 % du produit intérieur brut, ce qui fait que le Bade-Wurtemberg, comme d'autres régions, est massivement menacé par le changement structurel (Statistisches Landesamt Baden-Württemberg 2021).", - response="Le Bade-Wurtemberg étant fortement dépendant des industries traditionnelles, les start-ups sont d'autant plus importantes. Bien que les start-ups soient très actives, notamment à Mannheim, Karlsruhe et Stuttgart, les industries traditionnelles représentent toujours 30% du produit intérieur brut.", - ), - FewShotExample( - input="Pour des raisons politiques, l'étude évite les termes de pays ou d'État, mais s'articule autour des économies nationales. Dans 185 économies, les auteurs ont pu relever les prix pour 2020 et 2021 d'un produit de téléphonie mobile de données pur qui remplit les conditions minimales mentionnées. Il en ressort que le prix moyen mondial a baissé de 2 % pour atteindre 9,30 dollars US par mois. L'évolution varie fortement d'une région à l'autre. Dans la Communauté des États indépendants, le prix moyen a augmenté de près de moitié en un an seulement, pour atteindre l'équivalent de 5,70 dollars américains. Sur le continent américain, les prix ont augmenté de 10 % pour atteindre 14,70 dollars en moyenne. Alors que les consommateurs des économies prospères ont pu se réjouir d'une baisse moyenne des prix de 13% à 15,40 dollars US, les consommateurs des pays moins prospères n'ont pas connu de baisse des coûts.", - response="Les prix des produits mobiles de données pures ont baissé en moyenne de 2 % dans le monde en 2021, pour atteindre 9,30 dollars. Toutefois, les évolutions varient fortement d'une région à l'autre. Par exemple, les prix ont augmenté de 10% sur le continent américain. Ce sont les régions riches qui en profitent le plus (13% d'économies). Dans les régions plus pauvres, il n'y a eu en moyenne aucune réduction des coûts.", - ), - FewShotExample( - input="Huawei a subi une chute de 29 pour cent de son chiffre d'affaires en 2021. Rien d'étonnant à cela, puisque le groupe chinois est soumis à des sanctions américaines et ne peut plus acheter de nouveaux matériels ou logiciels aux États-Unis et dans certains autres pays occidentaux. Les exportations sont également limitées. Malgré cela, le siège du groupe à Shenzhen annonce un taux d'endettement plus faible, un bénéfice d'exploitation en hausse de 68 pour cent et même un bénéfice net en hausse de 76 pour cent pour 2021. Le bénéfice record de Huawei malgré la chute du chiffre d'affaires entrera-t-il dans les livres d'histoire comme le miracle de Shenzhen ? Les braves Chinois déjouent-ils les ambitions technologiques des Américains ? Les interdictions d'exportation se révèlent-elles être un boomerang qui nuit au commerce d'exportation américain, alors que dans le même temps Huawei imprime plus d'argent que jamais ?", - response="Bien que Huawei ait vu son chiffre d'affaires baisser de 29% en 2021, son bénéfice net a augmenté de 76% et son taux d'endettement a baissé. Les sanctions américaines, qui limitent le commerce et les exportations du groupe chinois, en sont probablement la raison. Toutefois, ces sanctions pourraient désormais avoir un effet boomerang.", - ), - ], - input_prefix="Texte", - response_prefix="Résumé", - additional_stop_sequences=["\n"], - ), - Language("it"): FewShotConfig( - instruction="Riassumete ogni testo in una o tre frasi.", - examples=[ - FewShotExample( - input="Anche l'ecosistema delle start-up è un fattore chiave di successo per il Baden-Württemberg come sede d'affari. Attualmente è caratterizzata soprattutto da un gran numero di località molto attive come Mannheim, Karlsruhe e Stoccarda (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Tuttavia, nel Baden-Württemberg in particolare, le industrie tradizionali rappresentano ancora circa il 30% del prodotto interno lordo, il che significa che, come altre regioni, è fortemente minacciato dal cambiamento strutturale (Statistisches Landesamt Baden-Württemberg 2021).", - response="Poiché il Baden-Württemberg è fortemente dipendente dalle industrie tradizionali, le start-up sono ancora più importanti. Sebbene le start-up siano molto attive soprattutto a Mannheim, Karlsruhe e Stoccarda, le industrie tradizionali rappresentano ancora il 30% del prodotto interno lordo.", - ), - FewShotExample( - input="Per ragioni politiche, lo studio evita i termini paese o stato, ma suddivide per economie nazionali. In 185 economie, gli autori sono stati in grado di rilevare i prezzi di un prodotto mobile di dati puro per il 2020 e il 2021 che soddisfa i requisiti minimi citati. I risultati mostrano che il prezzo medio globale è sceso del 2% a 9,30 dollari USA al mese. Lo sviluppo varia notevolmente da regione a regione. Nella Comunità degli Stati Indipendenti, il prezzo medio è aumentato di quasi la metà in un solo anno, fino all'equivalente di 5,70 dollari USA. Nelle Americhe, i prezzi sono aumentati fino al 10%, raggiungendo una media di 14,70 dollari USA. Mentre i consumatori delle economie ricche hanno beneficiato di una riduzione media dei prezzi del 13%, passando a 15,40 dollari USA, i consumatori dei Paesi meno ricchi non hanno registrato alcuna riduzione dei costi.", - response="I prezzi dei prodotti di telefonia mobile solo dati sono diminuiti in media del 2% a livello globale, raggiungendo i 9,30 dollari nel 2021. Tuttavia, gli sviluppi differiscono a livello regionale, a volte in modo significativo. Ad esempio, i prezzi nelle Americhe sono aumentati del 10%. Le regioni ricche sono quelle che ne beneficiano di più (13% di risparmio). Nelle regioni più povere non si è registrata in media alcuna riduzione dei costi.", - ), - FewShotExample( - input="Huawei ha subito un crollo delle vendite del 29% nel 2021. Non c'è da stupirsi, visto che l'azienda cinese è soggetta a sanzioni statunitensi e non può ottenere nuovo hardware o software dagli Stati Uniti e da alcuni altri Paesi occidentali. Anche le esportazioni sono limitate. Ciononostante, la sede centrale dell'azienda a Shenzhen ha registrato un rapporto di indebitamento più basso, un aumento del 68% dell'utile operativo e addirittura un aumento del 76% dell'utile netto per il 2021. Il profitto record di Huawei entrerà nei libri di storia come il miracolo di Shenzhen nonostante il crollo delle vendite? Riusciranno i coraggiosi cinesi a superare in astuzia gli americani esperti di tecnologia? I divieti all'esportazione si stanno rivelando un boomerang, danneggiando l'attività di esportazione degli Stati Uniti, mentre allo stesso tempo Huawei sta stampando più denaro che mai?", - response="Sebbene Huawei abbia subito un calo dei ricavi del 29% nel 2021, l'utile netto è aumentato del 76% e il rapporto di indebitamento è diminuito. Il motivo è probabilmente da ricercare nelle sanzioni statunitensi, che limitano il commercio e le esportazioni del gruppo cinese. Tuttavia, le sanzioni potrebbero ora rivelarsi un boomerang.", - ), - ], - input_prefix="Testo", - response_prefix="Sintesi", - additional_stop_sequences=["\n"], - ), -} - - -class LongContextLowCompressionSummarize(LongContextFewShotSummarize): - """Condenses a text into a long summary. - - Leverages few-shot prompting to generate a summary. - - Args: - client: Aleph Alpha client instance for running model related API calls. - fallback_language: The default language of the output. - - - Example: - >>> import os - >>> from intelligence_layer.connectors import ( - ... LimitedConcurrencyClient, - ... ) - >>> from intelligence_layer.core import InMemoryTracer - >>> from intelligence_layer.use_cases import ( - ... LongContextLowCompressionSummarize, - ... ) - >>> from intelligence_layer.use_cases import LongContextSummarizeInput - - - >>> client = LimitedConcurrencyClient.from_token(os.getenv("AA_TOKEN")) - >>> task = LongContextLowCompressionSummarize(client) - >>> input = LongContextSummarizeInput( - ... text="This is a story about pizza. Tina hates pizza. However, Mike likes it. Pete strongly believes that pizza is the best thing to exist." - ... ) - >>> tracer = InMemoryTracer() - >>> output = task.run(input, tracer) - """ - - def __init__( - self, client: AlephAlphaClientProtocol, model: str = "luminous-extended" - ) -> None: - super().__init__( - client=client, - few_shot_configs=FEW_SHOT_CONFIGS, - model=model, - max_generated_tokens=160, - max_tokens_per_chunk=200, - ) diff --git a/src/intelligence_layer/use_cases/summarize/long_context_medium_compression_summarize.py b/src/intelligence_layer/use_cases/summarize/long_context_medium_compression_summarize.py deleted file mode 100644 index fd0b7aeb2..000000000 --- a/src/intelligence_layer/use_cases/summarize/long_context_medium_compression_summarize.py +++ /dev/null @@ -1,154 +0,0 @@ -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) -from intelligence_layer.core.complete import FewShotConfig, FewShotExample -from intelligence_layer.core.detect_language import Language -from intelligence_layer.use_cases.summarize.long_context_few_shot_summarize import ( - LongContextFewShotSummarize, -) - -FEW_SHOT_CONFIGS = { - Language("en"): FewShotConfig( - instruction="Summarize each text in one to three sentences.", - examples=[ - FewShotExample( - input="The startup ecosystem also represents a key success factor for Baden-Württemberg as a business location. It is currently characterized above all by a large number of very active locations such as Mannheim, Karlsruhe and Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). However, in Baden-Württemberg in particular, traditional industries still account for around 30% of gross domestic product, which means that, like other regions, it is massively threatened by structural change (Statistisches Landesamt Baden-Württemberg 2021).", - response="Since Baden-Württemberg is heavily dependent on traditional industries, startups are all the more important. Start-ups are very active in Mannheim, Karlsruhe and Stuttgart.", - ), - FewShotExample( - input="For political reasons, the study avoids the terms country or state, but breaks down by national economies. In 185 economies, the authors were able to survey prices for a pure data mobile product that meets the minimum requirements mentioned for 2020 as well as 2021. The results show that the global average price has fallen by two percent to USD 9.30 per month. The development varies greatly from region to region. In the Commonwealth of Independent States, the average price has risen by almost half in just one year, to the equivalent of 5.70 US dollars. In the Americas, prices have risen by ten percent to an average of $14.70. While consumers in wealthy economies enjoyed an average price reduction of 13 percent to USD 15.40, there was no cost reduction for consumers in less wealthy countries.", - response="Prices for data-only mobile products fell by an average of two percent globally to USD 9.30 in 2021. Affluent regions benefited most (13% savings), poorer regions least (no cost reduction).", - ), - FewShotExample( - input="Huawei suffered a 29 percent drop in sales in 2021. No wonder, since the Chinese company is subject to U.S. sanctions and cannot obtain new hardware or software from the U.S. and some other Western countries. Exports are also restricted. Nevertheless, the company's headquarters in Shenzhen reported a lower debt ratio, a 68 percent increase in operating profit and even a 76 percent increase in net profit for 2021. Will Huawei's record profit go down in the history books as the Miracle of Shenzhen despite the slump in sales? Will the brave Chinese be able to outsmart the tech-hungry Americans? Are export bans proving to be a boomerang, hurting the U.S. export business while Huawei prints more money than ever before?", - response="Huawei's 2021 revenue fell 29%, but at the same time net profit rose 76% and its debt ratio fell. That's unusual.", - ), - ], - input_prefix="Text", - response_prefix="Summary", - additional_stop_sequences=["\n"], - ), - Language("de"): FewShotConfig( - instruction="Fasse jeden Text in ein bis drei Sätzen zusammen.", - examples=[ - FewShotExample( - input="Auch für den Wirtschaftsstandort Baden-Württemberg stellt das Start-up-Ökosystem einen zentralen Erfolgsfaktor dar. Es zeichnet sich aktuell vor allem durch eine Vielzahl von sehr aktiven Standorten wie Mannheim, Karlsruhe und Stuttgart aus (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Allerdings entfallen gerade in Baden-Württemberg noch immer rund 30 % des Bruttoinlandsprodukts auf traditionelle Industrien, womit es wie auch andere Regionen massiv durch den Strukturwandel bedroht ist (Statistisches Landesamt Baden-Württemberg 2021).", - response="Da Baden-Württemberg stark von traditionellen Industrien abhängig ist, sind Start-Ups umso wichtiger. Sehr aktiv sind Start-Ups in Mannheim, Karlsruhe und Stuttgart.", - ), - FewShotExample( - input="Aus politischen Gründen vermeidet die Studie die Begriffe Land oder Staat, sondern gliedert nach Volkswirtschaften. In 185 Volkswirtschaften konnten die Autoren für 2020 sowie 2021 Preise für ein reines Daten-Mobilfunkprodukt erheben, das die genannten Minimalvoraussetzungen erfüllt. Dabei zeigt sich, dass der globale Durchschnittspreis um zwei Prozent auf 9,30 US-Dollar pro Monat gesunken ist. Die Entwicklung ist regional höchst unterschiedlich. In der Gemeinschaft Unabhängiger Staaten ist der Durchschnittspreis in nur einem Jahr um fast die Hälfte gestiegen, auf umgerechnet 5,70 US-Dollar. Auf den Amerika-Kontinenten gab es einen Preisanstieg um immerhin zehn Prozent auf durchschnittlich 14,70 US-Dollar. Während Verbraucher in wohlhabenden Volkswirtschaften sich über eine durchschnittliche Preissenkung von 13 Prozent auf 15,40 US-Dollar freuen durften, gab es für Konsumenten in weniger wohlhabenden Ländern keine Kostensenkung.", - response="Die Preise für reine Daten-Mobilfunkprodukte sind im Jahr 2021 weltweit um durchschnittlich zwei Prozent auf 9,30 USD gefallen. Am stärksten profitieren wohlhabende Regionen (13% Ersparnis), am wenigsten ärmere Regionen (keine Kostensenkung).", - ), - FewShotExample( - input="Einen Umsatzeinbruch von 29 Prozent musste Huawei 2021 hinnehmen. Kein Wunder, ist der chinesische Konzern doch US-Sanktionen ausgesetzt und kann keine neue Hard- noch Software aus den USA und einigen anderen westlichen Ländern beziehen. Auch die Exporte sind eingeschränkt. Dennoch meldet die Konzernzentrale in Shenzhen eine geringere Schuldenquote, um 68 Prozent gestiegenen Betriebsgewinn und gar um 76 Prozent höheren Reingewinn für 2021. Geht Huaweis Rekordgewinn trotz Umsatzeinbruchs als Wunder von Shenzhen in die Geschichtsbücher ein? Schlagen die wackeren Chinesen den technik-geizigen Amis ein Schnippchen? Erweisen sich die Exportverbote als Bumerang, der das US-Exportgeschäft schädigt, während Huawei gleichzeitig mehr Geld druckt als je zuvor?", - response="Huawei hat im Jahr 2021 einen Umsatzrückgang von 29 Prozent hinnehmen müssen, aber gleichzeitig stieg der Reingewinn um 76% und die Schuldenquote sank. Das ist ungewöhnlich.", - ), - ], - input_prefix="Text", - response_prefix="Zusammenfassung", - additional_stop_sequences=["\n"], - ), - Language("es"): FewShotConfig( - instruction="Resuma cada texto en una o tres frases.", - examples=[ - FewShotExample( - input="El ecosistema de las start-ups es también un factor clave para el éxito de Baden-Württemberg como lugar de negocios. Actualmente se caracteriza sobre todo por un gran número de localidades muy activas como Mannheim, Karlsruhe y Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Sin embargo, en Baden-Württemberg, en particular, las industrias tradicionales siguen representando alrededor del 30% del producto interior bruto, lo que significa que, al igual que otras regiones, está muy amenazada por el cambio estructural (Statistisches Landesamt Baden-Württemberg 2021).", - response="Dado que Baden-Württemberg depende en gran medida de las industrias tradicionales, las empresas de nueva creación son aún más importantes. Las start-ups son muy activas en Mannheim, Karlsruhe y Stuttgart.", - ), - FewShotExample( - input="Por razones políticas, el estudio evita los términos país o estado, sino que se desglosa por economías nacionales. En 185 economías, los autores pudieron estudiar los precios de un producto móvil de datos puros para 2020 y 2021 que cumple los requisitos mínimos mencionados. Los resultados muestran que el precio medio global ha bajado un 2%, hasta los 9,30 dólares mensuales. El desarrollo varía mucho de una región a otra. En la Comunidad de Estados Independientes, el precio medio ha subido casi la mitad en sólo un año, hasta el equivalente a 5,70 dólares estadounidenses. En el continente americano, el precio subió un diez por ciento, hasta una media de 14,70 dólares. Mientras que los consumidores de las economías ricas disfrutaron de una reducción media de precios del 13%, hasta los 15,40 dólares, los consumidores de los países menos ricos no vieron ninguna reducción de costes.", - response="Los precios de los productos de telefonía móvil de sólo datos cayeron una media del 2% en todo el mundo, hasta los 9,30 dólares en 2021. Las regiones ricas son las que más se benefician (13% de ahorro), y las más pobres las que menos (ninguna reducción de costes).", - ), - FewShotExample( - input="Huawei sufrió una caída del 29% en sus ventas en 2021. No es de extrañar, ya que la empresa china está sometida a sanciones estadounidenses y no puede obtener nuevo hardware o software de EE.UU. y algunos otros países occidentales. Las exportaciones también están restringidas. Sin embargo, la sede central de la empresa en Shenzhen informó de un menor ratio de endeudamiento, un aumento del 68% en el beneficio operativo e incluso un incremento del 76% en el beneficio neto para 2021. ¿Pasará el récord de beneficios de Huawei a los libros de historia como el Milagro de Shenzhen a pesar del desplome de las ventas? ¿Serán los valientes chinos capaces de burlar a los expertos en tecnología estadounidenses? ¿Las prohibiciones a las exportaciones están siendo un bumerán, perjudicando al negocio de las exportaciones estadounidenses, mientras que al mismo tiempo Huawei está imprimiendo más dinero que nunca?", - response="Los ingresos de Huawei en 2021 cayeron un 29%, pero al mismo tiempo el beneficio neto aumentó un 76% y su ratio de endeudamiento se redujo. Esto es inusual.", - ), - ], - input_prefix="Texto", - response_prefix="Resumen", - additional_stop_sequences=["\n"], - ), - Language("fr"): FewShotConfig( - instruction="Résume chaque texte en une à trois phrases.", - examples=[ - FewShotExample( - input="L'écosystème des start-ups représente également un facteur de succès central pour le site économique du Bade-Wurtemberg. Il se caractérise actuellement surtout par un grand nombre de sites très actifs comme Mannheim, Karlsruhe et Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Cependant, dans le Bade-Wurtemberg en particulier, les industries traditionnelles représentent encore environ 30 % du produit intérieur brut, ce qui fait que le Bade-Wurtemberg, comme d'autres régions, est massivement menacé par le changement structurel (Statistisches Landesamt Baden-Württemberg 2021).", - response="Le Bade-Wurtemberg étant fortement dépendant des industries traditionnelles, les start-ups sont d'autant plus importantes. Les start-ups sont très actives à Mannheim, Karlsruhe et Stuttgart.", - ), - FewShotExample( - input="Pour des raisons politiques, l'étude évite les termes de pays ou d'État, mais s'articule autour des économies nationales. Dans 185 économies, les auteurs ont pu relever les prix pour 2020 et 2021 d'un produit de téléphonie mobile de données pur qui remplit les conditions minimales mentionnées. Il en ressort que le prix moyen mondial a baissé de 2 % pour atteindre 9,30 dollars US par mois. L'évolution varie fortement d'une région à l'autre. Dans la Communauté des États indépendants, le prix moyen a augmenté de près de moitié en un an seulement, pour atteindre l'équivalent de 5,70 dollars américains. Sur le continent américain, les prix ont augmenté de 10 % pour atteindre 14,70 dollars en moyenne. Alors que les consommateurs des économies prospères ont pu se réjouir d'une baisse moyenne des prix de 13% à 15,40 dollars US, les consommateurs des pays moins prospères n'ont pas connu de baisse des coûts.", - response="Les prix des produits mobiles de données pures ont baissé en moyenne de 2 % dans le monde en 2021, pour atteindre 9,30 dollars. Ce sont les régions riches qui en profitent le plus (13% d'économies) et les régions pauvres qui en profitent le moins (aucune réduction des coûts).", - ), - FewShotExample( - input="Huawei a subi une chute de 29 pour cent de son chiffre d'affaires en 2021. Rien d'étonnant à cela, puisque le groupe chinois est soumis à des sanctions américaines et ne peut plus acheter de nouveaux matériels ou logiciels aux États-Unis et dans certains autres pays occidentaux. Les exportations sont également limitées. Malgré cela, le siège du groupe à Shenzhen annonce un taux d'endettement plus faible, un bénéfice d'exploitation en hausse de 68 pour cent et même un bénéfice net en hausse de 76 pour cent pour 2021. Le bénéfice record de Huawei malgré la chute du chiffre d'affaires entrera-t-il dans les livres d'histoire comme le miracle de Shenzhen ? Les braves Chinois déjouent-ils les ambitions technologiques des Américains ? Les interdictions d'exportation se révèlent-elles être un boomerang qui nuit au commerce d'exportation américain, alors que dans le même temps Huawei imprime plus d'argent que jamais ?", - response="Huawei a vu son chiffre d'affaires baisser de 29% en 2021, mais dans le même temps, son bénéfice net a augmenté de 76% et son taux d'endettement a baissé. C'est inhabituel.", - ), - ], - input_prefix="Texte", - response_prefix="Résumé", - additional_stop_sequences=["\n"], - ), - Language("it"): FewShotConfig( - instruction="Riassumete ogni testo in una o tre frasi.", - examples=[ - FewShotExample( - input="Anche l'ecosistema delle start-up è un fattore chiave di successo per il Baden-Württemberg come sede d'affari. Attualmente è caratterizzata soprattutto da un gran numero di località molto attive come Mannheim, Karlsruhe e Stoccarda (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Tuttavia, nel Baden-Württemberg in particolare, le industrie tradizionali rappresentano ancora circa il 30% del prodotto interno lordo, il che significa che, come altre regioni, è fortemente minacciato dal cambiamento strutturale (Statistisches Landesamt Baden-Württemberg 2021).", - response="Poiché il Baden-Württemberg è fortemente dipendente dalle industrie tradizionali, le start-up sono ancora più importanti. Le start-up sono molto attive a Mannheim, Karlsruhe e Stoccarda.", - ), - FewShotExample( - input="Per ragioni politiche, lo studio evita i termini paese o stato, ma suddivide per economie nazionali. In 185 economie, gli autori sono stati in grado di rilevare i prezzi di un prodotto mobile di dati puro per il 2020 e il 2021 che soddisfa i requisiti minimi citati. I risultati mostrano che il prezzo medio globale è sceso del 2% a 9,30 dollari USA al mese. Lo sviluppo varia notevolmente da regione a regione. Nella Comunità degli Stati Indipendenti, il prezzo medio è aumentato di quasi la metà in un solo anno, fino all'equivalente di 5,70 dollari USA. Nelle Americhe, i prezzi sono aumentati fino al 10%, raggiungendo una media di 14,70 dollari USA. Mentre i consumatori delle economie ricche hanno beneficiato di una riduzione media dei prezzi del 13%, passando a 15,40 dollari USA, i consumatori dei Paesi meno ricchi non hanno registrato alcuna riduzione dei costi.", - response="I prezzi dei prodotti di telefonia mobile solo dati sono diminuiti in media del 2% a livello globale, raggiungendo i 9,30 dollari nel 2021. Le regioni ricche sono quelle che ne hanno beneficiato di più (13% di risparmio), quelle più povere di meno (nessuna riduzione dei costi).", - ), - FewShotExample( - input="Huawei ha subito un crollo delle vendite del 29% nel 2021. Non c'è da stupirsi, visto che l'azienda cinese è soggetta a sanzioni statunitensi e non può ottenere nuovo hardware o software dagli Stati Uniti e da alcuni altri Paesi occidentali. Anche le esportazioni sono limitate. Ciononostante, la sede centrale dell'azienda a Shenzhen ha registrato un rapporto di indebitamento più basso, un aumento del 68% dell'utile operativo e addirittura un aumento del 76% dell'utile netto per il 2021. Il profitto record di Huawei entrerà nei libri di storia come il miracolo di Shenzhen nonostante il crollo delle vendite? Riusciranno i coraggiosi cinesi a superare in astuzia gli americani esperti di tecnologia? I divieti all'esportazione si stanno rivelando un boomerang, danneggiando l'attività di esportazione degli Stati Uniti, mentre allo stesso tempo Huawei sta stampando più denaro che mai?", - response="Il fatturato di Huawei nel 2021 è sceso del 29%, ma allo stesso tempo l'utile netto è aumentato del 76% e il rapporto di indebitamento è diminuito. È un fatto insolito.", - ), - ], - input_prefix="Testo", - response_prefix="Sintesi", - additional_stop_sequences=["\n"], - ), -} - - -class LongContextMediumCompressionSummarize(LongContextFewShotSummarize): - """Condenses a text into a summary of medium length. - - Leverages few-shot prompting to generate a summary. - - Args: - client: Aleph Alpha client instance for running model related API calls. - fallback_language: The default language of the output. - - - Example: - >>> import os - >>> from intelligence_layer.connectors import ( - ... LimitedConcurrencyClient, - ... ) - >>> from intelligence_layer.core import InMemoryTracer - >>> from intelligence_layer.use_cases import ( - ... LongContextMediumCompressionSummarize, - ... ) - >>> from intelligence_layer.use_cases import LongContextSummarizeInput - - - >>> client = LimitedConcurrencyClient.from_token(os.getenv("AA_TOKEN")) - >>> task = LongContextMediumCompressionSummarize(client) - >>> input = LongContextSummarizeInput( - ... text="This is a story about pizza. Tina hates pizza. However, Mike likes it. Pete strongly believes that pizza is the best thing to exist." - ... ) - >>> tracer = InMemoryTracer() - >>> output = task.run(input, tracer) - """ - - def __init__( - self, client: AlephAlphaClientProtocol, model: str = "luminous-extended" - ) -> None: - super().__init__( - client, - FEW_SHOT_CONFIGS, - model=model, - max_generated_tokens=128, - max_tokens_per_chunk=400, - ) diff --git a/src/intelligence_layer/use_cases/summarize/single_chunk_few_shot_summarize.py b/src/intelligence_layer/use_cases/summarize/single_chunk_few_shot_summarize.py deleted file mode 100644 index 1eef1e55e..000000000 --- a/src/intelligence_layer/use_cases/summarize/single_chunk_few_shot_summarize.py +++ /dev/null @@ -1,165 +0,0 @@ -from typing import Mapping - -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) -from intelligence_layer.core.complete import ( - FewShot, - FewShotConfig, - FewShotExample, - FewShotInput, - PromptOutput, -) -from intelligence_layer.core.detect_language import Language -from intelligence_layer.core.task import Task -from intelligence_layer.core.tracer import TaskSpan -from intelligence_layer.use_cases.summarize.summarize import ( - SingleChunkSummarizeInput, - SummarizeOutput, -) - -FEW_SHOT_CONFIGS = { - Language("en"): FewShotConfig( - instruction="Summarize each text in one to three sentences.", - examples=[ - FewShotExample( - input="The startup ecosystem also represents a key success factor for Baden-Württemberg as a business location. It is currently characterized above all by a large number of very active locations such as Mannheim, Karlsruhe and Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). However, in Baden-Württemberg in particular, traditional industries still account for around 30% of gross domestic product, which means that, like other regions, it is massively threatened by structural change (Statistisches Landesamt Baden-Württemberg 2021).", - response="Since Baden-Württemberg is heavily dependent on traditional industries, startups are all the more important. Start-ups are very active in Mannheim, Karlsruhe and Stuttgart.", - ), - FewShotExample( - input="For political reasons, the study avoids the terms country or state, but breaks down by national economies. In 185 economies, the authors were able to survey prices for a pure data mobile product that meets the minimum requirements mentioned for 2020 as well as 2021. The results show that the global average price has fallen by two percent to USD 9.30 per month. The development varies greatly from region to region. In the Commonwealth of Independent States, the average price has risen by almost half in just one year, to the equivalent of 5.70 US dollars. In the Americas, prices have risen by ten percent to an average of $14.70. While consumers in wealthy economies enjoyed an average price reduction of 13 percent to USD 15.40, there was no cost reduction for consumers in less wealthy countries.", - response="Prices for data-only mobile products fell by an average of two percent globally to USD 9.30 in 2021. Affluent regions benefited most (13% savings), poorer regions least (no cost reduction).", - ), - FewShotExample( - input="Huawei suffered a 29 percent drop in sales in 2021. No wonder, since the Chinese company is subject to U.S. sanctions and cannot obtain new hardware or software from the U.S. and some other Western countries. Exports are also restricted. Nevertheless, the company's headquarters in Shenzhen reported a lower debt ratio, a 68 percent increase in operating profit and even a 76 percent increase in net profit for 2021. Will Huawei's record profit go down in the history books as the Miracle of Shenzhen despite the slump in sales? Will the brave Chinese be able to outsmart the tech-hungry Americans? Are export bans proving to be a boomerang, hurting the U.S. export business while Huawei prints more money than ever before?", - response="Huawei's 2021 revenue fell 29%, but at the same time net profit rose 76% and its debt ratio fell. That's unusual.", - ), - ], - input_prefix="Text", - response_prefix="Summary", - ), - Language("de"): FewShotConfig( - instruction="Fasse jeden Text in ein bis drei Sätzen zusammen.", - examples=[ - FewShotExample( - input="Auch für den Wirtschaftsstandort Baden-Württemberg stellt das Start-up-Ökosystem einen zentralen Erfolgsfaktor dar. Es zeichnet sich aktuell vor allem durch eine Vielzahl von sehr aktiven Standorten wie Mannheim, Karlsruhe und Stuttgart aus (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Allerdings entfallen gerade in Baden-Württemberg noch immer rund 30 % des Bruttoinlandsprodukts auf traditionelle Industrien, womit es wie auch andere Regionen massiv durch den Strukturwandel bedroht ist (Statistisches Landesamt Baden-Württemberg 2021).", - response="Da Baden-Württemberg stark von traditionellen Industrien abhängig ist, sind Start-Ups umso wichtiger. Sehr aktiv sind Start-Ups in Mannheim, Karlsruhe und Stuttgart.", - ), - FewShotExample( - input="Aus politischen Gründen vermeidet die Studie die Begriffe Land oder Staat, sondern gliedert nach Volkswirtschaften. In 185 Volkswirtschaften konnten die Autoren für 2020 sowie 2021 Preise für ein reines Daten-Mobilfunkprodukt erheben, das die genannten Minimalvoraussetzungen erfüllt. Dabei zeigt sich, dass der globale Durchschnittspreis um zwei Prozent auf 9,30 US-Dollar pro Monat gesunken ist. Die Entwicklung ist regional höchst unterschiedlich. In der Gemeinschaft Unabhängiger Staaten ist der Durchschnittspreis in nur einem Jahr um fast die Hälfte gestiegen, auf umgerechnet 5,70 US-Dollar. Auf den Amerika-Kontinenten gab es einen Preisanstieg um immerhin zehn Prozent auf durchschnittlich 14,70 US-Dollar. Während Verbraucher in wohlhabenden Volkswirtschaften sich über eine durchschnittliche Preissenkung von 13 Prozent auf 15,40 US-Dollar freuen durften, gab es für Konsumenten in weniger wohlhabenden Ländern keine Kostensenkung.", - response="Die Preise für reine Daten-Mobilfunkprodukte sind im Jahr 2021 weltweit um durchschnittlich zwei Prozent auf 9,30 USD gefallen. Am stärksten profitieren wohlhabende Regionen (13% Ersparnis), am wenigsten ärmere Regionen (keine Kostensenkung).", - ), - FewShotExample( - input="Einen Umsatzeinbruch von 29 Prozent musste Huawei 2021 hinnehmen. Kein Wunder, ist der chinesische Konzern doch US-Sanktionen ausgesetzt und kann keine neue Hard- noch Software aus den USA und einigen anderen westlichen Ländern beziehen. Auch die Exporte sind eingeschränkt. Dennoch meldet die Konzernzentrale in Shenzhen eine geringere Schuldenquote, um 68 Prozent gestiegenen Betriebsgewinn und gar um 76 Prozent höheren Reingewinn für 2021. Geht Huaweis Rekordgewinn trotz Umsatzeinbruchs als Wunder von Shenzhen in die Geschichtsbücher ein? Schlagen die wackeren Chinesen den technik-geizigen Amis ein Schnippchen? Erweisen sich die Exportverbote als Bumerang, der das US-Exportgeschäft schädigt, während Huawei gleichzeitig mehr Geld druckt als je zuvor?", - response="Huawei hat im Jahr 2021 einen Umsatzrückgang von 29 Prozent hinnehmen müssen, aber gleichzeitig stieg der Reingewinn um 76% und die Schuldenquote sank. Das ist ungewöhnlich.", - ), - ], - input_prefix="Text", - response_prefix="Zusammenfassung", - ), - Language("es"): FewShotConfig( - instruction="Resuma cada texto en una o tres frases.", - examples=[ - FewShotExample( - input="El ecosistema de las start-ups es también un factor clave para el éxito de Baden-Württemberg como lugar de negocios. Actualmente se caracteriza sobre todo por un gran número de localidades muy activas como Mannheim, Karlsruhe y Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Sin embargo, en Baden-Württemberg, en particular, las industrias tradicionales siguen representando alrededor del 30% del producto interior bruto, lo que significa que, al igual que otras regiones, está muy amenazada por el cambio estructural (Statistisches Landesamt Baden-Württemberg 2021).", - response="Dado que Baden-Württemberg depende en gran medida de las industrias tradicionales, las empresas de nueva creación son aún más importantes. Las start-ups son muy activas en Mannheim, Karlsruhe y Stuttgart.", - ), - FewShotExample( - input="Por razones políticas, el estudio evita los términos país o estado, sino que se desglosa por economías nacionales. En 185 economías, los autores pudieron estudiar los precios de un producto móvil de datos puros para 2020 y 2021 que cumple los requisitos mínimos mencionados. Los resultados muestran que el precio medio global ha bajado un 2%, hasta los 9,30 dólares mensuales. El desarrollo varía mucho de una región a otra. En la Comunidad de Estados Independientes, el precio medio ha subido casi la mitad en sólo un año, hasta el equivalente a 5,70 dólares estadounidenses. En el continente americano, el precio subió un diez por ciento, hasta una media de 14,70 dólares. Mientras que los consumidores de las economías ricas disfrutaron de una reducción media de precios del 13%, hasta los 15,40 dólares, los consumidores de los países menos ricos no vieron ninguna reducción de costes.", - response="Los precios de los productos de telefonía móvil de sólo datos cayeron una media del 2% en todo el mundo, hasta los 9,30 dólares en 2021. Las regiones ricas son las que más se benefician (13% de ahorro), y las más pobres las que menos (ninguna reducción de costes).", - ), - FewShotExample( - input="Huawei sufrió una caída del 29% en sus ventas en 2021. No es de extrañar, ya que la empresa china está sometida a sanciones estadounidenses y no puede obtener nuevo hardware o software de EE.UU. y algunos otros países occidentales. Las exportaciones también están restringidas. Sin embargo, la sede central de la empresa en Shenzhen informó de un menor ratio de endeudamiento, un aumento del 68% en el beneficio operativo e incluso un incremento del 76% en el beneficio neto para 2021. ¿Pasará el récord de beneficios de Huawei a los libros de historia como el Milagro de Shenzhen a pesar del desplome de las ventas? ¿Serán los valientes chinos capaces de burlar a los expertos en tecnología estadounidenses? ¿Las prohibiciones a las exportaciones están siendo un bumerán, perjudicando al negocio de las exportaciones estadounidenses, mientras que al mismo tiempo Huawei está imprimiendo más dinero que nunca?", - response="Los ingresos de Huawei en 2021 cayeron un 29%, pero al mismo tiempo el beneficio neto aumentó un 76% y su ratio de endeudamiento se redujo. Esto es inusual.", - ), - ], - input_prefix="Texto", - response_prefix="Resumen", - ), - Language("fr"): FewShotConfig( - instruction="Résume chaque texte en une à trois phrases.", - examples=[ - FewShotExample( - input="L'écosystème des start-ups représente également un facteur de succès central pour le site économique du Bade-Wurtemberg. Il se caractérise actuellement surtout par un grand nombre de sites très actifs comme Mannheim, Karlsruhe et Stuttgart (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Cependant, dans le Bade-Wurtemberg en particulier, les industries traditionnelles représentent encore environ 30 % du produit intérieur brut, ce qui fait que le Bade-Wurtemberg, comme d'autres régions, est massivement menacé par le changement structurel (Statistisches Landesamt Baden-Württemberg 2021).", - response="Le Bade-Wurtemberg étant fortement dépendant des industries traditionnelles, les start-ups sont d'autant plus importantes. Les start-ups sont très actives à Mannheim, Karlsruhe et Stuttgart.", - ), - FewShotExample( - input="Pour des raisons politiques, l'étude évite les termes de pays ou d'État, mais s'articule autour des économies nationales. Dans 185 économies, les auteurs ont pu relever les prix pour 2020 et 2021 d'un produit de téléphonie mobile de données pur qui remplit les conditions minimales mentionnées. Il en ressort que le prix moyen mondial a baissé de 2 % pour atteindre 9,30 dollars US par mois. L'évolution varie fortement d'une région à l'autre. Dans la Communauté des États indépendants, le prix moyen a augmenté de près de moitié en un an seulement, pour atteindre l'équivalent de 5,70 dollars américains. Sur le continent américain, les prix ont augmenté de 10 % pour atteindre 14,70 dollars en moyenne. Alors que les consommateurs des économies prospères ont pu se réjouir d'une baisse moyenne des prix de 13% à 15,40 dollars US, les consommateurs des pays moins prospères n'ont pas connu de baisse des coûts.", - response="Les prix des produits mobiles de données pures ont baissé en moyenne de 2 % dans le monde en 2021, pour atteindre 9,30 dollars. Ce sont les régions riches qui en profitent le plus (13% d'économies) et les régions pauvres qui en profitent le moins (aucune réduction des coûts).", - ), - FewShotExample( - input="Huawei a subi une chute de 29 pour cent de son chiffre d'affaires en 2021. Rien d'étonnant à cela, puisque le groupe chinois est soumis à des sanctions américaines et ne peut plus acheter de nouveaux matériels ou logiciels aux États-Unis et dans certains autres pays occidentaux. Les exportations sont également limitées. Malgré cela, le siège du groupe à Shenzhen annonce un taux d'endettement plus faible, un bénéfice d'exploitation en hausse de 68 pour cent et même un bénéfice net en hausse de 76 pour cent pour 2021. Le bénéfice record de Huawei malgré la chute du chiffre d'affaires entrera-t-il dans les livres d'histoire comme le miracle de Shenzhen ? Les braves Chinois déjouent-ils les ambitions technologiques des Américains ? Les interdictions d'exportation se révèlent-elles être un boomerang qui nuit au commerce d'exportation américain, alors que dans le même temps Huawei imprime plus d'argent que jamais ?", - response="Huawei a vu son chiffre d'affaires baisser de 29% en 2021, mais dans le même temps, son bénéfice net a augmenté de 76% et son taux d'endettement a baissé. C'est inhabituel.", - ), - ], - input_prefix="Texte", - response_prefix="Résumé", - ), - Language("it"): FewShotConfig( - instruction="Riassumete ogni testo in una o tre frasi.", - examples=[ - FewShotExample( - input="Anche l'ecosistema delle start-up è un fattore chiave di successo per il Baden-Württemberg come sede d'affari. Attualmente è caratterizzata soprattutto da un gran numero di località molto attive come Mannheim, Karlsruhe e Stoccarda (Kollmann et al. 2020, Bundesverband Deutsche Startups e.V. 2021a). Tuttavia, nel Baden-Württemberg in particolare, le industrie tradizionali rappresentano ancora circa il 30% del prodotto interno lordo, il che significa che, come altre regioni, è fortemente minacciato dal cambiamento strutturale (Statistisches Landesamt Baden-Württemberg 2021).", - response="Poiché il Baden-Württemberg è fortemente dipendente dalle industrie tradizionali, le start-up sono ancora più importanti. Le start-up sono molto attive a Mannheim, Karlsruhe e Stoccarda.", - ), - FewShotExample( - input="Per ragioni politiche, lo studio evita i termini paese o stato, ma suddivide per economie nazionali. In 185 economie, gli autori sono stati in grado di rilevare i prezzi di un prodotto mobile di dati puro per il 2020 e il 2021 che soddisfa i requisiti minimi citati. I risultati mostrano che il prezzo medio globale è sceso del 2% a 9,30 dollari USA al mese. Lo sviluppo varia notevolmente da regione a regione. Nella Comunità degli Stati Indipendenti, il prezzo medio è aumentato di quasi la metà in un solo anno, fino all'equivalente di 5,70 dollari USA. Nelle Americhe, i prezzi sono aumentati fino al 10%, raggiungendo una media di 14,70 dollari USA. Mentre i consumatori delle economie ricche hanno beneficiato di una riduzione media dei prezzi del 13%, passando a 15,40 dollari USA, i consumatori dei Paesi meno ricchi non hanno registrato alcuna riduzione dei costi.", - response="I prezzi dei prodotti di telefonia mobile solo dati sono diminuiti in media del 2% a livello globale, raggiungendo i 9,30 dollari nel 2021. Le regioni ricche sono quelle che ne hanno beneficiato di più (13% di risparmio), quelle più povere di meno (nessuna riduzione dei costi).", - ), - FewShotExample( - input="Huawei ha subito un crollo delle vendite del 29% nel 2021. Non c'è da stupirsi, visto che l'azienda cinese è soggetta a sanzioni statunitensi e non può ottenere nuovo hardware o software dagli Stati Uniti e da alcuni altri Paesi occidentali. Anche le esportazioni sono limitate. Ciononostante, la sede centrale dell'azienda a Shenzhen ha registrato un rapporto di indebitamento più basso, un aumento del 68% dell'utile operativo e addirittura un aumento del 76% dell'utile netto per il 2021. Il profitto record di Huawei entrerà nei libri di storia come il miracolo di Shenzhen nonostante il crollo delle vendite? Riusciranno i coraggiosi cinesi a superare in astuzia gli americani esperti di tecnologia? I divieti all'esportazione si stanno rivelando un boomerang, danneggiando l'attività di esportazione degli Stati Uniti, mentre allo stesso tempo Huawei sta stampando più denaro che mai?", - response="Il fatturato di Huawei nel 2021 è sceso del 29%, ma allo stesso tempo l'utile netto è aumentato del 76% e il rapporto di indebitamento è diminuito. È un fatto insolito.", - ), - ], - input_prefix="Testo", - response_prefix="Sintesi", - ), -} - - -class SingleChunkFewShotSummarize(Task[SingleChunkSummarizeInput, SummarizeOutput]): - """Summarises a text using a few-shot setup. - - Args: - client: Aleph Alpha client instance for running model related API calls. - few_shot_configs: A mapping of valid `Language` to `FewShotConfig` for each - supported language. - model: A valid Aleph Alpha model name. - maximum_tokens: The maximum number of tokens to be generated. - """ - - def __init__( - self, - client: AlephAlphaClientProtocol, - model: str, - maximum_tokens: int, - few_shot_configs: Mapping[Language, FewShotConfig] = FEW_SHOT_CONFIGS, - ) -> None: - self._few_shot_configs = few_shot_configs - self._few_shot = FewShot(client, model) - self._model = model - self._maximum_tokens = maximum_tokens - - def do_run( - self, input: SingleChunkSummarizeInput, task_span: TaskSpan - ) -> SummarizeOutput: - prompt_output = self._get_prompt_and_complete(input, task_span) - return SummarizeOutput( - summary=prompt_output.completion.strip(), - generated_tokens=prompt_output.generated_tokens, - ) - - def _get_prompt_and_complete( - self, input: SingleChunkSummarizeInput, task_span: TaskSpan - ) -> PromptOutput: - prompt_config = self._few_shot_configs.get(input.language) - if not prompt_config: - raise ValueError(f"Could not find `prompt_config` for {input.language}.") - return self._few_shot.run( - FewShotInput( - few_shot_config=prompt_config, - input=input.chunk, - maximum_response_tokens=self._maximum_tokens, - ), - task_span, - ) diff --git a/src/intelligence_layer/use_cases/summarize/steerable_single_chunk_summarize.py b/src/intelligence_layer/use_cases/summarize/steerable_single_chunk_summarize.py index 17d615e4d..0da93bcf7 100644 --- a/src/intelligence_layer/use_cases/summarize/steerable_single_chunk_summarize.py +++ b/src/intelligence_layer/use_cases/summarize/steerable_single_chunk_summarize.py @@ -4,7 +4,6 @@ AlephAlphaClientProtocol, ) from intelligence_layer.core import Language, Task, TaskSpan -from intelligence_layer.core.complete import Instruct, InstructInput, PromptOutput from intelligence_layer.use_cases.summarize.summarize import ( SingleChunkSummarizeInput, SummarizeOutput, diff --git a/tests/conftest.py b/tests/conftest.py index 5e8edaa77..7e82cf0a8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,6 +27,7 @@ RetrieverType, ) from intelligence_layer.core import NoOpTracer, Task, TaskSpan +from intelligence_layer.core.model import AlephAlphaModel, LuminousControlModel from intelligence_layer.evaluation import ( InMemoryDatasetRepository, InMemoryEvaluationRepository, @@ -37,6 +38,11 @@ ) +@fixture +def luminous_control_model() -> LuminousControlModel: + return LuminousControlModel("luminous-base-control-20240215") + + @fixture(scope="session") def token() -> str: load_dotenv() diff --git a/tests/core/test_complete.py b/tests/core/test_complete.py deleted file mode 100644 index cf9e10249..000000000 --- a/tests/core/test_complete.py +++ /dev/null @@ -1,58 +0,0 @@ -from aleph_alpha_client import Text -from pytest import fixture - -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) -from intelligence_layer.core.complete import ( - FewShot, - FewShotConfig, - FewShotExample, - FewShotInput, - Instruct, - InstructInput, -) -from intelligence_layer.core.tracer import NoOpTracer - - -@fixture -def instruct(client: AlephAlphaClientProtocol) -> Instruct: - return Instruct(client, model="luminous-base-control") - - -@fixture -def few_shot(client: AlephAlphaClientProtocol) -> FewShot: - return FewShot(client, model="luminous-base") - - -def test_instruct_without_input(instruct: Instruct, no_op_tracer: NoOpTracer) -> None: - input = InstructInput( - instruction="What is the capital of Germany?", - input=None, - ) - output = instruct.run(input, no_op_tracer) - - assert "Berlin" in output.completion - prompt_text_item = output.rich_prompt.items[0] - assert isinstance(prompt_text_item, Text) - assert "Input" not in prompt_text_item.text - - -def test_few_shot(few_shot: FewShot, no_op_tracer: NoOpTracer) -> None: - input = FewShotInput( - input="What is the capital of Germany?", - few_shot_config=FewShotConfig( - instruction="Answer each question.", - examples=[ - FewShotExample( - input="How high is Mount Everest?", response="8848 metres." - ), - FewShotExample(input="When was Caesar killed?", response="44 AD."), - ], - input_prefix="Question", - response_prefix="Answer", - ), - ) - output = few_shot.run(input, no_op_tracer) - - assert "Berlin" in output.completion diff --git a/tests/core/test_echo.py b/tests/core/test_echo.py index 9852671f0..17eb73e0f 100644 --- a/tests/core/test_echo.py +++ b/tests/core/test_echo.py @@ -8,7 +8,6 @@ from intelligence_layer.connectors.limited_concurrency_client import ( AlephAlphaClientProtocol, ) -from intelligence_layer.core.complete import Complete, CompleteInput, CompleteOutput from intelligence_layer.core.echo import EchoInput, EchoTask, TokenWithLogProb from intelligence_layer.core.task import MAX_CONCURRENCY, Task, Token from intelligence_layer.core.tracer import NoOpTracer, TaskSpan diff --git a/tests/core/test_model.py b/tests/core/test_model.py index 727a1925d..7c249d8b8 100644 --- a/tests/core/test_model.py +++ b/tests/core/test_model.py @@ -4,19 +4,25 @@ from intelligence_layer.connectors.limited_concurrency_client import ( AlephAlphaClientProtocol, ) -from intelligence_layer.core.model import AlephAlphaModel, CompleteInput, ControlModel +from intelligence_layer.core.model import ( + AlephAlphaModel, + CompleteInput, + LuminousControlModel, +) from intelligence_layer.core.tracer import NoOpTracer @fixture def model(client: AlephAlphaClientProtocol) -> AlephAlphaModel: - return ControlModel(client=client, model="luminous-base-control-20240215") + return LuminousControlModel(client=client, model="luminous-base-control-20240215") def test_model_without_input(model: AlephAlphaModel, no_op_tracer: NoOpTracer) -> None: prompt = model.to_instruct_prompt("What is the capital of Germany?") - input = CompleteInput(request=CompletionRequest(prompt=prompt)) + input = CompleteInput(prompt=prompt) + assert isinstance(input.model_dump(), dict) output = model.complete(input, no_op_tracer) + assert isinstance(output.model_dump(), dict) assert "Berlin" in output.completion prompt_text_item = prompt.items[0] diff --git a/tests/core/test_text_highlight.py b/tests/core/test_text_highlight.py index 1efd162aa..8b5780846 100644 --- a/tests/core/test_text_highlight.py +++ b/tests/core/test_text_highlight.py @@ -1,17 +1,15 @@ from aleph_alpha_client import Image from pytest import fixture, raises -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) +from intelligence_layer.core.model import LuminousControlModel from intelligence_layer.core.prompt_template import PromptTemplate from intelligence_layer.core.text_highlight import TextHighlight, TextHighlightInput from intelligence_layer.core.tracer import NoOpTracer @fixture -def text_highlight(client: AlephAlphaClientProtocol) -> TextHighlight: - return TextHighlight(client) +def text_highlight(luminous_control_model: LuminousControlModel) -> TextHighlight: + return TextHighlight(luminous_control_model) def test_text_highlight(text_highlight: TextHighlight) -> None: @@ -28,7 +26,6 @@ def test_text_highlight(text_highlight: TextHighlight) -> None: input = TextHighlightInput( rich_prompt=prompt_with_metadata, target=answer, - model=model, focus_ranges=frozenset({"r1"}), ) output = text_highlight.run(input, NoOpTracer()) @@ -58,7 +55,6 @@ def test_text_highlight_with_range_without_highlight( input = TextHighlightInput( rich_prompt=prompt_with_metadata, target=f" {answer}", - model="luminous-base", focus_ranges=frozenset(["no_content"]), ) output = text_highlight.run(input, NoOpTracer()) @@ -71,12 +67,10 @@ def test_text_highlight_with_only_one_sentence(text_highlight: TextHighlight) -> template = PromptTemplate(prompt_template_str) prompt_with_metadata = template.to_rich_prompt() completion = " Ursus Arctos" - model = "luminous-base" input = TextHighlightInput( rich_prompt=prompt_with_metadata, target=completion, - model=model, focus_ranges=frozenset({"r1"}), ) output = text_highlight.run(input, NoOpTracer()) @@ -97,11 +91,8 @@ def test_text_highlight_with_image_prompt( image=template.placeholder(prompt_image) ) completion = " The latin name of the brown bear is Ursus arctos." - model = "luminous-base" - input = TextHighlightInput( - rich_prompt=prompt_with_metadata, target=completion, model=model - ) + input = TextHighlightInput(rich_prompt=prompt_with_metadata, target=completion) output = text_highlight.run(input, NoOpTracer()) assert output.highlights @@ -120,11 +111,8 @@ def test_text_highlight_without_range( image=template.placeholder(prompt_image) ) completion = " The latin name of the brown bear is Ursus arctos." - model = "luminous-base" - input = TextHighlightInput( - rich_prompt=prompt_with_metadata, target=completion, model=model - ) + input = TextHighlightInput(rich_prompt=prompt_with_metadata, target=completion) output = text_highlight.run(input, NoOpTracer()) assert output.highlights @@ -145,13 +133,11 @@ def test_text_highlight_without_focus_range_highlights_entire_prompt( image=template.placeholder(prompt_image) ) answer = " Extreme conditions." - model = "luminous-base" focus_ranges: frozenset[str] = frozenset() # empty input = TextHighlightInput( rich_prompt=prompt_with_metadata, target=answer, - model=model, focus_ranges=focus_ranges, ) output = text_highlight.run(input, NoOpTracer()) @@ -174,13 +160,11 @@ def test_text_highlight_with_unknown_range_raises( template = PromptTemplate(prompt_template_str) prompt_with_metadata = template.to_rich_prompt() answer = " Extreme conditions." - model = "luminous-base" unknown_range_name = "bla" input = TextHighlightInput( rich_prompt=prompt_with_metadata, target=answer, - model=model, focus_ranges=frozenset([unknown_range_name]), ) with raises(ValueError) as e: diff --git a/tests/evaluation/test_instruct_comparison_argilla_evaluator.py b/tests/evaluation/test_instruct_comparison_argilla_evaluator.py index aa88f0bc4..271a16cd1 100644 --- a/tests/evaluation/test_instruct_comparison_argilla_evaluator.py +++ b/tests/evaluation/test_instruct_comparison_argilla_evaluator.py @@ -15,7 +15,6 @@ Question, RecordData, ) -from intelligence_layer.core.complete import InstructInput, PromptOutput from intelligence_layer.core.prompt_template import RichPrompt from intelligence_layer.core.tracer import utc_now from intelligence_layer.evaluation import ( diff --git a/tests/use_cases/classify/test_keyword_extract.py b/tests/use_cases/classify/test_keyword_extract.py index 5e59c6652..1ef296816 100644 --- a/tests/use_cases/classify/test_keyword_extract.py +++ b/tests/use_cases/classify/test_keyword_extract.py @@ -1,8 +1,5 @@ import pytest -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) from intelligence_layer.core.chunk import Chunk from intelligence_layer.core.detect_language import Language, LanguageNotSupportedError from intelligence_layer.core.tracer import NoOpTracer @@ -13,17 +10,17 @@ @pytest.fixture() -def keyword_extract(client: AlephAlphaClientProtocol) -> KeywordExtract: - return KeywordExtract(client) +def keyword_extract() -> KeywordExtract: + return KeywordExtract() def test_keyword_extract_works(keyword_extract: KeywordExtract) -> None: input = KeywordExtractInput( - chunk=Chunk("text about computers"), language=Language("en") + chunk=Chunk("I really like my computer"), language=Language("en") ) result = keyword_extract.run(input, NoOpTracer()) - assert "computers" in [keyword.lower() for keyword in result.keywords] + assert "computer" in [keyword.lower() for keyword in result.keywords] def test_keyword_extract_raises_for_unsupported_language( diff --git a/tests/use_cases/qa/conftest.py b/tests/use_cases/qa/conftest.py index 69088c468..8631316fc 100644 --- a/tests/use_cases/qa/conftest.py +++ b/tests/use_cases/qa/conftest.py @@ -1,11 +1,8 @@ from pytest import fixture -from intelligence_layer.connectors.limited_concurrency_client import ( - AlephAlphaClientProtocol, -) from intelligence_layer.use_cases.qa.single_chunk_qa import SingleChunkQa @fixture -def single_chunk_qa(client: AlephAlphaClientProtocol) -> SingleChunkQa: - return SingleChunkQa(client) +def single_chunk_qa() -> SingleChunkQa: + return SingleChunkQa() diff --git a/tests/use_cases/qa/test_multiple_chunk_qa.py b/tests/use_cases/qa/test_multiple_chunk_qa.py index e62d9d36a..232d5d2fb 100644 --- a/tests/use_cases/qa/test_multiple_chunk_qa.py +++ b/tests/use_cases/qa/test_multiple_chunk_qa.py @@ -15,8 +15,8 @@ @fixture -def qa(client: AlephAlphaClientProtocol) -> MultipleChunkQa: - return MultipleChunkQa(client) +def multiple_chunk_qa() -> MultipleChunkQa: + return MultipleChunkQa() CHUNK_CONTAINING_ANSWER = Chunk( @@ -34,11 +34,13 @@ def qa(client: AlephAlphaClientProtocol) -> MultipleChunkQa: UNRELATED_QUESTION = "What is the the capital of Germany?" -def test_multiple_chunk_qa_with_mulitple_chunks(qa: MultipleChunkQa) -> None: +def test_multiple_chunk_qa_with_mulitple_chunks( + multiple_chunk_qa: MultipleChunkQa, +) -> None: chunks: Sequence[Chunk] = [CHUNK_CONTAINING_ANSWER, RELATED_CHUNK_WITHOUT_ANSWER] input = MultipleChunkQaInput(chunks=chunks, question=RELATED_QUESTION) - output = qa.run(input, NoOpTracer()) + output = multiple_chunk_qa.run(input, NoOpTracer()) assert output.answer assert IMPORTANT_PART_OF_CORRECT_ANSWER in output.answer @@ -50,23 +52,25 @@ def test_multiple_chunk_qa_with_mulitple_chunks(qa: MultipleChunkQa) -> None: ) -def test_multiple_chunk_qa_without_answer(qa: MultipleChunkQa) -> None: +def test_multiple_chunk_qa_without_answer(multiple_chunk_qa: MultipleChunkQa) -> None: chunks: Sequence[Chunk] = [CHUNK_CONTAINING_ANSWER] input = MultipleChunkQaInput(chunks=chunks, question=UNRELATED_QUESTION) - output = qa.run(input, NoOpTracer()) + output = multiple_chunk_qa.run(input, NoOpTracer()) assert output.answer is None -def test_multiple_chunk_qa_with_spanish_question(qa: MultipleChunkQa) -> None: +def test_multiple_chunk_qa_with_spanish_question( + multiple_chunk_qa: MultipleChunkQa, +) -> None: question = "¿Cómo se llama el hermano de Paul Nicola?" chunks = [CHUNK_CONTAINING_ANSWER, CHUNK_CONTAINING_ANSWER] input = MultipleChunkQaInput( chunks=chunks, question=question, language=Language("es") ) - output = qa.run(input, NoOpTracer()) + output = multiple_chunk_qa.run(input, NoOpTracer()) assert len(output.subanswers) == len(chunks) assert output.answer diff --git a/tests/use_cases/summarize/conftest.py b/tests/use_cases/summarize/conftest.py index 0dcefb195..34c29f93e 100644 --- a/tests/use_cases/summarize/conftest.py +++ b/tests/use_cases/summarize/conftest.py @@ -4,19 +4,19 @@ AlephAlphaClientProtocol, ) from intelligence_layer.core.chunk import Chunk -from intelligence_layer.use_cases.summarize.long_context_high_compression_summarize import ( - LongContextHighCompressionSummarize, +from intelligence_layer.use_cases.summarize.steerable_long_context_summarize import ( + SteerableLongContextSummarize, ) -from intelligence_layer.use_cases.summarize.single_chunk_few_shot_summarize import ( - SingleChunkFewShotSummarize, +from intelligence_layer.use_cases.summarize.steerable_single_chunk_summarize import ( + SteerableSingleChunkSummarize, ) @fixture -def single_chunk_few_shot_summarize( +def steerable_single_chunk_summarize( client: AlephAlphaClientProtocol, -) -> SingleChunkFewShotSummarize: - return SingleChunkFewShotSummarize(client, "luminous-extended", 128) +) -> SteerableSingleChunkSummarize: + return SteerableSingleChunkSummarize(client, "luminous-extended", 128) @fixture @@ -27,10 +27,15 @@ def chunk() -> Chunk: @fixture -def long_context_high_compression_summarize( +def steerable_long_context_summarize( client: AlephAlphaClientProtocol, -) -> LongContextHighCompressionSummarize: - return LongContextHighCompressionSummarize(client, model="luminous-base") +) -> SteerableLongContextSummarize: + return SteerableLongContextSummarize( + client, + model="luminous-base", + max_generated_tokens=128, + max_tokens_per_chunk=512, + ) @fixture diff --git a/tests/use_cases/summarize/test_long_context_high_compression_summarize.py b/tests/use_cases/summarize/test_long_context_high_compression_summarize.py deleted file mode 100644 index 666df8a04..000000000 --- a/tests/use_cases/summarize/test_long_context_high_compression_summarize.py +++ /dev/null @@ -1,24 +0,0 @@ -from intelligence_layer.core.tracer import NoOpTracer -from intelligence_layer.use_cases.summarize.long_context_high_compression_summarize import ( - LongContextHighCompressionSummarize, -) -from intelligence_layer.use_cases.summarize.summarize import LongContextSummarizeInput - - -def test_long_context_high_compression_summarize_en( - long_context_high_compression_summarize: LongContextHighCompressionSummarize, - long_text: str, -) -> None: - input = LongContextSummarizeInput(text=long_text) - output = long_context_high_compression_summarize.run(input, NoOpTracer()) - - assert output.partial_summaries - assert any( - "bear" in partial_summary.summary - for partial_summary in output.partial_summaries - ) - assert len( - " ".join( - partial_summary.summary for partial_summary in output.partial_summaries - ) - ) < len(long_text) diff --git a/tests/use_cases/summarize/test_recursive_summarize.py b/tests/use_cases/summarize/test_recursive_summarize.py index b1fd7412f..1da829d0e 100644 --- a/tests/use_cases/summarize/test_recursive_summarize.py +++ b/tests/use_cases/summarize/test_recursive_summarize.py @@ -8,11 +8,7 @@ AlephAlphaClientProtocol, ) from intelligence_layer.core import NoOpTracer -from intelligence_layer.use_cases import ( - LongContextHighCompressionSummarize, - LongContextSummarizeInput, - RecursiveSummarize, -) +from intelligence_layer.use_cases import LongContextSummarizeInput, RecursiveSummarize from intelligence_layer.use_cases.summarize.steerable_long_context_summarize import ( SteerableLongContextSummarize, ) @@ -46,11 +42,11 @@ def very_long_text() -> str: def test_recursive_summarize_stops_when_hitting_max_tokens( very_long_text: str, - long_context_high_compression_summarize: LongContextHighCompressionSummarize, + steerable_long_context_summarize: SteerableLongContextSummarize, ) -> None: max_tokens = 1000 input = LongContextSummarizeInput(text=very_long_text, max_tokens=max_tokens) - task = RecursiveSummarize(long_context_high_compression_summarize) + task = RecursiveSummarize(steerable_long_context_summarize) output = task.run(input, NoOpTracer()) assert len(output.summary) < len(very_long_text) @@ -75,8 +71,11 @@ def test_recursive_summarize_stops_when_num_partial_summaries_stays_same( def test_recursive_summarize_stops_after_one_chunk( recursive_counting_client: RecursiveCountingClient, ) -> None: - long_context_high_compression_summarize = LongContextHighCompressionSummarize( - recursive_counting_client, model="luminous-base" + long_context_high_compression_summarize = SteerableLongContextSummarize( + recursive_counting_client, + model="luminous-base", + max_generated_tokens=128, + max_tokens_per_chunk=512, ) input = LongContextSummarizeInput(text=short_text) task = RecursiveSummarize(long_context_high_compression_summarize) diff --git a/tests/use_cases/summarize/test_single_chunk_few_shot_summarize.py b/tests/use_cases/summarize/test_single_chunk_few_shot_summarize.py deleted file mode 100644 index b5cf18ee2..000000000 --- a/tests/use_cases/summarize/test_single_chunk_few_shot_summarize.py +++ /dev/null @@ -1,30 +0,0 @@ -from intelligence_layer.core.chunk import Chunk -from intelligence_layer.core.detect_language import Language -from intelligence_layer.core.tracer import NoOpTracer -from intelligence_layer.use_cases.summarize.single_chunk_few_shot_summarize import ( - SingleChunkFewShotSummarize, -) -from intelligence_layer.use_cases.summarize.summarize import SingleChunkSummarizeInput - - -def test_high_compression_summarize_en( - single_chunk_few_shot_summarize: SingleChunkFewShotSummarize, chunk: Chunk -) -> None: - input = SingleChunkSummarizeInput(chunk=chunk, language=Language("en")) - output = single_chunk_few_shot_summarize.run(input, NoOpTracer()) - - assert output.summary - assert "bear" in output.summary.lower() - assert len(output.summary) < len(chunk) - - -def test_high_compression_summarize_is_language_sensitive( - single_chunk_few_shot_summarize: SingleChunkFewShotSummarize, chunk: Chunk -) -> None: - input_en = SingleChunkSummarizeInput(chunk=chunk, language=Language("en")) - input_de = SingleChunkSummarizeInput(chunk=chunk, language=Language("de")) - output_en, output_de = single_chunk_few_shot_summarize.run_concurrently( - [input_en, input_de], NoOpTracer(), concurrency_limit=2 - ) - - assert output_en.summary != output_de.summary diff --git a/tests/use_cases/summarize/test_summarize.py b/tests/use_cases/summarize/test_summarize.py index c73dba51d..3ceb8285f 100644 --- a/tests/use_cases/summarize/test_summarize.py +++ b/tests/use_cases/summarize/test_summarize.py @@ -14,18 +14,14 @@ from intelligence_layer.evaluation.data_storage.aggregation_repository import ( InMemoryAggregationRepository, ) -from intelligence_layer.use_cases.summarize.long_context_high_compression_summarize import ( - LongContextHighCompressionSummarize, -) -from intelligence_layer.use_cases.summarize.single_chunk_few_shot_summarize import ( - SingleChunkFewShotSummarize, -) -from intelligence_layer.use_cases.summarize.summarize import ( +from intelligence_layer.use_cases import ( LongContextSummarizeEvaluator, LongContextSummarizeInput, LongContextSummarizeOutput, SingleChunkSummarizeEvaluator, SingleChunkSummarizeInput, + SteerableLongContextSummarize, + SteerableSingleChunkSummarize, SummarizeEvaluation, SummarizeOutput, ) @@ -49,12 +45,12 @@ def single_chunk_summarize_evaluator( @fixture def single_chunk_summarize_runner( - single_chunk_few_shot_summarize: SingleChunkFewShotSummarize, + steerable_single_chunk_summarize: SteerableSingleChunkSummarize, in_memory_dataset_repository: InMemoryDatasetRepository, in_memory_run_repository: InMemoryRunRepository, ) -> Runner[SingleChunkSummarizeInput, SummarizeOutput]: return Runner( - single_chunk_few_shot_summarize, + steerable_single_chunk_summarize, in_memory_dataset_repository, in_memory_run_repository, "single-chunk-summarize", @@ -79,12 +75,12 @@ def long_context_summarize_evaluator( @fixture def long_context_summarize_runner( - long_context_high_compression_summarize: LongContextHighCompressionSummarize, + steerable_long_context_summarize: SteerableLongContextSummarize, in_memory_dataset_repository: DatasetRepository, in_memory_run_repository: InMemoryRunRepository, ) -> Runner[LongContextSummarizeInput, LongContextSummarizeOutput]: return Runner( - long_context_high_compression_summarize, + steerable_long_context_summarize, in_memory_dataset_repository, in_memory_run_repository, "long-context-summarize",