generated from songquanpeng/gin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ollama的嵌入模型调用错误 #1305
Labels
bug
Something isn't working
Comments
目前测试只支持测试聊天模型 |
这个之后优化吧,issue 先留着 |
同样需要使用ollama的embedding模型nomic。因为使用的mac,使用m3e时只能使用cpu,太慢了,希望能用ollama的nomic模型来作为embedding. |
这个接口不应该是一样的么? |
ollama 文档写了后续会把 embedding 也 OpenAI 化,OneAPI 完全没必要重复造轮子。 如果实在急着用,自己手写个 flask。参考个人写过的一段代码,如果懒得改,连同 Ollama 当前的调用方式丢给 GPT 转一下: from flask import Flask, request, jsonify
from sentence_transformers import SentenceTransformer
app = Flask(__name__)
# 加载模型
model_path = '/sshfs/pretrains/moka-ai/m3e-large'
model = SentenceTransformer(model_path)
@app.route('/v1/embeddings', methods=['POST'])
def get_embeddings():
data = request.get_json()
if not all((data, 'input' in data, 'model' in data)):
return jsonify({"error": "Missing required fields in request body"}), 400
input_text = data['input']
# 将单个输入转换为列表
if isinstance(input_text, str):
input_text = [input_text]
# 调用模型获取 embeddings
embeddings = model.encode(input_text)
# 构造响应
embeddings_response = []
for index, embedding in enumerate(embeddings):
embedding_dict = {
"object": "embedding",
"embedding": embedding.tolist(), # 将 numpy 数组转换为列表
"index": index
}
embeddings_response.append(embedding_dict)
# 可选: Token 计数
response = {
"object": "list",
"data": embeddings_response,
"model": data['model'],
"usage": {
"prompt_tokens": sum(len(text.split()) for text in input_text),
"total_tokens": sum(len(text.split()) for text in input_text)
}
}
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True, port=5000, host='0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
例行检查
问题描述
docker部署的。设置如下图,当填入聊天模式的时候,测试没有问题。但填入嵌入模式的时候,有400错误。是ollama那边设置的问题吗?
复现步骤
预期结果
相关截图
#1221
#1159
The text was updated successfully, but these errors were encountered: