0
点赞
收藏
分享

微信扫一扫

MoonBit MeetUp回顾——张正、宗喆:编程语言在云原生与区块链领域的技术探索

小铺有酒一两不够 03-31 22:30 阅读 3

例子1 Simple

from openai import OpenAI

client = OpenAI(
    api_key="xxxxxx",
    base_url="https://api.chatanywhere.tech/v1"
)
 
completion = client.chat.completions.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.chat.completions.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)
举报

相关推荐

0 条评论