feat: rag
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# 使用豆包来向量化文本
|
||||
|
||||
import requests
|
||||
|
||||
VOLC_EMBEDDINGS_API_URL = "https://ark.cn-beijing.volces.com/api/v3/embeddings"
|
||||
VOLC_API_KEY = "79b39c58-56db-4d8a-a8f8-84b95fca08db"
|
||||
|
||||
|
||||
def get_doubao_embedding(doc):
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {VOLC_API_KEY}",
|
||||
}
|
||||
params = {"model": "doubao-embedding-text-240715", "input": doc}
|
||||
response = requests.post(VOLC_EMBEDDINGS_API_URL, json=params, headers=headers)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
embedding = data["data"][0]["embedding"]
|
||||
return embedding
|
||||
else:
|
||||
raise Exception(f"Embedding API error:{response.text}")
|
||||
|
||||
|
||||
embedding = get_doubao_embedding("这是一段文档")
|
||||
print(embedding)
|
||||
Reference in New Issue
Block a user