跳转至

OpenAI

文本/对话请求

可用模型清单:https://platform.openai.com/docs/models/overview

import Agently
agent = (
    Agently.create_agent()
        .set_settings("current_model", "OpenAI")
        .set_settings("model.OpenAI.auth", { "api_key": "<Your-API-Key>" })
        # 如果需要切换模型,可参考模型清单: https://platform.openai.com/docs/models/overview
        # 默认模型: gpt-3.5-turbo
        .set_settings("model.OpenAI.options", { "model": "gpt-3.5-turbo" })
        # 如果您需要使用转发Base URL,通常为https://base_domain_name.com/v1这样的格式
        # .set_settings("model.OpenAI.url", "<Your-Base-URL>")
        # 如果您需要使用本地代理,确定本地代理的host和port后,可以按如下方式设置
        # .set_settings("proxy", "http://127.0.0.1:7890")
)

Vision模型请求

我们为GPT-4-Vision提供了请求方案。

import Agently
agent = (
    Agently.create_agent()
        .set_settings("current_model", "OpenAI")\
        .set_settings("model.OpenAI.auth", { "api_key": "<Your-API-Key>" })\
        .set_settings("model.OpenAI.options", { "model": "gpt-4-vision-preview" })
)

# 请求样例
result = (
    agent
        .files("https://cdn.hk01.com/di/media/images/dw/20200921/384674239925587968.jpeg/KJA2TRK9dzKTpbuXoVyiyz-DjNXw5N9RATMoCwEzKAs?v=w1280")
        .output({
            "observe": ("String", "Describe what can you see in this picture"),
            "explain": ("String", "Explain how can we thinking about this picture"),
            "tags": [("String", "Classify tag that you will give to this picture")]
        })
        .start("vision")
)
for key, content in result.items():
    print(key, ": ", content)