From fb25de5d54bf144dda44f59ffc2d845c4841aa14 Mon Sep 17 00:00:00 2001 From: henri123lemoine Date: Sun, 26 Mar 2023 12:46:04 -0400 Subject: [PATCH] Fixed bugs, and tested informed_assistant.py. Success! --- web/api/informed_assistant.py | 19 ++++++++++++------ web/api/semantic_search.py | 38 +++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/web/api/informed_assistant.py b/web/api/informed_assistant.py index b617e4d..e17129a 100644 --- a/web/api/informed_assistant.py +++ b/web/api/informed_assistant.py @@ -38,7 +38,7 @@ openai.api_key = OPENAI_API_KEY # OpenAI models EMBEDDING_MODEL = "text-embedding-ada-002" -COMPLETIONS_MODEL = "text-davinci-003" +COMPLETIONS_MODEL = "gpt-3.5-turbo" # OpenAI parameters LEN_EMBEDDINGS = 1536 @@ -286,10 +286,17 @@ if __name__ == "__main__": previous_dialogue = [ {"role": "assistant", "content": "Hi! I know all about AI Alignment. Ask me a question!"}, ] - k = 5 + k = 10 mode = "standard" - HyDE = False - stream = False + HyDE = True + stream = False # Doesn't quite work yet - for response in informed_assistant(user_query, previous_dialogue, k, mode, HyDE, stream): - print(response, end="") \ No newline at end of file + import asyncio + chat_completion = asyncio.run(informed_assistant(user_query, previous_dialogue, k, mode, HyDE, stream)) + print(chat_completion) + + # if stream: + # for part in informed_assistant(user_query, previous_dialogue, k, mode, HyDE, stream): + # print(part, end="") + # else: + # print(informed_assistant(user_query, previous_dialogue, k, mode, HyDE, stream)) \ No newline at end of file diff --git a/web/api/semantic_search.py b/web/api/semantic_search.py index f465a0d..475ae81 100644 --- a/web/api/semantic_search.py +++ b/web/api/semantic_search.py @@ -45,7 +45,7 @@ except ImportError: # OpenAI models EMBEDDING_MODEL = "text-embedding-ada-002" -COMPLETIONS_MODEL = "text-davinci-003" +COMPLETIONS_MODEL = "gpt-3.5-turbo" # OpenAI parameters LEN_EMBEDDINGS = 1536 @@ -131,7 +131,7 @@ def get_top_k_blocks(user_query: str, k: int = 10, HyDE: bool = False) -> List[B HyDE_completion = openai.ChatCompletion.create( model=COMPLETIONS_MODEL, messages=messages - )["choices"][0]["text"] + )["choices"][0]["message"]["content"] HyDe_completion_embedding = get_embedding(f"Question: {user_query}\n\nAnswer: {HyDE_completion}") similarity_scores = np.dot(metadataset.embeddings, HyDe_completion_embedding) @@ -156,17 +156,25 @@ def get_top_k_blocks(user_query: str, k: int = 10, HyDE: bool = False) -> List[B if __name__ == "__main__": # Test the embeddings function - query = "What is the best way to learn about AI alignment?" - k = 8 - HyDE = True + # query = "What is the best way to learn about AI alignment?" + # k = 8 + # HyDE = True - blocks = get_top_k_blocks(query, k, HyDE) - for link in blocks: - print(f"Title: {link.title}") - print(f"Author: {link.author}") - print(f"Date: {link.date}") - print(f"URL: {link.url}") - print(f"Tags: {link.tags}") - print(f"Text: {link.text}") - print() - print() \ No newline at end of file + # blocks = get_top_k_blocks(query, k, HyDE) + # for link in blocks: + # print(f"Title: {link.title}") + # print(f"Author: {link.author}") + # print(f"Date: {link.date}") + # print(f"URL: {link.url}") + # print(f"Tags: {link.tags}") + # print(f"Text: {link.text}") + # print() + # print() + + openai.ChatCompletion.create( + model=COMPLETIONS_MODEL, + messages=[ + {"role": "system", "content": "You are a knowledgeable AI Alignment assistant."}, + {"role": "user", "content": f"Do your best to answer the question/instruction, even if you don't know the correct answer or action for sure.\nQ: What is the best way to learn about AI alignment?"}, + ] + ) \ No newline at end of file