Skip to content

Commit

Permalink
Merge pull request #105 from Abirdcfly/main
Browse files Browse the repository at this point in the history
feat: add llama2 in dashscope as llm
  • Loading branch information
bjwswang authored Oct 10, 2023
2 parents 2484b8e + 7261fb5 commit 38f0813
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions examples/dashscope/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func main() {
panic(err)
}
}
for _, model := range []dashscope.Model{dashscope.LLAMA27BCHATV2, dashscope.LLAMA213BCHATV2} {
klog.V(0).Infof("\nChat with %s\n", model)
resp, err := sampleChatWithLlama2(apiKey, model)
if err != nil {
panic(err)
}
klog.V(0).Infof("Response: \n %s\n", resp)
}
klog.Infoln("sample chat done")
}

Expand All @@ -62,6 +70,14 @@ func sampleChat(apiKey string, model dashscope.Model) (llms.Response, error) {
return client.Call(params.Marshal())
}

func sampleChatWithLlama2(apiKey string, model dashscope.Model) (llms.Response, error) {
client := dashscope.NewDashScope(apiKey, false)
params := dashscope.DefaultModelParams()
params.Model = model
params.Input.Prompt = samplePrompt
return client.Call(params.Marshal())
}

func sampleSSEChat(apiKey string, model dashscope.Model) error {
client := dashscope.NewDashScope(apiKey, true)
params := dashscope.DefaultModelParams()
Expand Down
4 changes: 4 additions & 0 deletions pkg/llms/dashscope/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ const (
type Model string

const (
// 通义千问对外开源的 14B / 7B 规模参数量的经过人类指令对齐的 chat 模型
QWEN14BChat Model = "qwen-14b-chat"
QWEN7BChat Model = "qwen-7b-chat"
// LLaMa2 系列大语言模型由 Meta 开发并公开发布,其规模从 70 亿到 700 亿参数不等。在灵积上提供的 llama2-7b-chat-v2 和 llama2-13b-chat-v2,分别为 7B 和 13B 规模的 LLaMa2 模型,针对对话场景微调优化后的版本。
LLAMA27BCHATV2 Model = "llama2-7b-chat-v2"
LLAMA213BCHATV2 Model = "llama2-13b-chat-v2"
)

var _ llms.LLM = (*DashScope)(nil)
Expand Down
3 changes: 2 additions & 1 deletion pkg/llms/dashscope/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type ModelParams struct {
// +kubebuilder:object:generate=true

type Input struct {
Messages []Message `json:"messages"`
Messages []Message `json:"messages,omitempty"`
Prompt string `json:"prompt,omitempty"`
}

type Parameters struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/llms/dashscope/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type Response struct {
}

type Output struct {
Choices []Choice `json:"choices"`
Choices []Choice `json:"choices,omitempty"`
Text string `json:"text,omitempty"`
}

type FinishReason string
Expand Down

0 comments on commit 38f0813

Please sign in to comment.