Skip to content

Commit

Permalink
use requests.post (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzhe-log10 authored Dec 2, 2024
1 parent d9c513d commit 202966f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/log10/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def log_failure_event(self, kwargs, response_obj, start_time, end_time):
run = self.runs.get(litellm_call_id, None)
self.api_request(
f"/api/completions/{run['completion_id']}",
"POST",
update_log_row,
)

Expand Down
9 changes: 3 additions & 6 deletions src/log10/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def chat(self, messages: List[Message], hparams: dict = None) -> ChatCompletion:
def chat_request(self, messages: List[Message], hparams: dict = None) -> dict:
raise Exception("Not implemented")

def api_request(self, rel_url: str, method: str, request: dict):
def api_request(self, rel_url: str, request: dict):
def is_safe_url(url: str) -> bool:
parsed = urlparse(url)
base_domain = urlparse(self.log10_config.url).netloc
Expand All @@ -173,8 +173,7 @@ def is_safe_url(url: str) -> bool:
if not is_safe_url(full_url):
raise ValueError("Invalid URL: " + full_url)

return requests.request(
method,
return requests.post(
full_url,
headers={
"x-log10-token": self.log10_config.token,
Expand All @@ -188,7 +187,7 @@ def log_start(self, request, kind: Kind, tags: Optional[List[str]] = None):
if not self.log10_config:
return None

res = self.api_request("/api/completions", "POST", {"organization_id": self.log10_config.org_id})
res = self.api_request("/api/completions", {"organization_id": self.log10_config.org_id})
self.last_completion_response = res.json()
completion_id = res.json()["completionID"]

Expand All @@ -200,7 +199,6 @@ def log_start(self, request, kind: Kind, tags: Optional[List[str]] = None):

res = self.api_request(
f"/api/completions/{completion_id}",
"POST",
{
"kind": kind == Kind.text and "completion" or "chat",
"organization_id": self.log10_config.org_id,
Expand Down Expand Up @@ -238,7 +236,6 @@ def log_end(self, completion_id: str, response: dict, duration: int):

self.api_request(
f"/api/completions/{completion_id}",
"POST",
{
"organization_id": self.log10_config.org_id,
"response": json.dumps(response),
Expand Down

0 comments on commit 202966f

Please sign in to comment.