openai
成员函数 | 函数描述/介绍 |
---|---|
openai.Chat | Chat 使用 OpenAI 的大语言模型进行对话,返回对话结果 |
openai.FunctionCall | FunctionCall 使用 OpenAI 的大语言模型的函数调用功能,描述一个函数并让模型智能地选择输出一个包含调用函数的参数的 JSON 对象 详情请参考 https://platform.openai.com/docs/guides/function-calling @param {st... |
openai.TranslateToChinese | TranslateToChinese 使用 OpenAI 的大语言模型将传入的字符串翻译为中文,还可以接收零个到多个配置选项,用于配置代理、API Key、模型等,返回翻译后的中文字符串 |
openai.apiKey | apiKey 设置 OpenAI的API Key |
openai.domain | domain 设置 OpenAI的第三方加速域名,用于加速访问 |
openai.functionParamType | functionParamType 设置函数调用时的参数类型,默认为 "object" |
openai.functionProperty | functionProperty 设置函数调用时的单个参数属性 |
openai.functionRequired | functionRequired 设置函数调用时的必须参数 |
openai.localAPIKey | |
openai.model | model 设置 OpenAI的大语言模型 |
openai.proxy | proxy 设置调用 OpenAI 时使用的代理 |
openai.yakDomain |
#
函数定义#
Chat#
详细描述Chat 使用 OpenAI 的大语言模型进行对话,返回对话结果
Example:
result = openai.Chat("Hello, world!", openai.apiKey("sk-xxx"), openai.proxy("http://127.0.0.1:7890"))
#
定义Chat(data string, opts ...ConfigOption) string
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
data | string | |
opts | ...ConfigOption |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | string |
#
FunctionCall#
详细描述FunctionCall 使用 OpenAI 的大语言模型的函数调用功能,描述一个函数并让模型智能地选择输出一个包含调用函数的参数的 JSON 对象
详情请参考 https://platform.openai.com/docs/guides/function-calling
@param {string} data 用户的提问或描述
@param {string} funcName 函数名
@param {string} funcDesc 函数描述
@param {ConfigOption} ...opts 配置选项,用于配置代理、API Key、模型等
@return {map[string]any} 返回一个包含调用函数的参数的映射
Example:
resultMap = openai.FunctionCall("What is the weather like in Boston?","get_current_weather","Get the current weather in a given location",openai.apiKey("sk-xxxx"),openai.proxy("http://127.0.0.1:7890"),openai.functionProperty("location", "string", "The city and state, e.g. San Francisco, CA"),openai.functionRequired("location"))
#
定义FunctionCall(data string, funcName string, funcDesc string, opts ...ConfigOption) map[string]any
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
data | string | |
funcName | string | |
funcDesc | string | |
opts | ...ConfigOption |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | map[string]any |
#
TranslateToChinese#
详细描述TranslateToChinese 使用 OpenAI 的大语言模型将传入的字符串翻译为中文,还可以接收零个到多个配置选项,用于配置代理、API Key、模型等,返回翻译后的中文字符串
Example:
result = openai.TranslateToChinese("Hello, world!", openai.apiKey("sk-xxx"), openai.proxy("http://127.0.0.1:7890"))
#
定义TranslateToChinese(data string, opts ...ConfigOption) string
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
data | string | |
opts | ...ConfigOption |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | string |
#
apiKey#
详细描述apiKey 设置 OpenAI的API Key
Example:
result = openai.TranslateToChinese("Hello, world!", openai.apiKey("sk-xxx"))
#
定义apiKey(i string) ConfigOption
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
i | string |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | ConfigOption |
#
domain#
详细描述domain 设置 OpenAI的第三方加速域名,用于加速访问
Example:
result = openai.TranslateToChinese("Hello, world!", openai.apiKey("sk-xxx"), openai.domain("api.ai.yaklang.com"))
#
定义domain(i string) ConfigOption
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
i | string |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | ConfigOption |
#
functionParamType#
详细描述functionParamType 设置函数调用时的参数类型,默认为 "object"
Example:
resultMap = openai.FunctionCall("What is the weather like in Boston?","get_current_weather","Get the current weather in a given location",openai.apiKey("sk-xxxx"),openai.proxy("http://127.0.0.1:7890"),openai.functionProperty("location", "string", "The city and state, e.g. San Francisco, CA"),openai.functionRequired("location"))
#
定义functionParamType(i string) ConfigOption
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
i | string |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | ConfigOption |
#
functionProperty#
详细描述functionProperty 设置函数调用时的单个参数属性
Example:
resultMap = openai.FunctionCall("What is the weather like in Boston?","get_current_weather","Get the current weather in a given location",openai.apiKey("sk-xxxx"),openai.proxy("http://127.0.0.1:7890"),openai.functionProperty("location", "string", "The city and state, e.g. San Francisco, CA"),openai.functionRequired("location"))
#
定义functionProperty(name string, typ string, description string, enum ...[]string) ConfigOption
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
name | string | |
typ | string | |
description | string | |
enum | ...[]string |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | ConfigOption |
#
functionRequired#
详细描述functionRequired 设置函数调用时的必须参数
Example:
resultMap = openai.FunctionCall("What is the weather like in Boston?","get_current_weather","Get the current weather in a given location",openai.apiKey("sk-xxxx"),openai.proxy("http://127.0.0.1:7890"),openai.functionProperty("location", "string", "The city and state, e.g. San Francisco, CA"),openai.functionRequired("location"))
#
定义functionRequired(names ...string) ConfigOption
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
names | ...string |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | ConfigOption |
#
localAPIKey#
详细描述#
定义localAPIKey(client *Client)
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
client | *Client |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | `` |
#
model#
详细描述model 设置 OpenAI的大语言模型
Example:
result = openai.TranslateToChinese("Hello, world!", openai.apiKey("sk-xxx"), openai.model("gpt-4-0613"))
#
定义model(i string) ConfigOption
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
i | string |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | ConfigOption |
#
proxy#
详细描述proxy 设置调用 OpenAI 时使用的代理
Example:
result = openai.TranslateToChinese("Hello, world!", openai.apiKey("sk-xxx"), openai.proxy("http://127.0.0.1:7890"))
#
定义proxy(i string) ConfigOption
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
i | string |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | ConfigOption |
#
yakDomain#
详细描述#
定义yakDomain(client *Client)
#
参数参数名 | 参数类型 | 参数解释 |
---|---|---|
client | *Client |
#
返回值返回值(顺序) | 返回值类型 | 返回值解释 |
---|---|---|
r1 | `` |