Created
November 5, 2025 19:07
-
-
Save zseta/850945eea54d0cda22854ecd71758dc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def semantic_cached_prompt(prompt): | |
| """Retrieve a response from ScyllaDB or ask OpenAI if it's a new prompt. | |
| Args: | |
| prompt (str): The user prompt. | |
| Returns: | |
| str: The response to the prompt. | |
| """ | |
| embedding = create_embedding(prompt) | |
| cached_response = search_cache(embedding, threshold=0.80) | |
| if cached_response: | |
| print("Cache hit! Returning cached response...") | |
| return cached_response | |
| else: | |
| print("Cache miss... sending request to OpenAI!") | |
| response = ask_openai(prompt) | |
| insert_to_cache(prompt, embedding, response) | |
| return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment