Update backend/ai_decoder.py
Browse files- backend/ai_decoder.py +11 -14
backend/ai_decoder.py
CHANGED
|
@@ -1,24 +1,21 @@
|
|
| 1 |
import os
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
client =
|
| 6 |
|
| 7 |
def decode_semantic_intent(corrupted_text: str) -> str:
|
| 8 |
-
prompt = f"
|
| 9 |
-
A message was mathematically destroyed by wireless noise.
|
| 10 |
-
The traditional mathematical demodulator outputted this gibberish: '{corrupted_text}'
|
| 11 |
-
|
| 12 |
-
Based on linguistic probability, reconstruct the original intent of the message perfectly.
|
| 13 |
-
Only output the corrected sentence. Do not add any conversational text."""
|
| 14 |
|
| 15 |
try:
|
| 16 |
-
response = client.
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
temperature=0.1
|
| 21 |
)
|
| 22 |
-
return response.strip()
|
| 23 |
except Exception as e:
|
| 24 |
return f"AI Decoding Failed: {str(e)}"
|
|
|
|
| 1 |
import os
|
| 2 |
+
from openai import OpenAI
|
| 3 |
|
| 4 |
+
# Automatically reads the OPENAI_API_KEY from your Space Secrets
|
| 5 |
+
client = OpenAI()
|
| 6 |
|
| 7 |
def decode_semantic_intent(corrupted_text: str) -> str:
|
| 8 |
+
prompt = f"A message was destroyed by wireless noise. The demodulator outputted: '{corrupted_text}'. Reconstruct the original intent perfectly. Only output the corrected sentence."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
try:
|
| 11 |
+
response = client.chat.completions.create(
|
| 12 |
+
model="gpt-4o-mini",
|
| 13 |
+
messages=[
|
| 14 |
+
{"role": "system", "content": "You are a 6G Semantic Communication Decoder."},
|
| 15 |
+
{"role": "user", "content": prompt}
|
| 16 |
+
],
|
| 17 |
temperature=0.1
|
| 18 |
)
|
| 19 |
+
return response.choices[0].message.content.strip()
|
| 20 |
except Exception as e:
|
| 21 |
return f"AI Decoding Failed: {str(e)}"
|