-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest.py
37 lines (29 loc) · 878 Bytes
/
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
import os
import vertexai
PROJECT_ID = "tt-dev-001"
LOCATION = "us-central1"
vertexai.init(project=PROJECT_ID, location=LOCATION)
def create_session():
chat_model = vertexai.language_models.ChatModel.from_pretrained("chat-bison@001")
chat = chat_model.start_chat()
return chat
def response(chat, message):
parameters = {
"temperature": 0.2,
"max_output_tokens": 256,
"top_p": 0.8,
"top_k": 40
}
result = chat.send_message(message, **parameters)
return result.text
def run_chat():
chat_model = create_session()
print(f"Chat Session created")
while True:
user_input = input("You: ")
if user_input.lower() in ['exit', 'quit']:
break
content = response(chat_model, user_input)
print(f"AI: {content}")
if __name__ == '__main__':
run_chat()