| 13 | |
| 14 | |
| 15 | def encode(client, inputs, is_query=False): |
| 16 | if is_query: |
| 17 | instruction = "Instruction: Given a search query, retrieve passages that answer the question \nQuery:" |
| 18 | else: |
| 19 | instruction = "" |
| 20 | |
| 21 | params = { |
| 22 | "Model": model_name, |
| 23 | "Inputs": inputs, |
| 24 | "Instruction": instruction |
| 25 | } |
| 26 | |
| 27 | req = models.GetEmbeddingRequest() |
| 28 | req.from_json_string(json.dumps(params)) |
| 29 | |
| 30 | resp = client.GetEmbedding(req) |
| 31 | resp = json.loads(resp.to_json_string()) |
| 32 | outputs =[item["Embedding"] for item in resp["Data"]] |
| 33 | return outputs |
| 34 | |
| 35 | secret_id = os.getenv("TENCENTCLOUD_SECRET_ID") |
| 36 | secret_key = os.getenv("TENCENTCLOUD_SECRET_KEY") |