44import json
55import threading
66
7+ QUESTION_TEMPLATES = {
8+ "llava" : (
9+ "<|im_start|>system\n "
10+ "A chat between a curious human and an artificial intelligence assistant."
11+ "The assistant gives helpful, detailed, and polite answers to the human's questions."
12+ "<|im_end|><|im_start|>user\n "
13+ "<image>\n "
14+ "Please describe it.\n "
15+ "<|im_end|><|im_start|>assistant\n "
16+ ),
17+ "internvl-internlm2" : (
18+ "<|im_start|>system\n "
19+ "You are an AI assistant whose name is InternLM(书生·浦语).\n "
20+ "<|im_end|><|im_start|>user\n "
21+ "<image>\n "
22+ "Please describe it.\n "
23+ "<|im_end|><|im_start|>assistant\n "
24+ ),
25+ "internvl-phi3" : (
26+ "<|im_start|>system\n "
27+ "You are an AI assistant whose name is Phi-3.\n "
28+ "<|im_end|><|im_start|>user\n "
29+ "<image>\n "
30+ "Please describe it.\n "
31+ "<|im_end|><|im_start|>assistant\n "
32+ ),
33+ "internvl2-internlm2" : (
34+ "<|im_start|>system\n "
35+ "你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。\n "
36+ "<|im_end|><|im_start|>user\n "
37+ "<image>\n "
38+ "Please describe it.\n "
39+ "<|im_end|><|im_start|>assistant\n "
40+ ),
41+ "internvl2-phi3" : (
42+ "<|im_start|>system\n "
43+ "你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。\n "
44+ "<|im_end|><|im_start|>user\n "
45+ "<image>\n "
46+ "Please describe it.\n "
47+ "<|im_end|><|im_start|>assistant\n "
48+ ),
49+ "internvl2_5" : (
50+ "<|im_start|>system\n "
51+ "你是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。\n "
52+ "<|im_end|><|im_start|>user\n "
53+ "<image>\n "
54+ "Please describe it.\n "
55+ "<|im_end|><|im_start|>assistant\n "
56+ ),
57+ "qwen_vl" : (
58+ "<|im_start|>system\n "
59+ "You are a helpful assistant.\n "
60+ "<|im_end|>\n "
61+ "<|im_start|>user\n "
62+ "<img></img>Describe this image.\n "
63+ "<|im_end|>\n "
64+ "<|im_start|>assistant\n "
65+ ),
66+ "qwen2_vl" : (
67+ "<|im_start|>system\n "
68+ "You are a helpful assistant.\n "
69+ "<|im_end|>\n "
70+ "<|im_start|>user\n "
71+ "<|vision_start|><|image_pad|><|vision_end|>Describe this image.\n "
72+ "<|im_end|>\n "
73+ "<|im_start|>assistant\n "
74+ ),
75+ "qwen2_5_vl" : (
76+ "<|im_start|>system\n "
77+ "You are a helpful assistant.\n "
78+ "<|im_end|>\n "
79+ "<|im_start|>user\n "
80+ "<|vision_start|><|image_pad|><|vision_end|>Describe this image.\n "
81+ "<|im_end|>\n "
82+ "<|im_start|>assistant\n "
83+ ),
84+ }
85+
786
887class RequestThread (threading .Thread ):
988 def __init__ (self , url , headers , data ):
@@ -26,9 +105,13 @@ def image_to_base64(image):
26105 return encoded_string
27106
28107
108+ # Please replace the question template as QUESTION_TEMPLATES:
29109question = "Describe this picture to me."
30- question = f"user\n You are an AI assistant whose name is goodAI. \
31- <start_of_image>{ question } \n "
110+ question = (
111+ f"<|im_start|>system\n "
112+ f"You are an AI assistant whose name is InternLM(书生·浦语).<|im_end|>"
113+ f"<|im_start|>user\n <image>\n { question } <|im_end|><|im_start|>assistant\n "
114+ )
32115
33116url = "http://localhost:9999/generate"
34117headers = {"Content-Type" : "application/json" }
0 commit comments