-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_api.txt
More file actions
61 lines (46 loc) · 1.44 KB
/
Copy pathpython_api.txt
File metadata and controls
61 lines (46 loc) · 1.44 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
Python API
The Hyperbolic API provides compatibility for the OpenAI API standard, allowing easier integrations into existing applications.
Suggest Edits
If you’ve been using OpenAI API such as GPT-4 and GPT-4 Turbo, switching to Hyperbolic API is easy!
Requirements
Install OpenAI's Python SDK:
python3 -m pip install openai
Example code
Simply replace the api_key and base_url to the Hyperbolic ones.
import os
import openai
system_content = "You are a gourmet. Be descriptive and helpful."
user_content = "Tell me about Chinese hotpot"
client = openai.OpenAI(
api_key=HYPERBOLIC_API_KEY,
base_url="https://api.hyperbolic.xyz/v1",
)
chat_completion = client.chat.completions.create(
model="meta-llama/Meta-Llama-3-70B-Instruct",
messages=[
{"role": "system", "content": system_content},
{"role": "user", "content": user_content},
],
temperature=0.7,
max_tokens=1024,
)
response = chat_completion.choices[0].message.content
print("Response:\n", response)
import requests
url = "https://api.hyperbolic.xyz/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <api-key>"
}
data = {
"messages": [{
"role": "user",
"content": "What can I do in SF?"
}],
"model": "deepseek-ai/DeepSeek-V3-0324",
"max_tokens": 512,
"temperature": 0.1,
"top_p": 0.9
}
response = requests.post(url, headers=headers, json=data)
print(response.json())