-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathforking.py
41 lines (31 loc) · 1.22 KB
/
forking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import traceback
from typing import Any
from pydantic import BaseModel
from beeai_framework.errors import FrameworkError
from beeai_framework.template import PromptTemplate, PromptTemplateInput
def main() -> None:
class OriginalSchema(BaseModel):
name: str
objective: str
original: PromptTemplate[OriginalSchema] = PromptTemplate(
PromptTemplateInput(
schema=OriginalSchema,
template="""You are a helpful assistant called {{name}}. Your objective is to {{objective}}.""",
)
)
def customizer(temp_input: PromptTemplateInput[Any]) -> PromptTemplateInput[Any]:
new_temp = temp_input.model_copy()
new_temp.template = f"""{temp_input.template} Your answers must be concise."""
new_temp.defaults["name"] = "Bee"
return new_temp
modified = original.fork(customizer=customizer)
# You are a helpful assistant called Bee. Your objective is to fulfill the user needs. Your answers must be concise.
prompt = modified.render(objective="fulfill the user needs")
print(prompt)
if __name__ == "__main__":
try:
main()
except FrameworkError as e:
traceback.print_exc()
sys.exit(e.explain())