Skip to content

Commit

Permalink
fix: call golang api failing using multipartencoder
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvis8x7b committed Jul 10, 2024
1 parent d59ec0c commit 0a8d504
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions commons/human_feedback/dojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import httpx
from loguru import logger
from requests_toolbelt import MultipartEncoder

import template
from commons.utils import loaddotenv
Expand Down Expand Up @@ -92,29 +91,30 @@ async def create_task(
else:
logger.error(f"Unrecognized criteria type: {type(criteria_type)}")

body = {
"title": "LLM Code Generation Task",
"body": ranking_request.prompt,
json_body = {
"title": ("", "LLM Code Generation Task"),
"body": ("", ranking_request.prompt),
"expireAt": (
datetime.datetime.utcnow()
+ datetime.timedelta(seconds=template.TASK_DEADLINE)
)
.replace(microsecond=0, tzinfo=datetime.timezone.utc)
.isoformat()
.replace("+00:00", "Z"),
"taskData": json.dumps([taskData]),
"maxResults": "1",
"",
(
datetime.datetime.utcnow()
+ datetime.timedelta(seconds=template.TASK_DEADLINE)
)
.replace(microsecond=0, tzinfo=datetime.timezone.utc)
.isoformat()
.replace("+00:00", "Z"),
),
"taskData": ("", json.dumps([taskData])),
"maxResults": ("", "1"),
}

mp = MultipartEncoder(fields=body)
DOJO_API_KEY = loaddotenv("DOJO_API_KEY")
print("DOJO API KEY: ", DOJO_API_KEY)

response = await cls._http_client.post(
path,
data=mp.to_string(),
files=json_body,
headers={
"x-api-key": DOJO_API_KEY,
"content-type": mp.content_type,
},
timeout=15.0,
)
Expand All @@ -132,6 +132,7 @@ async def create_task(
print("Tried to export create task request as curl, but failed.")
print(f"Exception: {e}")

task_ids = []
if response.status_code == 200:
task_ids = response.json()["body"]
logger.success(f"Successfully created task with\ntask ids:{task_ids}")
Expand Down

0 comments on commit 0a8d504

Please sign in to comment.