-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
40 lines (30 loc) · 1.29 KB
/
example.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
import asyncio
import xai_sdk
# import os
# os.environ['XAI_API_KEY'] = 'YOUR_KEY_GOES_HERE'
async def main():
client = xai_sdk.Client()
sampler = client.sampler
FIRST_PREAMBLE = """\
This is a conversation between a human user and a highly intelligent AI. The AI's name is Grok and it makes every effort to truthfully answer a user's questions. It always responds politely but is not shy to use its vast knowledge in order to solve even the most difficult problems. The conversation begins.
Human: I want you to find the three main qualities or focus of these set of tweets.
Please format your answer as a valid JSON. For eg. if your qualities are (price, comfort, peaceful) your output should be.
{
quality1: "price",
quality2: "comfort",
quality3: "peaceful"
}<|separator|>
Assistant: Understood! Please provide the list of tweets as a list of strings."""
text = input("Write a message ")
prompt = FIRST_PREAMBLE + f"<|separator|>\n\nHuman: {text}<|separator|>\n\nAssistant: " + "{\n"
print(prompt)
async for token in sampler.sample(
prompt=prompt,
max_len=1024,
stop_tokens=["<|separator|>"],
temperature=0.5,
nucleus_p=0.95):
print(token.token_str, end="")
print()
if __name__ == '__main__':
asyncio.run(main())