Commit ·
c6fe983
1
Parent(s): fae1c05
Update app.py
Browse files81 unmodified lines8283848586878817 unmodified lines1061071081081091101111123 unmodified lines11611711811811912012012112212312412512112212312412512612712712812913013113213313413513613713813914014114214312812913013113213313413513613713813914014114214314414514514614714614714814914915015115215315415515615715815916016116215015115215315415515615715815916016116216316481 unmodified lines
@spaces.GPU(duration=120)def deidentify_doc(pdftext, maxtokens, temperature, top_probability): # prompt = "In the following text replace any person name and any address with term [redacted], replace any Date of Birth and NHS number with term [redacted]" # prompt = """ # Perform the following actions on given report:17 unmodified lines # n_ctx=8192, # )
# chat_template = MessagesFormatterType.LLAMA_3 chat_template = MessagesFormatterType.LLAMA_3 llm = Llama( model_path="models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf",3 unmodified lines n_ctx=8192, )
# provider = LlamaCppPythonProvider(llm) provider = LlamaCppPythonProvider(llm) # agent = LlamaCppAgent( # provider, # system_prompt="You are a helpful assistant.", # predefined_messages_formatter_type=chat_template, # debug_output=True # ) agent = LlamaCppAgent( provider, system_prompt="You are a helpful assistant.", predefined_messages_formatter_type=chat_template, debug_output=True ) # settings = provider.get_provider_default_settings() # settings.temperature = 0.7 # settings.top_k = 40 # settings.top_p = 0.95 # settings.max_tokens = 2048 # settings.repeat_penalty = 1.1 # settings.stream = True
# messages = BasicChatHistory()
# stream = agent.get_chat_response( # prompt + ' : ' + pdftext, # llm_sampling_settings=settings, # chat_history=messages, # returns_streaming_generator=True, # print_output=False # ) settings = provider.get_provider_default_settings() settings.temperature = temperature settings.top_k = 40 settings.top_p = top_probability settings.max_tokens = maxtokens settings.repeat_penalty = 1.1 settings.stream = True
messages = BasicChatHistory()
stream = agent.get_chat_response( prompt + ' : ' + pdftext, llm_sampling_settings=settings, chat_history=messages, returns_streaming_generator=True, print_output=False )
# outputs = "" # for output in stream: # outputs += output output = "" for op in stream: output += op # return outputs
output = llm.create_chat_completion( messages=[ {"role": "assistant", "content": prompt}, { "role": "user", "content": pdftext } ], max_tokens=maxtokens, temperature=temperature ) output = output['choices'][0]['message']['content'] # output = llm.create_chat_completion( # messages=[ # {"role": "assistant", "content": prompt}, # { # "role": "user", # "content": pdftext # } # ], # max_tokens=maxtokens, # temperature=temperature # ) # output = output['choices'][0]['message']['content']
# prompt = "Perform the following actions on given text: 1. Replace any person age with term [redacted] 2. DO NOT REPLACE ANY MEDICAL MEASUREMENTS 3. Replace only the CALENDAR DATES of format 'day/month/year' with term [redacted]" # output = model.create_chat_completion(app.py+41-42