Skip to content

Commit

Permalink
CD-153 - ran format.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
rmontoya12 committed Oct 25, 2024
1 parent 2fa8ffd commit 3060aad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fastchat/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def to_jab_api_messages(self):
if msg is not None:
ret.append({"role": "assistant", "content": msg})
return ret

def save_new_images(self, has_csam_images=False, use_remote_storage=False):
import hashlib
from fastchat.constants import LOGDIR
Expand Down
1 change: 1 addition & 0 deletions fastchat/model/model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2509,6 +2509,7 @@ def match(self, model_path: str):
def get_default_conv_template(self, model_path: str) -> Conversation:
return get_conv_template("api_based_default")


# Note: the registration order matters.
# The one registered earlier has a higher matching priority.
register_model_adapter(PeftModelAdapter)
Expand Down
15 changes: 9 additions & 6 deletions fastchat/serve/api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def get_api_provider_stream_iter(
messages=messages,
api_base=model_api_dict["api_base"],
api_key=model_api_dict["api_key"],
)
)
else:
raise NotImplementedError()

Expand Down Expand Up @@ -1270,20 +1270,21 @@ def metagen_api_stream_iter(
"error_code": 1,
}


def jab_api_stream_iter(
model_name,
messages,
api_base,
api_key,
api_key,
):
import requests

headers = {'Content-Type': 'application/json', 'x-api-key': api_key}
headers = {"Content-Type": "application/json", "x-api-key": api_key}

text_messages = []
for message in messages:
text_messages.append(message)

payload = {
"model": model_name,
"messages": text_messages,
Expand All @@ -1295,7 +1296,9 @@ def jab_api_stream_iter(
response = requests.post(api_base, json=payload, headers=headers)

if response.status_code != 200:
logger.error(f"Unexpected response ({response.status_code}): {response.text}")
logger.error(
f"Unexpected response ({response.status_code}): {response.text}"
)
yield {
"text": f"**API REQUEST FAILED** Reason: {response.status_code}.",
"error_code": 1,
Expand All @@ -1317,4 +1320,4 @@ def jab_api_stream_iter(
yield {
"text": f"**API REQUEST ERROR** Reason: Unknown.",
"error_code": 1,
}
}

0 comments on commit 3060aad

Please sign in to comment.