mirror of
https://github.com/Hopiu/llm.git
synced 2026-05-26 14:04:03 +00:00
Removed .stream() method in favor of .prompt(stream=False)
This commit is contained in:
parent
3136948408
commit
49e4d688c6
3 changed files with 12 additions and 15 deletions
|
|
@ -21,9 +21,8 @@ The `Model` class is an abstract base class that needs to be subclassed to provi
|
|||
|
||||
Model instances provide the following methods:
|
||||
|
||||
- `prompt(prompt: str, ...options) -> Prompt` - a convenience wrapper which creates a `Prompt` instance and then executes it. This is the most common way to use LLM models.
|
||||
- `stream(prompt: str) -> Response` - a convenient wrapper for `.execute(..., stream=True)`.
|
||||
- `execute(prompt: Prompt, stream: bool) -> Response` - execute a prepared Prompt instance against the model and return a `Response`, streaming or not-streaming.
|
||||
- `prompt(prompt: str, stream: bool, ...options) -> Prompt` - a convenience wrapper which creates a `Prompt` instance and then executes it. This is the most common way to use LLM models.
|
||||
- `execute(prompt: Prompt, stream: bool) -> Response` - execute a prepared Prompt instance against the model and return a `Response`.
|
||||
|
||||
Models usually return subclasses of `Response` that are specific to that model.
|
||||
|
||||
|
|
|
|||
|
|
@ -217,12 +217,10 @@ def prompt(
|
|||
raise click.ClickException(str(ex))
|
||||
|
||||
should_stream = model.can_stream and not no_stream
|
||||
if should_stream:
|
||||
method = model.stream
|
||||
else:
|
||||
method = model.prompt
|
||||
if not should_stream:
|
||||
validated_options["stream"] = False
|
||||
|
||||
response = method(prompt, system, **validated_options)
|
||||
response = model.prompt(prompt, system, **validated_options)
|
||||
|
||||
if should_stream:
|
||||
for chunk in response:
|
||||
|
|
|
|||
|
|
@ -144,18 +144,18 @@ class Model(ABC):
|
|||
return os.environ.get(self.key_env_var)
|
||||
return None
|
||||
|
||||
def prompt(self, prompt, system=None, **options):
|
||||
def prompt(
|
||||
self,
|
||||
prompt: Optional[str],
|
||||
system: Optional[str] = None,
|
||||
stream: bool = False,
|
||||
**options
|
||||
):
|
||||
return self.execute(
|
||||
Prompt(prompt, system=system, model=self, options=self.Options(**options)),
|
||||
stream=False,
|
||||
)
|
||||
|
||||
def stream(self, prompt, system=None, **options):
|
||||
return self.execute(
|
||||
Prompt(prompt, system=system, model=self, options=self.Options(**options)),
|
||||
stream=True,
|
||||
)
|
||||
|
||||
@abstractmethod
|
||||
def execute(self, prompt: Prompt, stream: bool = True) -> Response:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue