Python
簡單的展示如何使用Python來呼叫Stima API,Stima API為OpenAI base,故使用Python中的openai套件,並修改model變數即可呼叫所有支援模型。
from openai import OpenAI
api_key = 'sk-xxxxxxxxxxxxxxxxxxxxxxxx'
client = OpenAI(
api_key=api_key,
base_url="https://api.stima.tech/v1/"
)
chat_completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Hello world"}
]
)
print(chat_completion.choices[0].message.content)
或是使用class方式導入,modelName
與messages
都可以自行編輯。
import openai
import time
class api_cluster:
def __init__(self, modelName = "gemini-1.5-flash-latest"):
self.modelName = modelName
self.client = openai.OpenAI(
base_url="https://api.wlai.vip/v1",
api_key="sk-xxx"
)
messages = [
{"role": "system", "content": "You are a helpful assistant."}
]
def send_read_respond(self, user_input, stream=False, temperature= 0.5):
response = self.client.chat.completions.create(
model= self.modelName,
messages=[{"role": "user", "content": user_input}],
temperature=temperature,
)
assistant_response = response.choices[0].message.content
return assistant_response
cURL
簡單展示如何使用cURL呼叫Stima API,也是僅需修改model變數即可呼叫所有支援模型。
curl https://api.stima.tech/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-d '{
"model": "gpt-3.5-turbo"
"messages": [
{
"role": "system",
"content": "You are a test assistant."
}
]
}'