Skip to content

Commit

Permalink
feat: create prompt from file
Browse files Browse the repository at this point in the history
  • Loading branch information
bernard-ng committed Nov 25, 2024
1 parent 6bea4a3 commit 5e804bb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Model/Completion/Prompt/PromptTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ public static function from(string $template): self
return new self($template, []);
}

/**
* Create a new prompt from the given file.
*
* <code>
* $template = PromptTemplate::fromFile("/path/to/file.txt");
* </code>
*/
public static function fromFile(string $path): self
{
$content = file_get_contents($path);
if ($content === false) {
throw new \RuntimeException("Could not read the file at path: {$path}");
}

return new self($content, []);
}

/**
* Format the prompt with the given values.
* The values should be an associative array where the key is the placeholder
Expand Down

0 comments on commit 5e804bb

Please sign in to comment.