Typing bug fix.

This commit is contained in:
henri123lemoine
2023-03-26 05:59:25 -04:00
parent 8156767a29
commit a344e54c2c
2 changed files with 9 additions and 17 deletions
+6 -5
View File
@@ -139,10 +139,10 @@ def generate_prompt(user_query: str, previous_dialogue: List[Dict[str, str]] = [
mode (str): The mode of the assistant. Can be "standard", etc. Defaults to "standard".
Returns:
Dict[str, str]: The prompt for the ChatCompletions API.
List[Dict[str, str]]: The prompt in messages format.
"""
# Initialize prompt
prompt = {}
prompt = []
# Generate system description
if mode == "standard":
@@ -233,7 +233,7 @@ async def stream_completion(prompt: List[Dict[str, str]], stream_delay: float =
time.sleep(stream_delay)
yield f"{word} "
def informed_assistant(user_query: str, previous_dialogue: str, k: str, mode: str = "standard", HyDE: bool = False, stream: bool = True, stream_delay: float = 0.1) -> str:
def informed_assistant(user_query: str, previous_dialogue: List[Dict[str, str]] = [], k: str = 10, mode: str = "standard", HyDE: bool = False, stream: bool = True, stream_delay: float = 0.1) -> str:
"""
This function uses the OpenAI ChatCompletions API to answer a user query.
It first checks if the query is offensive, and if so, raises an exception.
@@ -243,6 +243,7 @@ def informed_assistant(user_query: str, previous_dialogue: str, k: str, mode: st
Args:
user_query (str): The user query.
previous_dialogue (List[Dict[str, str]]): The previous dialogue. Defaults to [].
k (str): The number of blocks to use as context.
mode (str): The mode to use for the ChatCompletions API. Defaults to "standard".
HyDE (bool): Whether to use the HyDE technique for semantic search. This makes search slower, but better. Defaults to False.
@@ -287,8 +288,8 @@ if __name__ == "__main__":
]
k = 5
mode = "standard"
HyDE = True
stream = True
HyDE = False
stream = False
for response in informed_assistant(user_query, previous_dialogue, k, mode, HyDE, stream):
print(response, end="")
+3 -12
View File
@@ -125,14 +125,12 @@ def get_top_k_blocks(user_query: str, k: int = 10, HyDE: bool = False) -> List[B
# If HyDE is enabled, produce a no-context ChatCompletion to the query.
if HyDE:
messages = [
{"role": "system", "content": "You are a knowledgeable AI Alignment assistant. Do your best to answer the user's question, even if you don't know the answer for sure."},
{"role": "user", "content": user_query},
{"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: {user_query}"},
]
HyDE_completion = openai.ChatCompletion.create(
model=COMPLETIONS_MODEL,
messages=messages,
temperature=0.0,
max_tokens=200
messages=messages
)["choices"][0]["text"]
HyDe_completion_embedding = get_embedding(f"Question: {user_query}\n\nAnswer: {HyDE_completion}")
@@ -155,13 +153,6 @@ def get_top_k_blocks(user_query: str, k: int = 10, HyDE: bool = False) -> List[B
return top_k_blocks
# def embeddings(query):
# # write a function here that takes a query, returns a bunch of semantically similar links
# top_k_blocks = get_top_k_blocks(query, 8, HyDE=False)
# return top_k_blocks
if __name__ == "__main__":
# Test the embeddings function