Update app.py
Browse files
app.py
CHANGED
@@ -196,8 +196,43 @@ class BaseGenerator(ABC):
|
|
196 |
pass
|
197 |
|
198 |
@abstractmethod
|
199 |
-
def generate(
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
# strategy.py
|
203 |
#TODO UPDATE Paths
|
@@ -433,40 +468,41 @@ class LlamaGenerator(BaseGenerator):
|
|
433 |
return " NOt implememnted yet "
|
434 |
|
435 |
def generate(
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
|
|
470 |
|
471 |
def generate_with_context(
|
472 |
self,
|
|
|
196 |
pass
|
197 |
|
198 |
@abstractmethod
|
199 |
+
def generate(
|
200 |
+
self,
|
201 |
+
prompt: str,
|
202 |
+
model_kwargs: Dict[str, Any],
|
203 |
+
strategy: str = "default",
|
204 |
+
**kwargs
|
205 |
+
) -> str:
|
206 |
+
"""
|
207 |
+
Generate text based on a given strategy.
|
208 |
+
|
209 |
+
Args:
|
210 |
+
prompt (str): Input prompt for text generation.
|
211 |
+
model_kwargs (Dict[str, Any]): Additional arguments for model generation.
|
212 |
+
strategy (str): The generation strategy to use (default: "default").
|
213 |
+
**kwargs: Additional arguments passed to the strategy.
|
214 |
+
|
215 |
+
Returns:
|
216 |
+
str: Generated text response.
|
217 |
+
|
218 |
+
Raises:
|
219 |
+
ValueError: If the specified strategy is not available.
|
220 |
+
"""
|
221 |
+
# Validate that the strategy exists
|
222 |
+
if strategy not in self.strategies:
|
223 |
+
raise ValueError(f"Unknown strategy: {strategy}. Available strategies are: {list(self.strategies.keys())}")
|
224 |
+
|
225 |
+
# Extract `generator` from kwargs if it exists to prevent duplication
|
226 |
+
kwargs.pop("generator", None)
|
227 |
+
|
228 |
+
# Call the selected strategy with the provided arguments
|
229 |
+
return self.strategies[strategy].generate(
|
230 |
+
generator=self, # The generator instance
|
231 |
+
prompt=prompt, # The input prompt
|
232 |
+
model_kwargs=model_kwargs, # Arguments for the model
|
233 |
+
**kwargs # Any additional strategy-specific arguments
|
234 |
+
)
|
235 |
+
|
236 |
|
237 |
# strategy.py
|
238 |
#TODO UPDATE Paths
|
|
|
468 |
return " NOt implememnted yet "
|
469 |
|
470 |
def generate(
|
471 |
+
self,
|
472 |
+
prompt: str,
|
473 |
+
model_kwargs: Dict[str, Any],
|
474 |
+
strategy: str = "default",
|
475 |
+
**kwargs
|
476 |
+
) -> str:
|
477 |
+
"""
|
478 |
+
Generate text based on a given strategy.
|
479 |
+
|
480 |
+
Args:
|
481 |
+
prompt (str): Input prompt for text generation.
|
482 |
+
model_kwargs (Dict[str, Any]): Additional arguments for model generation.
|
483 |
+
strategy (str): The generation strategy to use (default: "default").
|
484 |
+
**kwargs: Additional arguments passed to the strategy.
|
485 |
+
|
486 |
+
Returns:
|
487 |
+
str: Generated text response.
|
488 |
+
|
489 |
+
Raises:
|
490 |
+
ValueError: If the specified strategy is not available.
|
491 |
+
"""
|
492 |
+
# Validate that the strategy exists
|
493 |
+
if strategy not in self.strategies:
|
494 |
+
raise ValueError(f"Unknown strategy: {strategy}. Available strategies are: {list(self.strategies.keys())}")
|
495 |
+
|
496 |
+
# Extract `generator` from kwargs if it exists to prevent duplication
|
497 |
+
kwargs.pop("generator", None)
|
498 |
+
|
499 |
+
# Call the selected strategy with the provided arguments
|
500 |
+
return self.strategies[strategy].generate(
|
501 |
+
generator=self, # The generator instance
|
502 |
+
prompt=prompt, # The input prompt
|
503 |
+
model_kwargs=model_kwargs, # Arguments for the model
|
504 |
+
**kwargs # Any additional strategy-specific arguments
|
505 |
+
)
|
506 |
|
507 |
def generate_with_context(
|
508 |
self,
|