-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate prompt builder concept from adapter.
- Loading branch information
Showing
6 changed files
with
48 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
from abc import ABCMeta, abstractmethod | ||
|
||
from kiln_ai.datamodel.models import Task | ||
|
||
|
||
class BaseAdapter(metaclass=ABCMeta): | ||
@abstractmethod | ||
async def run(self, input: str) -> str: | ||
pass | ||
|
||
|
||
class BasePromptBuilder(metaclass=ABCMeta): | ||
def __init__(self, task: Task): | ||
self.task = task | ||
|
||
@abstractmethod | ||
def build_prompt(self, input: str) -> str: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from kiln_ai.adapters.base_adapter import BasePromptBuilder | ||
|
||
|
||
class SimplePromptBuilder(BasePromptBuilder): | ||
def build_prompt(self, input: str) -> str: | ||
base_prompt = self.task.instruction | ||
|
||
# TODO: this is just a quick version. Formatting and best practices TBD | ||
if len(self.task.requirements()) > 0: | ||
base_prompt += ( | ||
"\n\nYour response should respectthe following requirements:\n" | ||
) | ||
# iterate requirements, formatting them in numbereed list like 1) task.instruction\n2)... | ||
for i, requirement in enumerate(self.task.requirements()): | ||
base_prompt += f"{i+1}) {requirement.instruction}\n" | ||
|
||
# TODO: should be another message | ||
base_prompt += f"\n\nThe input is:\n{input}" | ||
return base_prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters