JDFPalladium commited on
Commit ·
142dea6
1
Parent(s): 0669c52
adding logging as function argument to detect_language
Browse files- app.py +2 -1
- utils/helpers.py +1 -39
app.py
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
# Import libraries
|
| 5 |
import os
|
| 6 |
import json
|
|
|
|
| 7 |
from datetime import datetime
|
| 8 |
from lingua import Language, LanguageDetectorBuilder
|
| 9 |
import gradio as gr
|
|
@@ -66,7 +67,7 @@ def nishauri(user_params: str, conversation_history: list[str]):
|
|
| 66 |
full_text = " ".join(filter(None, info_pieces))
|
| 67 |
|
| 68 |
# detect language of user
|
| 69 |
-
lang_question = helpers.detect_language(question, Language, LanguageDetectorBuilder, client)
|
| 70 |
print(lang_question)
|
| 71 |
|
| 72 |
# If user is making a greeting or acknowledgement, address that accordingly
|
|
|
|
| 4 |
# Import libraries
|
| 5 |
import os
|
| 6 |
import json
|
| 7 |
+
import logging
|
| 8 |
from datetime import datetime
|
| 9 |
from lingua import Language, LanguageDetectorBuilder
|
| 10 |
import gradio as gr
|
|
|
|
| 67 |
full_text = " ".join(filter(None, info_pieces))
|
| 68 |
|
| 69 |
# detect language of user
|
| 70 |
+
lang_question = helpers.detect_language(question, Language, LanguageDetectorBuilder, client, logging)
|
| 71 |
print(lang_question)
|
| 72 |
|
| 73 |
# If user is making a greeting or acknowledgement, address that accordingly
|
utils/helpers.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
def detect_language(text, Language, LanguageDetectorBuilder, client):
|
| 2 |
"""Detect language of a given text using an LLM for short texts and Lingua for longer ones."""
|
| 3 |
text = text.lower().strip()
|
| 4 |
|
|
@@ -36,45 +36,7 @@ def detect_language(text, Language, LanguageDetectorBuilder, client):
|
|
| 36 |
except Exception as e:
|
| 37 |
logging.warning(f"Language detection error (Lingua): {e}")
|
| 38 |
return "unknown"
|
| 39 |
-
|
| 40 |
-
def summarize_conversation(conversation, system_prompt=None):
|
| 41 |
-
"""
|
| 42 |
-
Summarizes a conversation using GPT-4o.
|
| 43 |
-
|
| 44 |
-
Args:
|
| 45 |
-
conversation (list): A list of dicts with 'role' and 'content'.
|
| 46 |
-
system_prompt (str): Optional custom system instruction for summarization.
|
| 47 |
-
|
| 48 |
-
Returns:
|
| 49 |
-
str: The summary of the conversation.
|
| 50 |
-
"""
|
| 51 |
-
# Default system prompt
|
| 52 |
-
if system_prompt is None:
|
| 53 |
-
system_prompt = "You are a helpful assistant that summarizes conversations clearly and concisely."
|
| 54 |
-
|
| 55 |
-
# Compose messages
|
| 56 |
-
messages = [{"role": "system", "content": system_prompt}]
|
| 57 |
-
messages += conversation
|
| 58 |
-
messages.append({
|
| 59 |
-
"role": "user",
|
| 60 |
-
"content": "Please summarize this conversation in a concise and clear paragraph."
|
| 61 |
-
})
|
| 62 |
-
|
| 63 |
-
# Call GPT-4o
|
| 64 |
-
completion = client.chat.completions.create(
|
| 65 |
-
model="gpt-4o",
|
| 66 |
-
messages=messages,
|
| 67 |
-
temperature=0.0
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
return completion.choices[0].message.content
|
| 71 |
|
| 72 |
-
def convert_conversation_format(conversation_history):
|
| 73 |
-
formatted = []
|
| 74 |
-
for turn in conversation_history:
|
| 75 |
-
formatted.append({"role": "user", "content": turn["user"]})
|
| 76 |
-
formatted.append({"role": "assistant", "content": turn["chatbot"]})
|
| 77 |
-
return formatted
|
| 78 |
|
| 79 |
def detect_intention(user_input, client):
|
| 80 |
system_prompt = """
|
|
|
|
| 1 |
+
def detect_language(text, Language, LanguageDetectorBuilder, client, logging):
|
| 2 |
"""Detect language of a given text using an LLM for short texts and Lingua for longer ones."""
|
| 3 |
text = text.lower().strip()
|
| 4 |
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
logging.warning(f"Language detection error (Lingua): {e}")
|
| 38 |
return "unknown"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def detect_intention(user_input, client):
|
| 42 |
system_prompt = """
|