-
Notifications
You must be signed in to change notification settings - Fork 0
/
mistral_gcp.py
54 lines (44 loc) · 1.6 KB
/
mistral_gcp.py
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
import requests
"""
MODEL="mistral-large"
MODEL_VERSION="2407"
url="https://europe-west4-aiplatform.googleapis.com/v1/projects/mistral-alan-hack24par-836/locations/europe-west4/publishers/mistralai/models/$MODEL@$MODEL_VERSION:rawPredict"
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
$url \
--data '{
"model": "'"$MODEL"'",
"temperature": 0,
"messages": [
{"role": "user", "content": "What is the best French cheese?"}
]
}'
"""
url = "https://europe-west4-aiplatform.googleapis.com/v1/projects/mistral-alan-hack24par-836/locations/europe-west4/publishers/mistralai/models/mistral-large@2407:rawPredict"
token = "ya29.a0AcM612w4VpuTITeG2vmEwMKav0p4hSZ36eo4X_3iWjOnyMXln646rP7Lgk1KQ0U11x8UhfQRcz-UPz37C6rGNDnpYrf7bosw9uxcjeGkXS-0qsYc8o0xieaU6oFdJyndRPTKQk1DT7GMFIqJhHSBBnRgWad5UauiuyJd4-d0SHAMlwaCgYKAX0SARMSFQHGX2MiPmhGT-fsX84xk9NEoOqvZQ0181"
def process(prompt):
try:
response = requests.post(
url,
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
},
json={
"model": "mistral-large",
"temperature": 0,
"messages": [
{"role": "user", "content": prompt}
]
}
)
data = response.json()
print(response.status_code)
result = data["choices"][0]["message"]["content"]
print(result)
return result
except Exception as e:
print(e)
return "Error"