青蛙小白
目录

OpenAI API

https://platform.openai.com/docs/api-reference/introduction

OpenAPI spec for the OpenAI API

EndPoints

Chat

https://platform.openai.com/docs/api-reference/chat

给定一组包含对话的消息列表(messages),模型将返回一个回复(response)。

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[
    {"role": "system", "content": "你是一个有用的助手."},
    {"role": "user", "content": "什么是大语言模型?"}
  ],
  temperature=0
)
print(response.choices[0].message.content)

环境变量

export OPENAI_BASE_URL=https://xxx.com/v1
export OPENAI_API_KEY=xxx

Embeddings

https://platform.openai.com/docs/api-reference/embeddings

获取给定输入的向量表示,这种表示可以被机器学习模型和算法轻松使用。

评论