您的位置:首页 > 娱乐 > 明星 > 快手小程序_产品经理培训哪个机构好_怎么创建一个网站_临沂今日头条新闻最新

快手小程序_产品经理培训哪个机构好_怎么创建一个网站_临沂今日头条新闻最新

2025/2/27 8:55:50 来源:https://blog.csdn.net/biancheng4/article/details/145855538  浏览:    关键词:快手小程序_产品经理培训哪个机构好_怎么创建一个网站_临沂今日头条新闻最新
快手小程序_产品经理培训哪个机构好_怎么创建一个网站_临沂今日头条新闻最新

1.查看官网

在这里插入图片描述

发现只有ollama,openai,Mistral于是查看代码

2.代码查看

先从llm, err := openai.New(url, model, token)开始

在这里插入图片描述

发现New方法可以传option参数,再看一下option参数
const (tokenEnvVarName        = "OPENAI_API_KEY"      //nolint:gosecmodelEnvVarName        = "OPENAI_MODEL"        //nolint:gosecbaseURLEnvVarName      = "OPENAI_BASE_URL"     //nolint:gosecbaseAPIBaseEnvVarName  = "OPENAI_API_BASE"     //nolint:gosecorganizationEnvVarName = "OPENAI_ORGANIZATION" //nolint:gosec
)type APIType openaiclient.APITypeconst (APITypeOpenAI  APIType = APIType(openaiclient.APITypeOpenAI)APITypeAzure           = APIType(openaiclient.APITypeAzure)APITypeAzureAD         = APIType(openaiclient.APITypeAzureAD)
)const (DefaultAPIVersion = "2023-05-15"
)type options struct {token        stringmodel        stringbaseURL      stringorganization stringapiType      APITypehttpClient   openaiclient.DoerresponseFormat *ResponseFormat// required when APIType is APITypeAzure or APITypeAzureADapiVersion     stringembeddingModel stringcallbackHandler callbacks.Handler
}// Option is a functional option for the OpenAI client.
type Option func(*options)// ResponseFormat is the response format for the OpenAI client.
type ResponseFormat = openaiclient.ResponseFormat// ResponseFormatJSON is the JSON response format.
var ResponseFormatJSON = &ResponseFormat{Type: "json_object"} //nolint:gochecknoglobals// WithToken passes the OpenAI API token to the client. If not set, the token
// is read from the OPENAI_API_KEY environment variable.
func WithToken(token string) Option {return func(opts *options) {opts.token = token}
}// WithModel passes the OpenAI model to the client. If not set, the model
// is read from the OPENAI_MODEL environment variable.
// Required when ApiType is Azure.
func WithModel(model string) Option {return func(opts *options) {opts.model = model}
}// WithEmbeddingModel passes the OpenAI model to the client. Required when ApiType is Azure.
func WithEmbeddingModel(embeddingModel string) Option {return func(opts *options) {opts.embeddingModel = embeddingModel}
}// WithBaseURL passes the OpenAI base url to the client. If not set, the base url
// is read from the OPENAI_BASE_URL environment variable. If still not set in ENV
// VAR OPENAI_BASE_URL, then the default value is https://api.openai.com/v1 is used.
func WithBaseURL(baseURL string) Option {return func(opts *options) {opts.baseURL = baseURL}
}// WithOrganization passes the OpenAI organization to the client. If not set, the
// organization is read from the OPENAI_ORGANIZATION.
func WithOrganization(organization string) Option {return func(opts *options) {opts.organization = organization}
}// WithAPIType passes the api type to the client. If not set, the default value
// is APITypeOpenAI.
func WithAPIType(apiType APIType) Option {return func(opts *options) {opts.apiType = apiType}
}// WithAPIVersion passes the api version to the client. If not set, the default value
// is DefaultAPIVersion.
func WithAPIVersion(apiVersion string) Option {return func(opts *options) {opts.apiVersion = apiVersion}
}// WithHTTPClient allows setting a custom HTTP client. If not set, the default value
// is http.DefaultClient.
func WithHTTPClient(client openaiclient.Doer) Option {return func(opts *options) {opts.httpClient = client}
}// WithCallback allows setting a custom Callback Handler.
func WithCallback(callbackHandler callbacks.Handler) Option {return func(opts *options) {opts.callbackHandler = callbackHandler}
}// WithResponseFormat allows setting a custom response format.
func WithResponseFormat(responseFormat *ResponseFormat) Option {return func(opts *options) {opts.responseFormat = responseFormat}
}
这里发现了各种配置的地方,以及获取环境变量,于是我们使用openai包下面的各种with方法来配置deepseek的地址
// 我这里使用的是腾讯的API
url := openai.WithBaseURL("https://api.lkeap.cloud.tencent.com/v1/chat/completions")model := openai.WithModel("deepseek-v3")token := openai.WithToken("API-KEY")// We can construct an LLMChain from a PromptTemplate and an LLM.llm, err := openai.New(url, model, token)if err != nil {return err}ctx := context.Background()completion, err := llm.Call(ctx, "The first man to walk on the moon",llms.WithTemperature(0.8),llms.WithStopWords([]string{"Armstrong"}))if err != nil {return err}fmt.Println(completion)return nil

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com