messages := []llms.MessageContent{llms.TextParts(llms.ChatMessageTypeSystem, "你是一个英文翻译员,需要将<>括起来的英文翻译为中文,用JSON格式输出:原始文本、翻译文本"),llms.TextParts(llms.ChatMessageTypeHuman, "<hello world>"),}content, err := llm.GenerateContent(ctx, messages, llms.WithJSONMode())
type MessageContent struct {Role ChatMessageTypeParts []ContentPart}
type ChatMessageType string
type ContentPart interface {isPart()}
func TextParts(role ChatMessageType, parts ...string) MessageContent {result := MessageContent{Role: role,Parts: []ContentPart{},}for _, part := range parts {result.Parts = append(result.Parts, TextPart(part))}return result}
func TextPart(s string) TextContent {return TextContent{Text: s}}
type TextContent struct {Text string}func (tc TextContent) String() string {return tc.Text}func (TextContent) isPart() {}
func WithJSONMode() CallOption {return func(o *CallOptions) {o.JSONMode = true}}
req := &openaiclient.ChatRequest{Model: opts.Model,StopWords: opts.StopWords,Messages: chatMsgs,StreamingFunc: opts.StreamingFunc,Temperature: opts.Temperature,N: opts.N,FrequencyPenalty: opts.FrequencyPenalty,PresencePenalty: opts.PresencePenalty,MaxCompletionTokens: opts.MaxTokens,ToolChoice: opts.ToolChoice,FunctionCallBehavior: openaiclient.FunctionCallBehavior(opts.FunctionCallBehavior),Seed: opts.Seed,Metadata: opts.Metadata,}if opts.JSONMode {req.ResponseFormat = ResponseFormatJSON}


文章转载自golang算法架构leetcode技术php,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




