rrg92 commited on
Commit
ec665ad
·
1 Parent(s): c9fd6d7

Some fixes in lang, field size and search

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -146,6 +146,7 @@ Reranker = CrossEncoder("mixedbread-ai/mxbai-rerank-large-v1", activation_fn=nn.
146
 
147
  class rfTranslatedText(BaseModel):
148
  text: str = Field(description='Translated text')
 
149
 
150
  class rfGenericText(BaseModel):
151
  text: str = Field(description='The text result')
@@ -197,7 +198,7 @@ def ChatFunc(message, history):
197
  m = BotMessage(msg);
198
  return ChatBotOutput();
199
 
200
- m = BotMessage("",metadata={"title":"Procurando scripts...","status":"pending"});
201
 
202
 
203
  def OnConnError(err):
@@ -208,26 +209,29 @@ def ChatFunc(message, history):
208
  # Responder algo sobre o historico!
209
  if IsNewSearch:
210
 
211
- yield m("Melhorando o prompt")
212
 
213
-
214
  LLMResult = ai("""
215
  Translate the user's message to English.
216
  The message is a question related to a SQL Server T-SQL script that the user is searching for.
217
- You only need to translate the message to English.
 
 
 
218
  """,message, rfTranslatedText)
219
  Question = LLMResult.message.parsed.text;
 
220
 
221
- yield m(f"Melhorado: {Question}")
222
 
223
- yield m("Procurando scripts...")
224
  try:
225
- FoundScripts = search(message, onConnectionError = OnConnError)
226
  except:
227
  yield m("Houve alguma falha ao executar a consulta no banco. Tente novamente. Se persistir, veja orientações na aba Help!")
228
  return;
229
 
230
- yield m("Fazendo o rerank");
231
  doclist = [doc['ScriptContent'] for doc in FoundScripts]
232
 
233
  # Faz o reranker!
@@ -253,20 +257,21 @@ def ChatFunc(message, history):
253
 
254
 
255
  CurrentTable = pd.DataFrame(ScriptTable)
256
- yield m("Script encontrados, a aba Rank atualizada!")
257
 
258
 
259
- WaitMessage = ai("""
260
  You will analyze some T-SQL scripts in order to check which is best for the user.
261
  You found scripts, presented them to the user, and now will do some work that takes time.
262
  Generate a message to tell the user to wait while you work, in the same language as the user.
263
  You will receive the question the user sent that triggered this process.
264
  Use the user’s original question to customize the message.
 
265
  """,message,rfGenericText).message.parsed.text
266
 
267
  yield Reply(WaitMessage);
268
 
269
- yield m(f"Analisando scripts...")
270
 
271
 
272
  ResultJson = json.dumps(RankedScripts);
@@ -290,7 +295,6 @@ def ChatFunc(message, history):
290
  Re-rank the results if necessary, presenting them from the most to the least relevant.
291
  You may filter out scripts that appear unrelated to the user query.
292
 
293
- Respond in the user's original language.
294
  ---
295
  ### Output Rules
296
 
@@ -298,7 +302,8 @@ def ChatFunc(message, history):
298
  - Summarize each script, ordering from the most relevant to the least relevant.
299
  - Write personalized and informative review text for each recommendation.
300
  - If applicable, explain how the user should run the script, including parameters or sections (like `WHERE` clauses) they might need to customize.
301
- - When referencing a script, include the link provided in the JSON — all scripts are hosted on GitHub.
 
302
  """
303
 
304
  ScriptPrompt = [
@@ -328,7 +333,7 @@ with gr.Blocks(fill_height=True) as demo:
328
  with gr.Column():
329
 
330
  with gr.Tab("Chat", scale = 1):
331
- ChatTextBox = gr.Textbox(max_length = 100, info = "Que script precisa?", submit_btn = True);
332
 
333
  gr.ChatInterface(
334
  ChatFunc
 
146
 
147
  class rfTranslatedText(BaseModel):
148
  text: str = Field(description='Translated text')
149
+ lang: str = Field(description='source language')
150
 
151
  class rfGenericText(BaseModel):
152
  text: str = Field(description='The text result')
 
198
  m = BotMessage(msg);
199
  return ChatBotOutput();
200
 
201
+ m = BotMessage("",metadata={"title":"Searching scripts...","status":"pending"});
202
 
203
 
204
  def OnConnError(err):
 
209
  # Responder algo sobre o historico!
210
  if IsNewSearch:
211
 
212
+ yield m("Enhancing the prompt...")
213
 
 
214
  LLMResult = ai("""
215
  Translate the user's message to English.
216
  The message is a question related to a SQL Server T-SQL script that the user is searching for.
217
+ You must do following actions:
218
+ - Identify the language of user text, using BCP 47 code (example: pt-BR, en-US, ja-JP, etc.)
219
+ - Generate translated user text to english
220
+ Return both source language and translated text.
221
  """,message, rfTranslatedText)
222
  Question = LLMResult.message.parsed.text;
223
+ SourceLang = LLMResult.message.parsed.lang;
224
 
225
+ yield m(f"Lang:{SourceLang}, English Prompt: {Question}")
226
 
227
+ yield m("searching...")
228
  try:
229
+ FoundScripts = search(Question, onConnectionError = OnConnError)
230
  except:
231
  yield m("Houve alguma falha ao executar a consulta no banco. Tente novamente. Se persistir, veja orientações na aba Help!")
232
  return;
233
 
234
+ yield m("Doing rerank");
235
  doclist = [doc['ScriptContent'] for doc in FoundScripts]
236
 
237
  # Faz o reranker!
 
257
 
258
 
259
  CurrentTable = pd.DataFrame(ScriptTable)
260
+ yield m("Found scripts, check Rank tab for details!")
261
 
262
 
263
+ WaitMessage = ai(f"""
264
  You will analyze some T-SQL scripts in order to check which is best for the user.
265
  You found scripts, presented them to the user, and now will do some work that takes time.
266
  Generate a message to tell the user to wait while you work, in the same language as the user.
267
  You will receive the question the user sent that triggered this process.
268
  Use the user’s original question to customize the message.
269
+ Answer in lang: {SourceLang}
270
  """,message,rfGenericText).message.parsed.text
271
 
272
  yield Reply(WaitMessage);
273
 
274
+ yield m(f"Analyzing scripts...")
275
 
276
 
277
  ResultJson = json.dumps(RankedScripts);
 
295
  Re-rank the results if necessary, presenting them from the most to the least relevant.
296
  You may filter out scripts that appear unrelated to the user query.
297
 
 
298
  ---
299
  ### Output Rules
300
 
 
302
  - Summarize each script, ordering from the most relevant to the least relevant.
303
  - Write personalized and informative review text for each recommendation.
304
  - If applicable, explain how the user should run the script, including parameters or sections (like `WHERE` clauses) they might need to customize.
305
+ - When referencing a script, include the link provided in the JSON — all scripts are hosted on GitHub
306
+ - YOU MUST ANSWER THAT LANGUAGE: {SourceLang}
307
  """
308
 
309
  ScriptPrompt = [
 
333
  with gr.Column():
334
 
335
  with gr.Tab("Chat", scale = 1):
336
+ ChatTextBox = gr.Textbox(max_length = 500, info = "Which script are you looking for?", submit_btn = True);
337
 
338
  gr.ChatInterface(
339
  ChatFunc