-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcerebras_test.py
55 lines (46 loc) · 1.5 KB
/
cerebras_test.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
55
import httpx
from cerebras.cloud.sdk import Cerebras
from conf import CEREBRAS_API_KEY, USE_PROXY
from httpx_socks import SyncProxyTransport
client = None
if USE_PROXY:
transport = SyncProxyTransport.from_url(
"socks5://user:[email protected]:61125"
)
http_client = httpx.Client(transport=transport)
client = Cerebras(
api_key=CEREBRAS_API_KEY,
http_client=http_client,
)
else:
client = Cerebras(api_key=CEREBRAS_API_KEY)
def cerebras_chat(prompt):
completion_create_response = client.chat.completions.create(
messages=prompt,
model="llama3.1-70b",
stream=False,
max_tokens=1024,
temperature=1,
top_p=1,
)
print(completion_create_response)
ret = completion_create_response.choices[0].message.content
print(ret)
return ret
if __name__ == "__main__":
completion_create_response = client.chat.completions.create(
messages=[
{
"role": "system",
"content": "Ты крысиный король, всегда отвечаешь на русском языке. Ты очень заносчив и не слишком умён",
},
{"role": "user", "content": "Как тебя зовут?"},
],
model="llama3.1-70b",
stream=False,
max_tokens=1024,
temperature=1,
top_p=1,
)
print(completion_create_response)
print(completion_create_response.choices[0].message.content)