alexkueck commited on
Commit
d86bca0
1 Parent(s): 5ebfc68

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +34 -0
utils.py CHANGED
@@ -250,6 +250,40 @@ def rag_chain(prompt, db, k=3):
250
 
251
 
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  ##########################################
254
  #Hashing....
255
  # Funktion zum Hashen des Eingabewerts
 
250
 
251
 
252
 
253
+ ###################################################
254
+ #Prompts mit History erzeugen für verschiednee Modelle
255
+ ###################################################
256
+ #Funktion, die einen Prompt mit der history zusammen erzeugt - allgemein
257
+ def generate_prompt_with_history(text, history, max_length=4048):
258
+ #prompt = "The following is a conversation between a human and an AI assistant named Baize (named after a mythical creature in Chinese folklore). Baize is an open-source AI assistant developed by UCSD and Sun Yat-Sen University. The human and the AI assistant take turns chatting. Human statements start with [|Human|] and AI assistant statements start with [|AI|]. The AI assistant always provides responses in as much detail as possible, and in Markdown format. The AI assistant always declines to engage with topics, questions and instructions related to unethical, controversial, or sensitive issues. Complete the transcript in exactly that format.\n[|Human|]Hello!\n[|AI|]Hi!"
259
+ #prompt = "Das folgende ist eine Unterhaltung in deutsch zwischen einem Menschen und einem KI-Assistenten, der Baize genannt wird. Baize ist ein open-source KI-Assistent, der von UCSD entwickelt wurde. Der Mensch und der KI-Assistent chatten abwechselnd miteinander in deutsch. Die Antworten des KI Assistenten sind immer so ausführlich wie möglich und in Markdown Schreibweise und in deutscher Sprache. Wenn nötig übersetzt er sie ins Deutsche. Die Antworten des KI-Assistenten vermeiden Themen und Antworten zu unethischen, kontroversen oder sensiblen Themen. Die Antworten sind immer sehr höflich formuliert..\n[|Human|]Hallo!\n[|AI|]Hi!"
260
+ prompt=""
261
+ history = ["\n{}\n{}".format(x[0],x[1]) for x in history]
262
+ history.append("\n{}\n".format(text))
263
+ history_text = ""
264
+ flag = False
265
+ for x in history[::-1]:
266
+ history_text = x + history_text
267
+ flag = True
268
+ print("hist+prompt: ")
269
+ print(history_text)
270
+ if flag:
271
+ return prompt+history_text
272
+ else:
273
+ return None
274
+
275
+
276
+ #############################################
277
+ #Prompt und History für Hugging Face Schnittstelle
278
+ def generate_prompt_with_history_hf(prompt, history):
279
+ history_transformer_format = history + [[prompt, ""]]
280
+ #stop = StopOnTokens()
281
+
282
+ messages = "".join(["".join(["\n<human>:"+item[0], "\n<bot>:"+item[1]]) #curr_system_message +
283
+ for item in history_transformer_format])
284
+
285
+
286
+
287
  ##########################################
288
  #Hashing....
289
  # Funktion zum Hashen des Eingabewerts