|
471 | 471 | " return response.model_dump()\n", |
472 | 472 | "\n", |
473 | 473 | "def chat_completion(cache_container, movies_container, user_input):\n", |
474 | | - "\n", |
| 474 | + " print(\"starting completion\")\n", |
475 | 475 | " # Generate embeddings from the user input\n", |
476 | 476 | " user_embeddings = generate_embeddings(user_input)\n", |
477 | 477 | " # Query the chat history cache first to see if this question has been asked before\n", |
478 | | - " cache_results = vector_search(container = cache_container, vectors = user_embeddings, similarity_score=0.99, num_results=1)\n", |
479 | | - "\n", |
| 478 | + " cache_results = get_cache(container = cache_container, vectors = user_embeddings, similarity_score=0.99, num_results=1)\n", |
480 | 479 | " if len(cache_results) > 0:\n", |
481 | | - " print(\"\\n Cached Result\\n\")\n", |
482 | | - " return cache_results[0]['document']['completion']\n", |
| 480 | + " print(\"Cached Result\\n\")\n", |
| 481 | + " return cache_results[0]['completion'], True\n", |
483 | 482 | " \n", |
484 | 483 | " else:\n", |
485 | | - " \n", |
486 | 484 | " #perform vector search on the movie collection\n", |
487 | | - " print(\"\\n New result\\n\")\n", |
| 485 | + " print(\"New result\\n\")\n", |
488 | 486 | " search_results = vector_search(movies_container, user_embeddings)\n", |
489 | 487 | "\n", |
490 | 488 | " print(\"Getting Chat History\\n\")\n", |
491 | 489 | " #chat history\n", |
492 | 490 | " chat_history = get_chat_history(cache_container, 3)\n", |
493 | | - "\n", |
494 | 491 | " #generate the completion\n", |
495 | 492 | " print(\"Generating completions \\n\")\n", |
496 | 493 | " completions_results = generate_completion(user_input, search_results, chat_history)\n", |
|
501 | 498 | "\n", |
502 | 499 | " print(\"\\n\")\n", |
503 | 500 | " # Return the generated LLM completion\n", |
504 | | - " return completions_results['choices'][0]['message']['content'] " |
| 501 | + " return completions_results['choices'][0]['message']['content'], False" |
505 | 502 | ] |
506 | 503 | }, |
507 | 504 | { |
|
0 commit comments