-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (48 loc) · 1.93 KB
/
main.py
File metadata and controls
65 lines (48 loc) · 1.93 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
62
63
64
65
# pip install aisuite[all]
import os
import aisuite as ai
from config import *
# Set API keys as environment variables
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
os.environ['ANTHROPIC_API_KEY'] = ANTHROPIC_API_KEY
os.environ['HUGGINGFACE_TOKEN'] = HF_API_KEY
os.environ['GROQ_API_KEY'] = GROQ_API_KEY
client = ai.Client()
# 4.1
messages = [
{"role": "system", "content": "You are a creative thinker."},
{"role": "user", "content": "Suggest five app ideas that promote sustainable living."}
]
response = client.chat.completions.create(model="openai:gpt-4o", messages=messages)
print("\n".join([f"{i+1}. {idea}" for i, idea in enumerate(response.choices[0].message.content.splitlines())]))
# 4.2
# Specify the Hugging Face model
hf_model = "huggingface:mistralai/Mistral-7B-Instruct-v0.3"
# Prepare the conversation
messages = [
{"role": "user", "content": "Can you explain the concept of generative AI in simple terms?"}
]
# Generate a response
response = client.chat.completions.create(
model=hf_model,
messages=messages
)
# Print the response
print("AI Response:")
print(response.choices[0].message.content)
# 4.3
messages = [
{"role": "system", "content": "You are a math tutor."},
{"role": "user", "content": "Explain how to solve for x in the equation 2x + 5 = 15."}
]
groq_llama3_8b = "groq:llama3-8b-8192"
# groq_llama3_70b = "groq:llama3-70b-8192"
response = client.chat.completions.create(model=groq_llama3_8b, messages=messages)
print(response.choices[0].message.content)
# 4.4
messages = [
{"role": "system", "content": "You are a sentiment analysis expert."},
{"role": "user", "content": "Analyze the sentiment of this review: 'The product quality is excellent, but delivery was delayed.'"}
]
response = client.chat.completions.create(model="openai:gpt-4o", messages=messages)
print(response.choices[0].message.content)