-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy path001-connect-llm.py
More file actions
61 lines (40 loc) · 1.25 KB
/
001-connect-llm.py
File metadata and controls
61 lines (40 loc) · 1.25 KB
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
56
57
58
59
60
61
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai_api_key = os.environ["OPENAI_API_KEY"]
from langchain_openai import OpenAI
llmModel = OpenAI()
print("\n----------\n")
response = llmModel.invoke(
"Tell me one fun fact about the Kennedy family."
)
print("Tell me one fun fact about the Kennedy family:")
print(response)
print("\n----------\n")
print("Streaming:")
for chunk in llmModel.stream(
"Tell me one fun fact about the Kennedy family."
):
print(chunk, end="", flush=True)
print("\n----------\n")
creativeLlmModel = OpenAI(temperature=0.9)
response = llmModel.invoke(
"Write a short 5 line poem about JFK"
)
print("Write a short 5 line poem about JFK:")
print(response)
print("\n----------\n")
from langchain_openai import ChatOpenAI
chatModel = ChatOpenAI(model="gpt-3.5-turbo-0125")
messages = [
("system", "You are an historian expert in the Kennedy family."),
("human", "Tell me one curious thing about JFK."),
]
response = chatModel.invoke(messages)
print("Tell me one curious thing about JFK:")
print(response.content)
print("\n----------\n")
print("Streaming:")
for chunk in chatModel.stream(messages):
print(chunk.content, end="", flush=True)
print("\n----------\n")