mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
Fixed prompt service
This commit is contained in:
parent
e2d7778cd3
commit
79f8d84e10
2 changed files with 32 additions and 22 deletions
|
|
@ -33,7 +33,7 @@ class Processor(FlowProcessor):
|
||||||
super(Processor, self).__init__(
|
super(Processor, self).__init__(
|
||||||
**params | {
|
**params | {
|
||||||
"id": id,
|
"id": id,
|
||||||
"config-type": config_key,
|
"config-type": self.config_key,
|
||||||
"concurrency": concurrency,
|
"concurrency": concurrency,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -21,29 +21,19 @@ class PromptManager:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.config = PromptConfiguration("", {}, {})
|
self.load_config({})
|
||||||
self.terms = config.global_terms
|
|
||||||
self.prompts = config.prompts
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.system_template = ibis.Template(config.system_template)
|
|
||||||
except:
|
|
||||||
raise RuntimeError("Error in system template")
|
|
||||||
|
|
||||||
self.templates = {}
|
|
||||||
for k, v in self.prompts.items():
|
|
||||||
try:
|
|
||||||
self.templates[k] = ibis.Template(v.template)
|
|
||||||
except:
|
|
||||||
raise RuntimeError(f"Error in template: {k}")
|
|
||||||
|
|
||||||
if v.terms is None:
|
|
||||||
v.terms = {}
|
|
||||||
|
|
||||||
def load_config(self, config):
|
def load_config(self, config):
|
||||||
|
|
||||||
system = json.loads(config["system"])
|
try:
|
||||||
ix = json.loads(config["template-index"])
|
system = json.loads(config["system"])
|
||||||
|
except:
|
||||||
|
system = "Be helpful."
|
||||||
|
|
||||||
|
try:
|
||||||
|
ix = json.loads(config["template-index"])
|
||||||
|
except:
|
||||||
|
ix = []
|
||||||
|
|
||||||
prompts = {}
|
prompts = {}
|
||||||
|
|
||||||
|
|
@ -69,6 +59,24 @@ class PromptManager:
|
||||||
prompts
|
prompts
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.terms = self.config.global_terms
|
||||||
|
self.prompts = self.config.prompts
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.system_template = ibis.Template(self.config.system_template)
|
||||||
|
except:
|
||||||
|
raise RuntimeError("Error in system template")
|
||||||
|
|
||||||
|
self.templates = {}
|
||||||
|
for k, v in self.prompts.items():
|
||||||
|
try:
|
||||||
|
self.templates[k] = ibis.Template(v.template)
|
||||||
|
except:
|
||||||
|
raise RuntimeError(f"Error in template: {k}")
|
||||||
|
|
||||||
|
if v.terms is None:
|
||||||
|
v.terms = {}
|
||||||
|
|
||||||
def parse_json(self, text):
|
def parse_json(self, text):
|
||||||
json_match = re.search(r'```(?:json)?(.*?)```', text, re.DOTALL)
|
json_match = re.search(r'```(?:json)?(.*?)```', text, re.DOTALL)
|
||||||
|
|
||||||
|
|
@ -80,7 +88,7 @@ class PromptManager:
|
||||||
|
|
||||||
return json.loads(json_str)
|
return json.loads(json_str)
|
||||||
|
|
||||||
async def render(self, id, input):
|
def render(self, id, input):
|
||||||
|
|
||||||
if id not in self.prompts:
|
if id not in self.prompts:
|
||||||
raise RuntimeError("ID invalid")
|
raise RuntimeError("ID invalid")
|
||||||
|
|
@ -95,6 +103,8 @@ class PromptManager:
|
||||||
|
|
||||||
print("Invoke...", flush=True)
|
print("Invoke...", flush=True)
|
||||||
|
|
||||||
|
terms = self.terms | self.prompts[id].terms | input
|
||||||
|
|
||||||
resp_type = self.prompts[id].response_type
|
resp_type = self.prompts[id].response_type
|
||||||
|
|
||||||
prompt = {
|
prompt = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue