Skip to content

Commit

Permalink
[HOTFIX] Change postAPI embedding model _parse_resonse to OpenAI form…
Browse files Browse the repository at this point in the history
…at (#479)
  • Loading branch information
ZiTao-Li authored Nov 6, 2024
1 parent 0334b8b commit e4321a0
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/agentscope/models/post_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,37 +273,37 @@ def _parse_response(self, response: dict) -> ModelResponse:
Args:
response (`dict`):
The response obtained from the API. This parsing assume the
structure of the response is as following:
structure of the response is the same as OpenAI's as following:
{
"code": 200,
"data": {
...
"response": {
"data": [
{
"embedding": [
0.001,
...
],
...
}
],
"model": "xxxx",
...
},
},
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
.... (1536 floats total for ada-002)
-0.0028842222,
],
"index": 0
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
"""
if "data" not in response["data"]["response"]:
if "error" in response["data"]["response"]:
error_msg = response["data"]["response"]["error"]["message"]
else:
error_msg = response["data"]["response"]
if (
"data" not in response
or len(response["data"]) < 1
or "embedding" not in response["data"][0]
):
error_msg = json.dumps(response, ensure_ascii=False, indent=2)
logger.error(f"Error in embedding API call:\n{error_msg}")
raise ValueError(f"Error in embedding API call:\n{error_msg}")
embeddings = [
data["embedding"] for data in response["data"]["response"]["data"]
]
embeddings = [data["embedding"] for data in response["data"]]
return ModelResponse(
embedding=embeddings,
raw=response,
Expand Down

0 comments on commit e4321a0

Please sign in to comment.