Update app.py
Browse files
app.py
CHANGED
@@ -439,17 +439,35 @@ class LlamaGenerator(BaseGenerator):
|
|
439 |
strategy: str = "default",
|
440 |
**kwargs
|
441 |
) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
if strategy not in self.strategies:
|
443 |
-
raise ValueError(f"Unknown strategy: {strategy}")
|
444 |
-
|
|
|
445 |
return self.strategies[strategy].generate(
|
446 |
-
self,
|
447 |
-
prompt,
|
448 |
-
model_kwargs,
|
449 |
-
**kwargs
|
450 |
)
|
451 |
|
452 |
|
|
|
453 |
def generate_with_context(
|
454 |
self,
|
455 |
context: str,
|
@@ -486,14 +504,16 @@ class LlamaGenerator(BaseGenerator):
|
|
486 |
max_history_turns
|
487 |
)
|
488 |
return self.generate(
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
|
|
495 |
)
|
496 |
|
|
|
497 |
|
498 |
def check_health(self) -> HealthStatus:
|
499 |
"""Check the health status of the generator."""
|
|
|
439 |
strategy: str = "default",
|
440 |
**kwargs
|
441 |
) -> str:
|
442 |
+
"""
|
443 |
+
Generate text based on a given strategy.
|
444 |
+
|
445 |
+
Args:
|
446 |
+
prompt (str): Input prompt for text generation.
|
447 |
+
model_kwargs (Dict[str, Any]): Additional arguments for model generation.
|
448 |
+
strategy (str): The generation strategy to use (default: "default").
|
449 |
+
**kwargs: Additional arguments passed to the strategy.
|
450 |
+
|
451 |
+
Returns:
|
452 |
+
str: Generated text response.
|
453 |
+
|
454 |
+
Raises:
|
455 |
+
ValueError: If the specified strategy is not available.
|
456 |
+
"""
|
457 |
+
# Validate that the strategy exists
|
458 |
if strategy not in self.strategies:
|
459 |
+
raise ValueError(f"Unknown strategy: {strategy}. Available strategies are: {list(self.strategies.keys())}")
|
460 |
+
|
461 |
+
# Call the selected strategy with the provided arguments
|
462 |
return self.strategies[strategy].generate(
|
463 |
+
generator=self, # The generator instance
|
464 |
+
prompt=prompt, # The input prompt
|
465 |
+
model_kwargs=model_kwargs, # Arguments for the model
|
466 |
+
**kwargs # Any additional strategy-specific arguments
|
467 |
)
|
468 |
|
469 |
|
470 |
+
|
471 |
def generate_with_context(
|
472 |
self,
|
473 |
context: str,
|
|
|
504 |
max_history_turns
|
505 |
)
|
506 |
return self.generate(
|
507 |
+
generator=self,
|
508 |
+
prompt=prompt,
|
509 |
+
model_kwargs=model_kwargs,
|
510 |
+
strategy=strategy,
|
511 |
+
num_samples=num_samples,
|
512 |
+
depth=depth,
|
513 |
+
breadth=breadth
|
514 |
)
|
515 |
|
516 |
+
|
517 |
|
518 |
def check_health(self) -> HealthStatus:
|
519 |
"""Check the health status of the generator."""
|