SergeyO7 commited on
Commit
fd2c8ea
·
verified ·
1 Parent(s): 165f692

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -81,20 +81,39 @@ def process_query(query_text: str, vectorstore):
81
  for doc, score in results
82
  ])
83
 
 
 
 
84
  # Формируем строковый промпт для модели
85
- prompt = f"Answer the question based on the following context:\n{context_text}\n\nQuestion: {query_text}"
86
 
87
  # Используем модель t5-base для text2text-generation
 
 
 
 
 
 
 
 
 
88
  model = HuggingFaceEndpoint(
89
- repo_id="t5-base",
90
  task="text2text-generation",
91
- temperature=0.5,
92
- max_length=512,
93
- # huggingfacehub_api_token=os.getenv("HUGGINGFACEHUB_API_TOKEN") # Раскомментируйте, если нужен токен
94
  )
95
 
96
  # Передаем строковый промпт
97
- response_text = model.invoke(prompt)
 
 
 
 
 
 
 
 
 
 
98
 
99
  sources = list(set([doc.metadata.get("source", "") for doc, _ in results]))
100
  return response_text, sources
 
81
  for doc, score in results
82
  ])
83
 
84
+ # Формируем промпт в формате, который понимает T5
85
+ prompt = f"question: {query_text} context: {context_text}"
86
+
87
  # Формируем строковый промпт для модели
88
+ #prompt = f"Answer the question based on the following context:\n{context_text}\n\nQuestion: {query_text}"
89
 
90
  # Используем модель t5-base для text2text-generation
91
+ #model = HuggingFaceEndpoint(
92
+ # repo_id="t5-base",
93
+ # task="text2text-generation",
94
+ # temperature=0.5,
95
+ # max_length=512,
96
+ # # huggingfacehub_api_token=os.getenv("HUGGINGFACEHUB_API_TOKEN") # Раскомментируйте, если нужен токен
97
+ #)
98
+
99
+ # Инициализация модели с базовыми параметрами
100
  model = HuggingFaceEndpoint(
101
+ repo_id="google/flan-t5-small", # Используем Flan-T5 вместо t5-base
102
  task="text2text-generation",
 
 
 
103
  )
104
 
105
  # Передаем строковый промпт
106
+ #response_text = model.invoke(prompt)
107
+
108
+ # Вызов модели с параметрами генерации
109
+ response_text = model.invoke(
110
+ prompt,
111
+ generation_kwargs={
112
+ "max_length": 512,
113
+ "temperature": 0.5,
114
+ "repetition_penalty": 1.2
115
+ }
116
+ )
117
 
118
  sources = list(set([doc.metadata.get("source", "") for doc, _ in results]))
119
  return response_text, sources