added stepback-Prompting
Browse files
app.py
CHANGED
|
@@ -328,6 +328,40 @@ class BSIChatbot:
|
|
| 328 |
|
| 329 |
return query, context
|
| 330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
def ragPromptNew(self, query, rerankingStep, history, stepBackPrompt):
|
| 332 |
global rerankingModel
|
| 333 |
prompt_in_chat_format = [
|
|
@@ -584,39 +618,7 @@ class BSIChatbot:
|
|
| 584 |
def launchGr(self):
|
| 585 |
gr.Interface.from_pipeline(self.llmpipeline).launch()
|
| 586 |
|
| 587 |
-
def queryRemoteLLM(self, systemPrompt, query, summary):
|
| 588 |
-
if summary != True:
|
| 589 |
-
chat_completion = self.llm_client.chat.completions.create(
|
| 590 |
-
messages=[{"role": "system", "content": systemPrompt},
|
| 591 |
-
{"role": "user", "content": "Step-Back Frage, die neu gestellt werden soll: " + query}],
|
| 592 |
-
model=self.llm_remote_model,
|
| 593 |
-
)
|
| 594 |
-
if summary == True:
|
| 595 |
-
chat_completion = self.llm_client.chat.completions.create(
|
| 596 |
-
messages=[{"role": "system", "content": systemPrompt},
|
| 597 |
-
{"role": "user", "content": query}],
|
| 598 |
-
model=self.llm_remote_model,
|
| 599 |
-
)
|
| 600 |
-
return Answer
|
| 601 |
|
| 602 |
-
def stepBackPrompt(self, query):
|
| 603 |
-
systemPrompt = """
|
| 604 |
-
Sie sind ein Experte für den IT-Grundschutz des BSI.
|
| 605 |
-
Ihre Aufgabe ist es, eine Frage neu zu formulieren und sie in eine
|
| 606 |
-
Stepback-Frage umzuformulieren, die nach einem Grundkonzept der Begrifflichkeit fragt.
|
| 607 |
-
|
| 608 |
-
Hier sind ein paar Beispiele:
|
| 609 |
-
Ursprüngliche Frage: Welche Bausteine werden auf einen Webserver angewendet?
|
| 610 |
-
Stepback-Frage: Wie werden Bausteine im IT-Grundschutz angewendet?
|
| 611 |
-
|
| 612 |
-
Ursprüngliche Frage: Wer war der Ehemann von Anna Karina von 1968 bis 1974?
|
| 613 |
-
Stepback-Frage: Wer waren die Ehegatten von Anna Karina?
|
| 614 |
-
|
| 615 |
-
Ursprüngliche Frage: Welche Inhalte enthält der Standard 200-1?
|
| 616 |
-
Stepback Frage: Welche Standards gibt es im IT-Grundschutz?
|
| 617 |
-
"""
|
| 618 |
-
stepBackQuery = queryRemoteLLM(systemPrompt, query)
|
| 619 |
-
return stepBackQuery
|
| 620 |
|
| 621 |
if __name__ == '__main__':
|
| 622 |
#RAW_KNOWLEDGE_BASE = []
|
|
|
|
| 328 |
|
| 329 |
return query, context
|
| 330 |
|
| 331 |
+
def queryRemoteLLM(self, systemPrompt, query, summary):
|
| 332 |
+
if summary != True:
|
| 333 |
+
chat_completion = self.llm_client.chat.completions.create(
|
| 334 |
+
messages=[{"role": "system", "content": systemPrompt},
|
| 335 |
+
{"role": "user", "content": "Step-Back Frage, die neu gestellt werden soll: " + query}],
|
| 336 |
+
model=self.llm_remote_model,
|
| 337 |
+
)
|
| 338 |
+
if summary == True:
|
| 339 |
+
chat_completion = self.llm_client.chat.completions.create(
|
| 340 |
+
messages=[{"role": "system", "content": systemPrompt},
|
| 341 |
+
{"role": "user", "content": query}],
|
| 342 |
+
model=self.llm_remote_model,
|
| 343 |
+
)
|
| 344 |
+
return Answer
|
| 345 |
+
|
| 346 |
+
def stepBackPrompt(self, query):
|
| 347 |
+
systemPrompt = """
|
| 348 |
+
Sie sind ein Experte für den IT-Grundschutz des BSI.
|
| 349 |
+
Ihre Aufgabe ist es, eine Frage neu zu formulieren und sie in eine
|
| 350 |
+
Stepback-Frage umzuformulieren, die nach einem Grundkonzept der Begrifflichkeit fragt.
|
| 351 |
+
|
| 352 |
+
Hier sind ein paar Beispiele:
|
| 353 |
+
Ursprüngliche Frage: Welche Bausteine werden auf einen Webserver angewendet?
|
| 354 |
+
Stepback-Frage: Wie werden Bausteine im IT-Grundschutz angewendet?
|
| 355 |
+
|
| 356 |
+
Ursprüngliche Frage: Wer war der Ehemann von Anna Karina von 1968 bis 1974?
|
| 357 |
+
Stepback-Frage: Wer waren die Ehegatten von Anna Karina?
|
| 358 |
+
|
| 359 |
+
Ursprüngliche Frage: Welche Inhalte enthält der Standard 200-1?
|
| 360 |
+
Stepback Frage: Welche Standards gibt es im IT-Grundschutz?
|
| 361 |
+
"""
|
| 362 |
+
stepBackQuery = queryRemoteLLM(systemPrompt, query)
|
| 363 |
+
return stepBackQuery
|
| 364 |
+
|
| 365 |
def ragPromptNew(self, query, rerankingStep, history, stepBackPrompt):
|
| 366 |
global rerankingModel
|
| 367 |
prompt_in_chat_format = [
|
|
|
|
| 618 |
def launchGr(self):
|
| 619 |
gr.Interface.from_pipeline(self.llmpipeline).launch()
|
| 620 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 622 |
|
| 623 |
if __name__ == '__main__':
|
| 624 |
#RAW_KNOWLEDGE_BASE = []
|