-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_chat.py
More file actions
56 lines (48 loc) · 1.89 KB
/
Copy pathmodel_chat.py
File metadata and controls
56 lines (48 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
from openai import OpenAI
import requests
from tqdm import tqdm
import os
MLLM_client = OpenAI(
base_url="http://localhost:7777/v1",
api_key="00000000",
)
LLM_client = OpenAI(
base_url="http://localhost:8888/v1",
api_key="00000000",
)
class MLLM:
def __init__(self, client, model_name="../models/Qwen2.5-VL-72B-Instruct"):
self.model_name = model_name
self.client = client
def chat(self, image_path, text):
completion = self.client.chat.completions.create(
model=self.model_name,
messages=[
{ "role": "user",
"content": [{"type": "image_url", "image_url": {"url": "file://"+image_path}},
{"type": "text", "text":text
}]
}
]
)
return completion.choices[0].message.content.strip()
class LLM:
def __init__(self, client, model_name="../models/Qwen3-32B"):
self.client = client
self.model_name = model_name
def chat(self, text):
completion = self.client.chat.completions.create(
model=self.model_name,
messages=[
{"role": "user", "content": text}
],
extra_body={
"chat_template_kwargs": {"enable_thinking": False}, # 关闭Qwen3的思考模式
},
)
return completion.choices[0].message.content.strip()
# 发送http请求时要带上Bearer认证
# headers = {"Authorization": "Bearer 00000000"}
# response = requests.get(url="http://localhost:7777/v1/models", headers=headers)
# print(response.json())