From 9b04d746953eff58ca3f23e0c5efb60176ffd176 Mon Sep 17 00:00:00 2001 From: Onur ULUSOY Date: Sat, 25 May 2024 10:41:18 +0000 Subject: [PATCH] Sync with master --- upsonic/remote/on_prem.py | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/upsonic/remote/on_prem.py b/upsonic/remote/on_prem.py index 4287b80..d8f5a5a 100644 --- a/upsonic/remote/on_prem.py +++ b/upsonic/remote/on_prem.py @@ -1534,6 +1534,65 @@ def return_ollama_llm(self, model=None): + def check_idea(self, idea): + search_result = self.search(idea) + if len(search_result) == 0: + return True + + # Get the first result of check and as ai to check the similarity + first_result = search_result[0] + + # Get the document of the first result + first_result_document = self.get_document(first_result) + + # get the code of the first result + first_result_code = self.get_code(first_result) + + # Ask to AI to check the similarity + prompt = f""" + The user planning to write a function about this: {idea} + + Currently function: {first_result} + Currently function Document: {first_result_document} + Currently function Code: {first_result_code} + + Is the idea making same thing with the first result (Y/N)? + """ + + + ai_answer = self.ai_completion(prompt) + ai_answer = ai_answer.replace("`", "").replace("\n", "") + ai_answer = ai_answer.split(",")[0] + ai_answer = ai_answer.replace("ASSISTANT: ", "") + + is_not_similar = False + + + if ai_answer == "N" or ai_answer == "NO" or ai_answer == "No": + is_not_similar = True + + if not is_not_similar: + #Ask ai to explain similarity in one sentence + prompt = f""" + Current Idea: {idea} + First Result: {first_result} + First Result Document: {first_result_document} + First Result Code: {first_result_code} + + Explain the similarity in one sentence. If you need to refer to First Result please use {first_result}. + """ + + ai_answer = self.ai_completion(prompt) + ai_answer = ai_answer.replace("`", "").replace("\n", "") + ai_answer = ai_answer.split(",")[0] + ai_answer = ai_answer.replace("ASSISTANT: ", "") + + return "Fail: "+ ai_answer + else: + return "Pass: There is no same functionality in the library" + + + class UpsonicOnPrem(Upsonic_On_Prem): pass