forked from IBM/ibm-generative-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpt_chat_bash.py
33 lines (25 loc) · 828 Bytes
/
gpt_chat_bash.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
import os
from dotenv import load_dotenv
from genai.model import Credentials, Model
from genai.schemas import GenerateParams, ModelType
# make sure you have a .env file under genai root with
# GENAI_KEY=<your-genai-key>
load_dotenv()
api_key = os.getenv("GENAI_KEY", None)
print("\n------------- Example (GPT Chat)-------------\n")
params = GenerateParams(
decoding_method="sample",
max_new_tokens=128,
min_new_tokens=1,
stream=False,
temperature=0.7,
top_k=50,
top_p=1,
)
creds = Credentials(api_key)
chat = Model(ModelType.FLAN_UL2_20B, params=params, credentials=creds)
prompt = "Write a bash script to split string on comma display as list"
print(f"Prompt {prompt}")
responses = chat.generate([prompt])
for response in responses:
print(f"Generated text:\n {response.generated_text}")