Fixed bugs, and tested informed_assistant.py. Success!

This commit is contained in:
henri123lemoine
2023-03-26 12:46:04 -04:00
parent a344e54c2c
commit fb25de5d54
2 changed files with 36 additions and 21 deletions
+13 -6
View File
@@ -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="")
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))
+23 -15
View File
@@ -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()
# 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?"},
]
)