Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add question caching #82

Open
pamelafox opened this issue Sep 25, 2024 · 0 comments
Open

Add question caching #82

pamelafox opened this issue Sep 25, 2024 · 0 comments

Comments

@pamelafox
Copy link
Contributor

pamelafox commented Sep 25, 2024

Description

Add a question caching feature. Pseudocode based on other repo-

def chat_completion(user_input):
   # Generate embeddings from the user input
   user_embeddings = generate_embeddings(openai_client, user_input)
   # Query the chat history cache first to see if this question has been asked before
   cache_results = cache_search(vectors=user_embeddings , num_results=1)
 
   if len(cache_results) > 0:
       return cache_results[0]['completion'], True
   else:
       # Perform vector search 
       search_results = get_similar_docs(openai_client, dbsource, user_input, 3)
       print("Getting Chat History\n")
       # Chat history
       chat_history = get_chat_history(1)
 
       # Generate the completion
       print("Generating completions \n")
       completions_results = generatecompletionede(user_input, search_results, chat_history)
 
       # Cache the response
       cacheresponse(user_input, user_embeddings, completions_results)
 
       print("\n")
       # Return the generated LLM completion
       return completions_results['choices'][0]['message']['content'], False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant