Skip to content

Commit

Permalink
update to openai > 1 (#529)
Browse files Browse the repository at this point in the history
* update to openai > 1

* changelog
  • Loading branch information
willydouhard authored Nov 8, 2023
1 parent 31efb53 commit 371b374
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 280 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

Nothing unreleased!

## [0.7.600rc0] - 2023-11-08

### Changed

- Replaced aiohttp with httpx
- Prompt Playground has been updated to work with the new openai release (v1). Including tools.

## [0.7.500] - 2023-11-07

### Added
Expand Down
48 changes: 22 additions & 26 deletions backend/chainlit/client/cloud.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from typing import Any, Dict, List, Optional, Union

import aiohttp
import httpx
from chainlit.logger import logger

from .base import (
Expand Down Expand Up @@ -459,41 +459,37 @@ async def upload_element(
if conversation_id:
body["conversationId"] = conversation_id

path = f"/api/upload/file"
path = "/api/upload/file"

async with aiohttp.ClientSession() as session:
async with session.post(
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self.chainlit_server}{path}",
json=body,
headers=self.headers,
) as r:
if not r.ok:
reason = await r.text()
logger.error(f"Failed to sign upload url: {reason}")
return {"object_key": None, "url": None}
json_res = await r.json()
)
if response.status_code != 200:
reason = response.text
logger.error(f"Failed to sign upload url: {reason}")
return {"object_key": None, "url": None}
json_res = response.json()

upload_details = json_res["post"]
object_key = upload_details["fields"]["key"]
signed_url = json_res["signedUrl"]

form_data = aiohttp.FormData()
# Prepare form data
form_data = upload_details["fields"].copy()
form_data["file"] = (id, content, "multipart/form-data")

# Add fields to the form_data
for field_name, field_value in upload_details["fields"].items():
form_data.add_field(field_name, field_value)

# Add file to the form_data
form_data.add_field("file", content, content_type="multipart/form-data")
async with aiohttp.ClientSession() as session:
async with session.post(
async with httpx.AsyncClient() as client:
upload_response = await client.post(
upload_details["url"],
data=form_data,
) as upload_response:
if not upload_response.ok:
reason = await upload_response.text()
logger.error(f"Failed to upload file: {reason}")
return {"object_key": None, "url": None}

files=form_data,
)
try:
upload_response.raise_for_status()
url = f'{upload_details["url"]}/{object_key}'
return {"object_key": object_key, "url": signed_url}
except Exception as e:
logger.error(f"Failed to upload file: {str(e)}")
return {"object_key": None, "url": None}
17 changes: 7 additions & 10 deletions backend/chainlit/langflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from typing import Dict, Optional, Union

import aiohttp
import httpx
from chainlit.telemetry import trace_event


Expand All @@ -16,15 +16,12 @@ async def load_flow(schema: Union[Dict, str], tweaks: Optional[Dict] = None):

trace_event("load_langflow")

if type(schema) == str:
async with aiohttp.ClientSession() as session:
async with session.get(
schema,
) as r:
if not r.ok:
reason = await r.text()
raise ValueError(f"Error: {reason}")
schema = await r.json()
if isinstance(schema, str):
async with httpx.AsyncClient() as client:
response = await client.get(schema)
if response.status_code != 200:
raise ValueError(f"Error: {response.text}")
schema = response.json()

flow = load_flow_from_json(flow=schema, tweaks=tweaks)

Expand Down
Loading

0 comments on commit 371b374

Please sign in to comment.