vl_embedding_test.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import sys
  2. import os
  3. from PIL import Image
  4. # 添加项目根目录到Python路径
  5. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  6. from model.multimodal_embedding import Embedding
  7. from conf.config import ModelConfig
  8. def main():
  9. """测试主函数"""
  10. print("开始测试VL嵌入...")
  11. print("=" * 50)
  12. # 初始化OpenAIEmbedding模型
  13. embedding_model = Embedding("qwen2.5-vl-embedding", "sk-bc0f1026a41c4c92beb014be8973e4e2")
  14. # 图片
  15. image_path = r"D:\project\work\ragflow_plugs\book\output\temp\美美.png"
  16. # 检查图片文件是否存在
  17. if not os.path.exists(image_path):
  18. print(f"图片文件不存在: {image_path}")
  19. return
  20. try:
  21. # 打开图像文件
  22. image = Image.open(image_path)
  23. text = "美美"
  24. res = embedding_model.get_multimodal_embedding(text, image)
  25. print(f"图片embedding值: {res}")
  26. except Exception as e:
  27. print(f"测试失败: {str(e)}")
  28. print("=" * 50)
  29. if __name__ == "__main__":
  30. main()