Commit e1fb0284 authored by Wade's avatar Wade

split flow

parent a0086259
This diff is collapsed.
...@@ -169,7 +169,7 @@ paths: ...@@ -169,7 +169,7 @@ paths:
model: model:
type: string type: string
description: The model to use for the chat response description: The model to use for the chat response
example: "gpt-3.5-turbo" example: "deepseek/deepseek-chat"
apiKey: apiKey:
type: string type: string
description: The API key for authentication description: The API key for authentication
......
...@@ -243,18 +243,6 @@ func main() { ...@@ -243,18 +243,6 @@ func main() {
}, nil }, nil
}) })
simpleQaPrompt, err := genkit.DefinePrompt(g, "simpleQaPrompt",
// ai.WithModelName("googleai/gemini-2.0-flash"),
// deepseek
ai.WithModelName("deepseek/deepseek-chat"),
ai.WithPrompt(simpleQaPromptTemplate),
ai.WithInputType(simpleQaPromptInput{}),
ai.WithOutputFormat(ai.OutputFormatText),
)
if err != nil {
log.Fatal().Msg(err.Error())
}
qa, err := question.InitQAStore(*pgConnString) qa, err := question.InitQAStore(*pgConnString)
if err != nil { if err != nil {
log.Fatal().Msgf("InitQAStore failed: %v", err) log.Fatal().Msgf("InitQAStore failed: %v", err)
...@@ -361,6 +349,15 @@ func main() { ...@@ -361,6 +349,15 @@ func main() {
fmt.Println("graph time", time.Since(begin).Seconds()) fmt.Println("graph time", time.Since(begin).Seconds())
simpleQaPrompt,err := defineSimpleQaPrompt(g,input.Model)
if err != nil {
return Response{
Code: 500,
Msg: fmt.Sprintf("index document: %w", err),
}, nil
}
resp, err := simpleQaPrompt.Execute(ctx, ai.WithInput(promptInput)) resp, err := simpleQaPrompt.Execute(ctx, ai.WithInput(promptInput))
if err != nil { if err != nil {
...@@ -448,3 +445,49 @@ type Response struct { ...@@ -448,3 +445,49 @@ type Response struct {
Code int `json:"code"` Code int `json:"code"`
Msg string `json:"msg"` Msg string `json:"msg"`
} }
// defineSimpleQaPrompt 加载或定义指定名称的 Prompt
func defineSimpleQaPrompt(g *genkit.Genkit, promptName string) (*ai.Prompt, error) {
// 步骤 1:尝试查找现有的 Prompt
log.Info().
Str("method", "defineSimpleQaPrompt").
Str("prompt_name", promptName).
Msg("Attempting to lookup prompt")
prompt := genkit.LookupPrompt(g, promptName)
if prompt != nil {
log.Info().
Str("method", "defineSimpleQaPrompt").
Str("prompt_name", promptName).
Msg("Prompt found and loaded")
return prompt, nil
}
log.Info().
Str("method", "defineSimpleQaPrompt").
Str("prompt_name", promptName).
Msg("Prompt not found, defining new prompt")
// 步骤 2:如果未找到,定义新的 Prompt
simpleQaPrompt, err := genkit.DefinePrompt(g, promptName,
// ai.WithModelName("deepseek/deepseek-chat"),
ai.WithModelName(promptName),
ai.WithPrompt(simpleQaPromptTemplate),
ai.WithInputType(simpleQaPromptInput{}),
ai.WithOutputFormat(ai.OutputFormatText),
)
if err != nil {
log.Error().
Str("method", "defineSimpleQaPrompt").
Str("prompt_name", promptName).
Err(err).
Msg("Failed to define prompt")
return nil, err
}
log.Info().
Str("method", "defineSimpleQaPrompt").
Str("prompt_name", promptName).
Msg("Prompt defined successfully")
return simpleQaPrompt, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment