Embeddings文本向量化API 异常返回 异常返回时: http code 返回非200。 http body 中返回 error 结构,error结构中包含code、type、message、param等信息,具体可见OpenAPI接口文档中的error结构描述及错误码部分介绍。 错误结果示例 python { "error" : { "code" : "500001", "type" : "INVOKEMODELERROR", "message" : "服务接口异常,请联系管理员" } } 请求示例代码 html 假设慧聚平台用户组AppKey884c8fc4054548a7b1ca1123592f5b7,模型ID96dcaaaaaaaaaaaa5ff55ea377831a,以此为例进行说明。 curl方式请求 python curl request POST url header 'Accept: /' header 'AcceptEncoding: gzip, deflate, br' header 'Authorization: Bearer 884c8fc4054548a7b1ca1123592f5b7' header 'ContentType: application/json' data '{ "model": "4b38a36cabe247c8a996206984c9e2a61", "input" : "A cute baby sea otter" }' python方式请求 python import json import requests URL " headers { "Authorization": "Bearer 884c8fc4054548a7b1ca1123592f5b7", "ContentType": "application/json" } data { "model": "4b38a36cabe247c8a996206984c9e2a61", "input" : "A cute baby sea otter" } try: response requests.post(URL, headersheaders, jsondata) if response.statuscode ! 200: print(response.json()) else: embeddings response.json()["data"][0]["embeddings"] except Exception as e: print(f"Exception: {e}") openai 客户端示例代码 python import openai from openai import OpenAI client OpenAI(baseurl" apikey"884c8fc4054548a7b1ca1123592f5b7") try: response client.embeddings( model"4b38a36cabe247c8a996206984c9e2a61", input"A cute baby sea otter", ) print(f"{response}") except openai.APIStatusError as e: print(f"APIStatusError: {e.statuscode}, {e.message}, {e.body}") except openai.APIError as e: print(f"APIError: {e.body}") except Exception as e: print(f"Exception: {e}")