Skip to content

Commit f75e046

Browse files
committed
Optimize prompt of GenAI, optimize codeGen ignore
1 parent a550661 commit f75e046

11 files changed

+228
-652
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
## 🚀 Quick Start (≤3 Commands)
44

5-
**Prerequisites:** Install code generation dependencies first:
5+
**Prerequisites:**
6+
- [Node.js](https://nodejs.org/) (v22+)
7+
- [Docker](https://www.docker.com/get-started/)
8+
- [Docker Compose](https://docs.docker.com/compose/install/)
9+
10+
Then install code generation dependencies:
611
```bash
712
npm install
813
```

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ services:
133133
- CONCEPT_SERVICE_URL=http://concept-svc:8080
134134
- OPENWEBUI_MODEL=llama3.3:latest
135135
- OPENWEBUI_API_TOKEN=your_api_token # REPLACE WITH YOUR TOKEN!!
136+
- OPENWEBUI_API_URL=https://gpu.aet.cit.tum.de/api
136137
depends_on:
137138
- genai-svc-weaviate
138139
- genai-svc-minio

genai-svc/services/concept_extractor.py

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class ConceptExtractor:
1313
"""Extracts concept suggestions from LLM responses"""
1414

1515
def extract_concept_suggestion(self, response_text: str) -> ChatResponseConceptSuggestion:
16-
"""Extract concept suggestions from the response text"""
16+
"""Extract concept suggestions from the response text. Assumes a complete JSON block is always present."""
1717
# Initialize with default values
1818
title = "Event Concept Suggestion"
19-
description = response_text
19+
description = ""
2020
event_details = None
2121
agenda = []
2222
speakers = []
@@ -25,71 +25,74 @@ def extract_concept_suggestion(self, response_text: str) -> ChatResponseConceptS
2525
reasoning = ""
2626
confidence = 0.9
2727

28-
# Try to extract JSON from the response
28+
# Always extract JSON from the response
2929
json_data = self._extract_json_from_text(response_text)
30+
if not json_data:
31+
# If no JSON found, return a minimal suggestion
32+
return ChatResponseConceptSuggestion(
33+
title=title,
34+
description=response_text,
35+
event_details=None,
36+
agenda=None,
37+
speakers=None,
38+
pricing=None,
39+
notes=notes,
40+
reasoning=reasoning,
41+
confidence=confidence
42+
)
43+
44+
# Extract all fields from JSON, using empty string or None for missing values
45+
title = json_data.get("title", "")
46+
description = json_data.get("description", "")
47+
notes = json_data.get("notes", "")
48+
reasoning = json_data.get("reasoning", "")
49+
50+
# Event details
51+
event_details_data = json_data.get("eventDetails", {})
52+
event_details = ChatResponseConceptSuggestionEventDetails(
53+
theme=event_details_data.get("theme", ""),
54+
format=event_details_data.get("format", "").upper() if event_details_data.get("format") else None,
55+
capacity=event_details_data.get("capacity"),
56+
duration=event_details_data.get("duration", ""),
57+
target_audience=event_details_data.get("targetAudience", ""),
58+
location=event_details_data.get("location", "")
59+
) if event_details_data else None
60+
61+
# Agenda
62+
agenda = [
63+
ChatResponseConceptSuggestionAgendaInner(
64+
time=item.get("time", ""),
65+
title=item.get("title", ""),
66+
type=item.get("type", "KEYNOTE"),
67+
duration=item.get("duration", 60)
68+
) for item in json_data.get("agenda", [])
69+
] or None
70+
71+
# Speakers
72+
speakers = [
73+
ChatResponseConceptSuggestionSpeakersInner(
74+
name=speaker.get("name", ""),
75+
expertise=speaker.get("expertise", ""),
76+
suggested_topic=speaker.get("suggestedTopic", "")
77+
) for speaker in json_data.get("speakers", [])
78+
] or None
79+
80+
# Pricing
81+
pricing_data = json_data.get("pricing", {})
82+
pricing = ChatResponseConceptSuggestionPricing(
83+
currency=pricing_data.get("currency", "USD"),
84+
regular=pricing_data.get("regular"),
85+
early_bird=pricing_data.get("earlyBird"),
86+
vip=pricing_data.get("vip"),
87+
student=pricing_data.get("student")
88+
) if pricing_data else None
3089

31-
if json_data:
32-
# Extract data from JSON
33-
if "title" in json_data:
34-
title = json_data["title"]
35-
36-
# Extract event details
37-
if "eventDetails" in json_data:
38-
event_details_data = json_data["eventDetails"]
39-
event_details = ChatResponseConceptSuggestionEventDetails(
40-
theme=event_details_data.get("theme"),
41-
format=event_details_data.get("format", "").upper() if event_details_data.get("format") else None,
42-
capacity=event_details_data.get("capacity"),
43-
duration=event_details_data.get("duration"),
44-
target_audience=event_details_data.get("targetAudience"),
45-
location=event_details_data.get("location")
46-
)
47-
48-
# Extract agenda
49-
if "agenda" in json_data and json_data["agenda"]:
50-
for agenda_item in json_data["agenda"]:
51-
agenda.append(ChatResponseConceptSuggestionAgendaInner(
52-
time=agenda_item.get("time", ""),
53-
title=agenda_item.get("title", ""),
54-
type=agenda_item.get("type", "KEYNOTE"),
55-
duration=agenda_item.get("duration", 60)
56-
))
57-
58-
# Extract speakers
59-
if "speakers" in json_data and json_data["speakers"]:
60-
for speaker in json_data["speakers"]:
61-
speakers.append(ChatResponseConceptSuggestionSpeakersInner(
62-
name=speaker.get("name", ""),
63-
expertise=speaker.get("expertise", ""),
64-
suggested_topic=speaker.get("suggestedTopic", "")
65-
))
66-
67-
# Extract pricing
68-
if "pricing" in json_data:
69-
pricing_data = json_data["pricing"]
70-
pricing = ChatResponseConceptSuggestionPricing(
71-
currency=pricing_data.get("currency", "USD"),
72-
regular=pricing_data.get("regular"),
73-
early_bird=pricing_data.get("earlyBird"),
74-
vip=pricing_data.get("vip"),
75-
student=pricing_data.get("student")
76-
)
77-
78-
# Extract notes and reasoning
79-
if "notes" in json_data:
80-
notes = json_data["notes"]
81-
82-
if "reasoning" in json_data:
83-
reasoning = json_data["reasoning"]
84-
# No fallback to legacy method - we expect the LLM to always include a JSON object
85-
86-
# Create and return the concept suggestion object
8790
return ChatResponseConceptSuggestion(
8891
title=title,
8992
description=description,
9093
event_details=event_details,
91-
agenda=agenda if agenda else None,
92-
speakers=speakers if speakers else None,
94+
agenda=agenda,
95+
speakers=speakers,
9396
pricing=pricing,
9497
notes=notes,
9598
reasoning=reasoning,
@@ -194,4 +197,4 @@ def _extract_json_from_text(self, text: str) -> dict:
194197

195198

196199
# Create a singleton instance
197-
concept_extractor = ConceptExtractor()
200+
concept_extractor = ConceptExtractor()

0 commit comments

Comments
 (0)