TymaaHammouda commited on
Commit
8cd4d68
·
verified ·
1 Parent(s): 5f20637

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py CHANGED
@@ -122,3 +122,49 @@ def predict(request: ConflictDetectionRequest):
122
 
123
  except Exception as e:
124
  return JSONResponse({"error": str(e)}, status_code=500)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  except Exception as e:
124
  return JSONResponse({"error": str(e)}, status_code=500)
125
+
126
+
127
+ def run_fanar_to_resolve(req1, req2):
128
+ client = OpenAI(base_url="https://api.fanar.qa/v1", api_key=os.getenv("FANAR_API"))
129
+ prompt = f"""
130
+ You are a requirements engineer. You are given two potentially conflicting requirements.
131
+
132
+
133
+ Requirement 1: "{req1}"
134
+ Requirement 2: "{req2}"
135
+
136
+
137
+ Your task is to resolve the conflict in Arabic using a hybrid strategy:
138
+ 1. If possible, combine both requirements into **a single non-conflicting and concise requirement** that preserves the intent of both.
139
+ 2. If they cannot be merged clearly, rewrite them as **two separate non-conflicting requirements**, possibly by adding conditions, default cases, or clarifying their scope.
140
+
141
+
142
+ Avoid using vague expressions such as 'as needed', 'if possible', or 'may'. Only merge requirements if they can be resolved clearly and deterministically. Otherwise, indicate that clarification is needed.
143
+
144
+
145
+ The resolved output must follow proper software requirement language and be easy to test.
146
+
147
+
148
+ Format your answer like this:
149
+ [Resolution Type]: Single / Split
150
+ Resolved Requirement(s):
151
+ - ...
152
+ """
153
+
154
+ response = client.chat.completions.create(
155
+ model="Fanar",
156
+ messages=[{"role": "user", "content": prompt}]
157
+ )
158
+ return response.choices[0].message.content.strip()
159
+
160
+
161
+ class ConflictResoluionRequest(BaseModel):
162
+ Req1: str
163
+ Req2: str
164
+
165
+
166
+ @app.post("/resolve")
167
+ def resolve(request: ConflictResoluionRequest):
168
+ answer = run_fanar_to_resolve(request.Req1, request.Req2)
169
+ return JSONResponse({"resp": answer, "statusText": "OK", "statusCode": 0}, status_code=200)
170
+