Api
Python配置方式
如何使用python 调用api
Python基础对话
key='sk-xxxx'
from openai import OpenAI
client = OpenAI(
base_url="https://api.aiki.cc/v1",
api_key=key
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "你好?"},
]
)
print(response)
Python使用gpt-4o识别图片
from openai import OpenAI
client = OpenAI(
base_url="https://api.aiki.cc/v1",
api_key=key
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What’s in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
},
],
}
],
max_tokens=300,
)
print(response.choices[0])
Python使用Claude识别图片
from openai import OpenAI
client = OpenAI(
base_url="https://api.aiki.cc/v1",
api_key=key
)
response = client.chat.completions.create(
model="claude-3-5-sonnet-20240620",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What’s in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
},
],
}
],
max_tokens=300,
)
print(response.choices[0])