Spaces:
Paused
Paused
Commit
·
e8f51cf
1
Parent(s):
26db70a
fix: hf access token and post request
Browse files- .env.example +3 -0
- main.py +13 -1
- utils/config.py +57 -1
.env.example
CHANGED
|
@@ -2,3 +2,6 @@
|
|
| 2 |
# Copy this file to .env and set your values
|
| 3 |
DS_API_BASE_URL=https://learning.test.orbitant.dev/api
|
| 4 |
DS_API_ENDPOINT=/mcp_bug_localization
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
# Copy this file to .env and set your values
|
| 3 |
DS_API_BASE_URL=https://learning.test.orbitant.dev/api
|
| 4 |
DS_API_ENDPOINT=/mcp_bug_localization
|
| 5 |
+
|
| 6 |
+
# Replace with your Hugging Face access token
|
| 7 |
+
HF_ACCESS_TOKEN=
|
main.py
CHANGED
|
@@ -57,11 +57,23 @@ async def full_bug_localization(request: BugLocalizationRequest, ctx: Context) -
|
|
| 57 |
client = ds_ctx.client
|
| 58 |
|
| 59 |
api_url = API_CONFIG["api_base_url"] + API_CONFIG["api_endpoint"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
try:
|
| 61 |
logger.info(f"Sending bug localization request to {api_url} with data: {request.model_dump()}")
|
| 62 |
response = await client.post(
|
| 63 |
api_url,
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
)
|
| 66 |
response.raise_for_status()
|
| 67 |
logger.info(f"Received response: {response.text}")
|
|
|
|
| 57 |
client = ds_ctx.client
|
| 58 |
|
| 59 |
api_url = API_CONFIG["api_base_url"] + API_CONFIG["api_endpoint"]
|
| 60 |
+
hf_token = API_CONFIG.get("hf_access_token", None)
|
| 61 |
+
|
| 62 |
+
headers = {
|
| 63 |
+
"Authorization": f"Bearer {hf_token}",
|
| 64 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
try:
|
| 68 |
logger.info(f"Sending bug localization request to {api_url} with data: {request.model_dump()}")
|
| 69 |
response = await client.post(
|
| 70 |
api_url,
|
| 71 |
+
params={
|
| 72 |
+
"issue_key": request.issue_key,
|
| 73 |
+
"summary": request.summary,
|
| 74 |
+
"description": request.description
|
| 75 |
+
},
|
| 76 |
+
headers=headers
|
| 77 |
)
|
| 78 |
response.raise_for_status()
|
| 79 |
logger.info(f"Received response: {response.text}")
|
utils/config.py
CHANGED
|
@@ -7,5 +7,61 @@ load_dotenv()
|
|
| 7 |
API_CONFIG = {
|
| 8 |
"api_base_url": os.getenv("DS_API_BASE_URL", "https://dnext-ds-api.hf.space"),
|
| 9 |
"api_endpoint": os.getenv("DS_API_ENDPOINT", "/mcp_bug_localization"),
|
|
|
|
| 10 |
"timeout": 30.0,
|
| 11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
API_CONFIG = {
|
| 8 |
"api_base_url": os.getenv("DS_API_BASE_URL", "https://dnext-ds-api.hf.space"),
|
| 9 |
"api_endpoint": os.getenv("DS_API_ENDPOINT", "/mcp_bug_localization"),
|
| 10 |
+
"hf_access_token": os.getenv("HF_ACCESS_TOKEN", None),
|
| 11 |
"timeout": 30.0,
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# import os
|
| 18 |
+
# import asyncio
|
| 19 |
+
# import httpx
|
| 20 |
+
#
|
| 21 |
+
# HF_TOKEN = os.getenv("HF_ACCESS_TOKEN")
|
| 22 |
+
#
|
| 23 |
+
# async def test_post():
|
| 24 |
+
# api_url = API_CONFIG["api_base_url"] + API_CONFIG["api_endpoint"]
|
| 25 |
+
# params = {
|
| 26 |
+
# "issue_key": "BUG-123",
|
| 27 |
+
# "summary": "Sample bug summary",
|
| 28 |
+
# "description": "Detailed bug description",
|
| 29 |
+
# "project_id": "test_project",
|
| 30 |
+
# }
|
| 31 |
+
# headers = {
|
| 32 |
+
# "Authorization": f"Bearer {HF_TOKEN}",
|
| 33 |
+
# }
|
| 34 |
+
# async with httpx.AsyncClient(timeout=API_CONFIG["timeout"]) as client:
|
| 35 |
+
# response = await client.post(api_url, params=params, headers=headers)
|
| 36 |
+
# print("Status code:", response.status_code)
|
| 37 |
+
# print("Response:", response.text)
|
| 38 |
+
#
|
| 39 |
+
# if __name__ == "__main__":
|
| 40 |
+
# asyncio.run(test_post())
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# import os
|
| 44 |
+
# import asyncio
|
| 45 |
+
# import httpx
|
| 46 |
+
#
|
| 47 |
+
# HF_TOKEN = os.getenv("HF_ACCESS_TOKEN")
|
| 48 |
+
#
|
| 49 |
+
# async def test_post_with_data():
|
| 50 |
+
# api_url = API_CONFIG["api_base_url"] + API_CONFIG["api_endpoint"]
|
| 51 |
+
# data = {
|
| 52 |
+
# "issue_key": "BUG-123",
|
| 53 |
+
# "summary": "Sample bug summary",
|
| 54 |
+
# "description": "Detailed bug description",
|
| 55 |
+
# "project_id": "test_project",
|
| 56 |
+
# }
|
| 57 |
+
# headers = {
|
| 58 |
+
# "Authorization": f"Bearer {HF_TOKEN}",
|
| 59 |
+
# "Content-Type": "application/x-www-form-urlencoded"
|
| 60 |
+
# }
|
| 61 |
+
# async with httpx.AsyncClient(timeout=API_CONFIG["timeout"]) as client:
|
| 62 |
+
# response = await client.post(api_url, data=data, headers=headers)
|
| 63 |
+
# print("Status code:", response.status_code)
|
| 64 |
+
# print("Response:", response.text)
|
| 65 |
+
#
|
| 66 |
+
# if __name__ == "__main__":
|
| 67 |
+
# asyncio.run(test_post_with_data())
|