Spaces:
Sleeping
Sleeping
fix client
Browse files- client.py +6 -1
- examples/emails.csv +6 -0
- examples/emails.xlsx +0 -0
- examples/feedback_clients.csv +6 -0
- examples/feedback_clients.xlsx +0 -0
- examples/reviews.csv +101 -0
- examples/reviews_sample.csv +20 -0
- examples/social_posts.csv +6 -0
- examples/social_posts.xlsx +0 -0
- examples/tickets.csv +6 -0
- examples/tickets.xlsx +0 -0
- server.py +5 -3
- test_server.py +18 -7
client.py
CHANGED
@@ -16,11 +16,13 @@ def get_client():
|
|
16 |
def initialize_client(api_key=None):
|
17 |
"""Initialize the OpenAI client with an API key"""
|
18 |
global client
|
|
|
19 |
|
20 |
# Use provided API key or get from environment
|
21 |
api_key = api_key or os.environ.get("OPENAI_API_KEY")
|
22 |
|
23 |
if not api_key:
|
|
|
24 |
return False, "No API key provided"
|
25 |
|
26 |
try:
|
@@ -31,7 +33,10 @@ def initialize_client(api_key=None):
|
|
31 |
messages=[{"role": "user", "content": "test"}],
|
32 |
max_tokens=5,
|
33 |
)
|
|
|
34 |
return True, "API Key updated and verified successfully"
|
35 |
except Exception as e:
|
36 |
client = None
|
37 |
-
|
|
|
|
|
|
16 |
def initialize_client(api_key=None):
|
17 |
"""Initialize the OpenAI client with an API key"""
|
18 |
global client
|
19 |
+
import logging
|
20 |
|
21 |
# Use provided API key or get from environment
|
22 |
api_key = api_key or os.environ.get("OPENAI_API_KEY")
|
23 |
|
24 |
if not api_key:
|
25 |
+
logging.error("No API key provided")
|
26 |
return False, "No API key provided"
|
27 |
|
28 |
try:
|
|
|
33 |
messages=[{"role": "user", "content": "test"}],
|
34 |
max_tokens=5,
|
35 |
)
|
36 |
+
logging.info("API Key updated and verified successfully")
|
37 |
return True, "API Key updated and verified successfully"
|
38 |
except Exception as e:
|
39 |
client = None
|
40 |
+
error_message = f"Failed to initialize client: {str(e)}"
|
41 |
+
logging.error(error_message)
|
42 |
+
return False, error_message
|
examples/emails.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
id,sujet,contenu
|
2 |
+
1,Réunion reportée,"Bonjour, la réunion de demain est reportée à vendredi. Merci."
|
3 |
+
2,Offre commerciale,Veuillez trouver ci-joint notre nouvelle offre. Nous attendons votre retour.
|
4 |
+
3,Problème technique urgent,Mon accès au VPN ne fonctionne plus depuis ce matin.
|
5 |
+
4,Merci,Merci pour votre aide sur le dossier de la semaine dernière !
|
6 |
+
5,Publicité,Découvrez nos nouvelles promotions de printemps !
|
examples/emails.xlsx
ADDED
Binary file (5.74 kB). View file
|
|
examples/feedback_clients.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
client_id,commentaire
|
2 |
+
876,"J’adore la nouvelle interface, elle est beaucoup plus fluide !"
|
3 |
+
877,"Beaucoup trop de bugs dans la dernière version, impossible de l’utiliser"
|
4 |
+
878,"Votre support client est très réactif, merci !"
|
5 |
+
879,"Je ne comprends pas comment accéder à mes factures, ce n’est pas clair du tout"
|
6 |
+
880,Un peu lent sur mobile mais correct dans l’ensemble
|
examples/feedback_clients.xlsx
ADDED
Binary file (5.67 kB). View file
|
|
examples/reviews.csv
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
text
|
2 |
+
"I absolutely love this product! It exceeded all my expectations."
|
3 |
+
"The service was terrible and the staff was rude."
|
4 |
+
"The product arrived on time but was slightly damaged."
|
5 |
+
"I have mixed feelings about this. Some features are great, others not so much."
|
6 |
+
"This is a complete waste of money. Do not buy!"
|
7 |
+
"The customer service team was very helpful in resolving my issue."
|
8 |
+
"It's okay, nothing special but gets the job done."
|
9 |
+
"I'm extremely disappointed with the quality of this product."
|
10 |
+
"This is the best purchase I've made all year!"
|
11 |
+
"It's reasonably priced and works as expected."
|
12 |
+
"The packaging was beautiful but the product inside was disappointing."
|
13 |
+
"I can't believe how fast the shipping was! Amazing service."
|
14 |
+
"This product changed my life - I use it every single day."
|
15 |
+
"Save your money and look elsewhere. Not worth the price."
|
16 |
+
"The quality has gone downhill since my last purchase."
|
17 |
+
"Outstanding value for money - highly recommend!"
|
18 |
+
"The instructions were confusing and unclear."
|
19 |
+
"Perfect size and exactly what I was looking for."
|
20 |
+
"Three months in and still working perfectly."
|
21 |
+
"Wish I had bought this sooner, makes everything easier."
|
22 |
+
"The color is different from what was shown online."
|
23 |
+
"Great product but the price is a bit steep."
|
24 |
+
"Customer support never responded to my emails."
|
25 |
+
"This exceeded my expectations in every way possible."
|
26 |
+
"Decent product but there's room for improvement."
|
27 |
+
"Not as durable as I hoped it would be."
|
28 |
+
"The features are exactly what I needed."
|
29 |
+
"Impressive quality for the price point."
|
30 |
+
"Had to return it - didn't work as advertised."
|
31 |
+
"Simple to use and very effective."
|
32 |
+
"The design is sleek and modern."
|
33 |
+
"Broke after just two weeks of normal use."
|
34 |
+
"Best customer service I've ever experienced."
|
35 |
+
"Average product, nothing to write home about."
|
36 |
+
"The warranty coverage saved me when it malfunctioned."
|
37 |
+
"Fantastic product that delivers on all promises."
|
38 |
+
"The size was much smaller than expected."
|
39 |
+
"Would definitely purchase again!"
|
40 |
+
"Not compatible with my other devices."
|
41 |
+
"The quality control needs serious improvement."
|
42 |
+
"Perfect for what I needed it for."
|
43 |
+
"The product arrived damaged and customer service was unhelpful."
|
44 |
+
"Amazing attention to detail in the design."
|
45 |
+
"The battery life is much shorter than advertised."
|
46 |
+
"Worth every penny - exceptional quality."
|
47 |
+
"The app that comes with it keeps crashing."
|
48 |
+
"Stylish, functional, and reasonably priced."
|
49 |
+
"The material feels cheap and flimsy."
|
50 |
+
"Installation was a nightmare."
|
51 |
+
"Exactly what I was looking for at a great price."
|
52 |
+
"The product stopped working after a month."
|
53 |
+
"Superior quality compared to similar products."
|
54 |
+
"The shipping took forever and tracking wasn't updated."
|
55 |
+
"Love the eco-friendly packaging!"
|
56 |
+
"Not user-friendly at all."
|
57 |
+
"The customer service team went above and beyond."
|
58 |
+
"Mediocre performance for the premium price."
|
59 |
+
"The product looks better in person than online."
|
60 |
+
"Had issues with delivery but the product is great."
|
61 |
+
"Revolutionary design but poor execution."
|
62 |
+
"The learning curve is steeper than expected."
|
63 |
+
"Excellent build quality and durability."
|
64 |
+
"The refund process was quick and hassle-free."
|
65 |
+
"Not worth the hype or the price tag."
|
66 |
+
"Perfect gift - recipient loved it!"
|
67 |
+
"The product arrived earlier than expected."
|
68 |
+
"Disappointing performance overall."
|
69 |
+
"Great value but limited functionality."
|
70 |
+
"The warranty process was straightforward."
|
71 |
+
"Innovative features but needs refinement."
|
72 |
+
"Outstanding product and company ethics."
|
73 |
+
"The size chart was completely inaccurate."
|
74 |
+
"Regular updates keep improving the product."
|
75 |
+
"Terrible customer experience from start to finish."
|
76 |
+
"The product exceeded industry standards."
|
77 |
+
"Beautiful design but impractical to use."
|
78 |
+
"Fast shipping but poor packaging."
|
79 |
+
"Life-changing product for daily use."
|
80 |
+
"The quality justifies the premium price."
|
81 |
+
"Defective on arrival and no response from seller."
|
82 |
+
"Perfect balance of features and simplicity."
|
83 |
+
"The interface is very intuitive."
|
84 |
+
"Product arrived damaged but replacement was quick."
|
85 |
+
"Great value for a premium product."
|
86 |
+
"Customer service was exceptional."
|
87 |
+
"The build quality is outstanding."
|
88 |
+
"Instructions were confusing and unclear."
|
89 |
+
"Shipping was faster than expected."
|
90 |
+
"The product works as advertised."
|
91 |
+
"Not compatible with my setup."
|
92 |
+
"Easy to install and configure."
|
93 |
+
"The warranty coverage is comprehensive."
|
94 |
+
"Excellent product but expensive shipping."
|
95 |
+
"The mobile app needs improvement."
|
96 |
+
"Perfect for small spaces."
|
97 |
+
"Technical support was very helpful."
|
98 |
+
"The product feels durable and well-made."
|
99 |
+
"Color matches the online photos perfectly."
|
100 |
+
"Setup was straightforward and quick."
|
101 |
+
|
examples/reviews_sample.csv
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
text
|
2 |
+
"I absolutely love this product! It exceeded all my expectations."
|
3 |
+
"The service was terrible and the staff was rude."
|
4 |
+
"The product arrived on time but was slightly damaged."
|
5 |
+
"I have mixed feelings about this. Some features are great, others not so much."
|
6 |
+
"This is a complete waste of money. Do not buy!"
|
7 |
+
"The customer service team was very helpful in resolving my issue."
|
8 |
+
"It's okay, nothing special but gets the job done."
|
9 |
+
"I'm extremely disappointed with the quality of this product."
|
10 |
+
"This is the best purchase I've made all year!"
|
11 |
+
"It's reasonably priced and works as expected."
|
12 |
+
"The packaging was beautiful but the product inside was disappointing."
|
13 |
+
"I can't believe how fast the shipping was! Amazing service."
|
14 |
+
"This product changed my life - I use it every single day."
|
15 |
+
"Save your money and look elsewhere. Not worth the price."
|
16 |
+
"The quality has gone downhill since my last purchase."
|
17 |
+
"Outstanding value for money - highly recommend!"
|
18 |
+
"The instructions were confusing and unclear."
|
19 |
+
"Perfect size and exactly what I was looking for."
|
20 |
+
"Three months in and still working perfectly."
|
examples/social_posts.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
id_post,texte
|
2 |
+
P01,Nouvelle fonctionnalité déployée ! Vous pouvez désormais trier vos tâches par priorité.
|
3 |
+
P02,Bug sur la version Android corrigé ✅ Merci pour votre patience !
|
4 |
+
P03,Que pensez-vous de notre design ? Donnez-nous vos retours 🙏
|
5 |
+
P04,Concours ! Gagnez un abonnement en répondant à ce tweet 🎁
|
6 |
+
P05,"Impossible de me connecter aujourd’hui, ça rame à mort 😤"
|
examples/social_posts.xlsx
ADDED
Binary file (5.72 kB). View file
|
|
examples/tickets.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ticket_id,description
|
2 |
+
101,L’application plante au démarrage sur mon téléphone Android.
|
3 |
+
102,Je souhaite changer mon mot de passe.
|
4 |
+
103,"Mon paiement a été refusé, pouvez-vous vérifier ?"
|
5 |
+
104,Juste un retour pour vous dire bravo pour la dernière mise à jour !
|
6 |
+
105,Le formulaire ne valide pas les adresses emails correctement.
|
examples/tickets.xlsx
ADDED
Binary file (5.65 kB). View file
|
|
server.py
CHANGED
@@ -6,7 +6,7 @@ import json
|
|
6 |
from classifiers.llm import LLMClassifier
|
7 |
from litellm import completion
|
8 |
import asyncio
|
9 |
-
|
10 |
app = FastAPI()
|
11 |
|
12 |
# Configure CORS
|
@@ -18,8 +18,10 @@ app.add_middleware(
|
|
18 |
allow_headers=["*"],
|
19 |
)
|
20 |
|
|
|
|
|
21 |
# Initialize the LLM classifier
|
22 |
-
classifier = LLMClassifier(client=
|
23 |
|
24 |
class TextInput(BaseModel):
|
25 |
text: str
|
@@ -61,4 +63,4 @@ async def suggest_categories(texts: List[str]):
|
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
import uvicorn
|
64 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
6 |
from classifiers.llm import LLMClassifier
|
7 |
from litellm import completion
|
8 |
import asyncio
|
9 |
+
from client import get_client
|
10 |
app = FastAPI()
|
11 |
|
12 |
# Configure CORS
|
|
|
18 |
allow_headers=["*"],
|
19 |
)
|
20 |
|
21 |
+
client = get_client()
|
22 |
+
|
23 |
# Initialize the LLM classifier
|
24 |
+
classifier = LLMClassifier(client=client, model="gpt-3.5-turbo")
|
25 |
|
26 |
class TextInput(BaseModel):
|
27 |
text: str
|
|
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
import uvicorn
|
66 |
+
uvicorn.run("server:app", host="0.0.0.0", port=8000, reload=True)
|
test_server.py
CHANGED
@@ -4,23 +4,34 @@ import json
|
|
4 |
BASE_URL = "http://localhost:8000"
|
5 |
|
6 |
def test_classify_text():
|
7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
response = requests.post(
|
9 |
f"{BASE_URL}/classify",
|
10 |
-
json={"text": "
|
11 |
)
|
12 |
-
print("Classification with default categories:")
|
13 |
print(json.dumps(response.json(), indent=2))
|
14 |
|
15 |
-
# Test with custom categories
|
|
|
16 |
response = requests.post(
|
17 |
f"{BASE_URL}/classify",
|
18 |
json={
|
19 |
-
"text": "
|
20 |
-
"categories": ["
|
21 |
}
|
22 |
)
|
23 |
-
print("\nClassification with custom categories:")
|
24 |
print(json.dumps(response.json(), indent=2))
|
25 |
|
26 |
def test_suggest_categories():
|
|
|
4 |
BASE_URL = "http://localhost:8000"
|
5 |
|
6 |
def test_classify_text():
|
7 |
+
# Load emails from CSV file
|
8 |
+
import csv
|
9 |
+
|
10 |
+
emails = []
|
11 |
+
with open("examples/emails.csv", "r", encoding="utf-8") as file:
|
12 |
+
reader = csv.DictReader(file)
|
13 |
+
for row in reader:
|
14 |
+
emails.append(row)
|
15 |
+
|
16 |
+
# Test with default categories using email content
|
17 |
+
email = emails[0] # First email
|
18 |
response = requests.post(
|
19 |
f"{BASE_URL}/classify",
|
20 |
+
json={"text": email["contenu"]}
|
21 |
)
|
22 |
+
print(f"Classification of email '{email['sujet']}' with default categories:")
|
23 |
print(json.dumps(response.json(), indent=2))
|
24 |
|
25 |
+
# Test with custom categories using another email
|
26 |
+
email = emails[2] # Third email
|
27 |
response = requests.post(
|
28 |
f"{BASE_URL}/classify",
|
29 |
json={
|
30 |
+
"text": email["contenu"],
|
31 |
+
"categories": ["Urgent", "Technique", "Commercial", "Personnel"]
|
32 |
}
|
33 |
)
|
34 |
+
print(f"\nClassification of email '{email['sujet']}' with custom categories:")
|
35 |
print(json.dumps(response.json(), indent=2))
|
36 |
|
37 |
def test_suggest_categories():
|