Update app.py
Browse files
app.py
CHANGED
|
@@ -47,24 +47,8 @@ def gpt_inference(base_url, model, openai_key, prompt):
|
|
| 47 |
}
|
| 48 |
|
| 49 |
response = requests.post(f"{base_url}/v1/chat/completions", headers=headers, data=json.dumps(data))
|
| 50 |
-
|
| 51 |
-
def extract_code(text):
|
| 52 |
-
# Match triple backtick blocks first
|
| 53 |
-
triple_match = re.search(r'```(?:\w+\n)?(.+?)```', text, re.DOTALL)
|
| 54 |
-
if triple_match:
|
| 55 |
-
return triple_match.group(1).strip()
|
| 56 |
-
else:
|
| 57 |
-
# If no triple backtick blocks, match single backtick blocks
|
| 58 |
-
single_match = re.search(r'`(.+?)`', text, re.DOTALL)
|
| 59 |
-
if single_match:
|
| 60 |
-
return single_match.group(1).strip()
|
| 61 |
-
# If no code blocks found, return original text
|
| 62 |
-
return text
|
| 63 |
-
|
| 64 |
-
if response.status_code != 200:
|
| 65 |
-
return "Error: " + response.text, 500
|
| 66 |
|
| 67 |
-
code =
|
| 68 |
print(f"code:{code}")
|
| 69 |
img = execute_code(code)
|
| 70 |
return img
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
response = requests.post(f"{base_url}/v1/chat/completions", headers=headers, data=json.dumps(data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
code = response.json()["choices"][0]["message"]["content"]
|
| 52 |
print(f"code:{code}")
|
| 53 |
img = execute_code(code)
|
| 54 |
return img
|