Chris4K commited on
Commit
e96e53f
·
verified ·
1 Parent(s): d2106c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -36
app.py CHANGED
@@ -196,8 +196,43 @@ class BaseGenerator(ABC):
196
  pass
197
 
198
  @abstractmethod
199
- def generate(self, prompt: str, model_kwargs: Dict[str, Any], **kwargs) -> str:
200
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- self,
437
- prompt: str,
438
- model_kwargs: Dict[str, Any],
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,
 
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,