admin管理员组文章数量:1631701
例子1 Simple
from openai import OpenAI
client = OpenAI(
api_key="xxxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
completion = client.chatpletions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "简单计算"},
{"role": "user", "content": "1+12等于多少?"}
],
temperature=0.3,
)
print(completion.choices[0].message.content)
例子2 Function_call
from openai import OpenAI
client = OpenAI(
api_key="xxxxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
article="the wind"
functions = [
{
"name": "write_post",
"description": "Shows the title and summary of some text.",
"parameters": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "Title of the text output."
},
"summary": {
"type": "string",
"description": "Summary of the text output."
}
}
}
}
]
completion = client.chatpletions.create(
model="gpt-3.5-turbo",
messages = [
{
"role": "system",
"content": "You are a useful assistant."
},
{
"role": "user",
"content": f"Here is an article: {article}. Please return a title and summary."
},
],
functions = functions,
function_call = {
"name": functions[0]["name"]
}
)
print(completion.choices[0].message.function_call.arguments)
例子3 Embedding
from openai import OpenAI
client = OpenAI(
api_key="xxxxxx",
base_url="https://api.chatanywhere.tech/v1"
)
completion =client.embeddings.create(
input="what is the berlin wall?",
model="text-embedding-ada-002"
)
print(completion.data[0].embedding)
版权声明:本文标题:Python 的chatGPT API小例子 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729101952a1186688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论