GPTfree api
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,21 @@
|
|
|
|
1 |
import os
|
2 |
-
import tempfile
|
3 |
-
from vllm import LLM
|
4 |
-
from vllm.sampling_params import SamplingParams
|
5 |
-
from datetime import datetime, timedelta
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
yesterday = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d')
|
16 |
-
return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
SYSTEM_PROMPT = load_system_prompt(system_prompt_path)
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
# メッセージリストの作成
|
29 |
-
messages = [
|
30 |
-
{"role": "system", "content": SYSTEM_PROMPT},
|
31 |
-
{
|
32 |
-
"role": "user",
|
33 |
-
"content": "Which of the depicted countries has the best food?",
|
34 |
-
},
|
35 |
-
]
|
36 |
-
|
37 |
-
sampling_params = SamplingParams(max_tokens=512)
|
38 |
-
|
39 |
-
# モデルロードと実行
|
40 |
-
llm = LLM(model=model_name, trust_remote_code=True, tensor_parallel_size=1, device="cpu")
|
41 |
-
outputs = llm.chat(messages, sampling_params=sampling_params)
|
42 |
-
|
43 |
-
# 出力を表示
|
44 |
-
print(outputs[0].outputs[0].text)
|
|
|
1 |
+
import requests
|
2 |
import os
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Hugging Face APIエンドポイントと認証トークン
|
5 |
+
api_url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
|
6 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
7 |
|
8 |
+
# クエリのメッセージ
|
9 |
+
payload = {
|
10 |
+
"inputs": "Which of the depicted countries has the best food?",
|
11 |
+
"parameters": {"max_new_tokens": 512}
|
12 |
+
}
|
|
|
|
|
13 |
|
14 |
+
# APIリクエスト
|
15 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
|
|
16 |
|
17 |
+
# 結果表示
|
18 |
+
if response.status_code == 200:
|
19 |
+
print("Response:", response.json())
|
20 |
+
else:
|
21 |
+
print(f"Error {response.status_code}: {response.text}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|