Spaces:
Build error
Build error
Hjgugugjhuhjggg
commited on
Commit
•
1e6f7d7
1
Parent(s):
b327dbd
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4 |
import torch
|
5 |
from fastapi import FastAPI
|
6 |
from langchain.llms import VLLM
|
7 |
-
from
|
8 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
9 |
from sklearn.metrics.pairwise import cosine_similarity
|
10 |
import nltk
|
@@ -27,10 +27,11 @@ model_2 = None
|
|
27 |
model_3 = None
|
28 |
model_4 = None
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
previous_responses_1 = []
|
36 |
previous_responses_2 = []
|
@@ -149,7 +150,7 @@ def create_langchain_model(model_name: str, device: torch.device, cache, previou
|
|
149 |
prev_output = output_text.split()[-50:]
|
150 |
output_chunks = split_output(output_text, MAX_TOKENS)
|
151 |
best_response = get_best_response(output_chunks[0], previous_responses)
|
152 |
-
cache
|
153 |
previous_responses.append(best_response)
|
154 |
return best_response
|
155 |
return generate_for_model
|
|
|
4 |
import torch
|
5 |
from fastapi import FastAPI
|
6 |
from langchain.llms import VLLM
|
7 |
+
from cachetools import TTLCache
|
8 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
9 |
from sklearn.metrics.pairwise import cosine_similarity
|
10 |
import nltk
|
|
|
27 |
model_3 = None
|
28 |
model_4 = None
|
29 |
|
30 |
+
# Using TTLCache from cachetools
|
31 |
+
cache_1 = TTLCache(maxsize=100, ttl=600) # maxsize=100 and ttl=600 (10 minutes)
|
32 |
+
cache_2 = TTLCache(maxsize=100, ttl=600)
|
33 |
+
cache_3 = TTLCache(maxsize=100, ttl=600)
|
34 |
+
cache_4 = TTLCache(maxsize=100, ttl=600)
|
35 |
|
36 |
previous_responses_1 = []
|
37 |
previous_responses_2 = []
|
|
|
150 |
prev_output = output_text.split()[-50:]
|
151 |
output_chunks = split_output(output_text, MAX_TOKENS)
|
152 |
best_response = get_best_response(output_chunks[0], previous_responses)
|
153 |
+
cache[input_text] = best_response
|
154 |
previous_responses.append(best_response)
|
155 |
return best_response
|
156 |
return generate_for_model
|