forked from chromalock/TI-32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestapi2.py
40 lines (32 loc) · 1.09 KB
/
testapi2.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 sys
from openai import OpenAI
# Replace with your actual API key
YOUR_API_KEY = "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"
# Initialize the client
client = OpenAI(api_key=YOUR_API_KEY, base_url="https://api.perplexity.ai")
def get_perplexity_response(prompt):
messages = [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": prompt}
]
try:
response = client.chat.completions.create(
model="llama-3-sonar-large-32k-online",
messages=messages,
)
return response.choices[0].message.content
except Exception as e:
return f"An error occurred: {str(e)}"
def main():
print("Welcome to the Perplexity AI CLI!")
print("Type 'exit' to quit.")
while True:
user_input = input("\nYou: ")
if user_input.lower() == 'exit':
print("Goodbye!")
sys.exit(0)
print("\nPerplexity AI: ", end="")
response = get_perplexity_response(user_input)
print(response)
if __name__ == "__main__":
main()