Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,14 +33,12 @@ MODELS = {
|
|
| 33 |
},
|
| 34 |
},
|
| 35 |
"Mistral Small": {
|
|
|
|
| 36 |
"api_url": "https://ezofisai.services.ai.azure.com/api/projects/firstProject",
|
| 37 |
-
"model": "mistral-small-2503",
|
| 38 |
"key_env": "AZUREMIST_API_KEY",
|
| 39 |
"response_format": {"type": "json_object"},
|
| 40 |
-
|
| 41 |
-
"HTTP-Referer": "https://huggingface.co",
|
| 42 |
-
"X-Title": "Invoice Extractor",
|
| 43 |
-
},
|
| 44 |
},
|
| 45 |
}
|
| 46 |
|
|
@@ -54,17 +52,23 @@ def get_api_key(model_choice):
|
|
| 54 |
def query_llm(model_choice, prompt):
|
| 55 |
cfg = MODELS[model_choice]
|
| 56 |
headers = {
|
| 57 |
-
"Authorization": f"Bearer {get_api_key(model_choice)}",
|
| 58 |
"Content-Type": "application/json",
|
| 59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
if cfg.get("extra_headers"):
|
| 61 |
headers.update(cfg["extra_headers"])
|
| 62 |
payload = {
|
| 63 |
-
"model": cfg["model"],
|
| 64 |
"messages": [{"role": "user", "content": prompt}],
|
| 65 |
"temperature": 0.1,
|
| 66 |
"max_tokens": 2000,
|
| 67 |
}
|
|
|
|
|
|
|
|
|
|
| 68 |
if cfg.get("response_format"):
|
| 69 |
payload["response_format"] = cfg["response_format"]
|
| 70 |
try:
|
|
@@ -206,4 +210,4 @@ with tab2:
|
|
| 206 |
if "last_api" in st.session_state:
|
| 207 |
with st.expander("Debug"):
|
| 208 |
st.code(st.session_state.last_api)
|
| 209 |
-
st.code(st.session_state.last_raw)
|
|
|
|
| 33 |
},
|
| 34 |
},
|
| 35 |
"Mistral Small": {
|
| 36 |
+
# Update these two fields with your Azure values:
|
| 37 |
"api_url": "https://ezofisai.services.ai.azure.com/api/projects/firstProject",
|
| 38 |
+
"model": "mistral-small-2503", # this is not used by Azure, just for completeness
|
| 39 |
"key_env": "AZUREMIST_API_KEY",
|
| 40 |
"response_format": {"type": "json_object"},
|
| 41 |
+
# No extra_headers needed for Azure
|
|
|
|
|
|
|
|
|
|
| 42 |
},
|
| 43 |
}
|
| 44 |
|
|
|
|
| 52 |
def query_llm(model_choice, prompt):
|
| 53 |
cfg = MODELS[model_choice]
|
| 54 |
headers = {
|
|
|
|
| 55 |
"Content-Type": "application/json",
|
| 56 |
}
|
| 57 |
+
# Azure OpenAI (Mistral Small) needs api-key header instead of Authorization
|
| 58 |
+
if model_choice == "mistral-small-2503":
|
| 59 |
+
headers["api-key"] = get_api_key(model_choice)
|
| 60 |
+
else:
|
| 61 |
+
headers["Authorization"] = f"Bearer {get_api_key(model_choice)}"
|
| 62 |
if cfg.get("extra_headers"):
|
| 63 |
headers.update(cfg["extra_headers"])
|
| 64 |
payload = {
|
|
|
|
| 65 |
"messages": [{"role": "user", "content": prompt}],
|
| 66 |
"temperature": 0.1,
|
| 67 |
"max_tokens": 2000,
|
| 68 |
}
|
| 69 |
+
# Only non-Azure APIs need "model" in payload
|
| 70 |
+
if model_choice != "mistral-small-2503":
|
| 71 |
+
payload["model"] = cfg["model"]
|
| 72 |
if cfg.get("response_format"):
|
| 73 |
payload["response_format"] = cfg["response_format"]
|
| 74 |
try:
|
|
|
|
| 210 |
if "last_api" in st.session_state:
|
| 211 |
with st.expander("Debug"):
|
| 212 |
st.code(st.session_state.last_api)
|
| 213 |
+
st.code(st.session_state.last_raw)
|