func()

in internal/enricher/enricher.go [615:672]


func (mc *MetadataCollector) generateDescriptionWithGemini(ctx context.Context, metadata *ColumnMetadata, schemaContext string) (string, error) {
	if mc.GeminiAPIKey == "" {
		return "", nil
	}

	if mc.AdditionalContext == "" {
		return "", nil
	}

	prompt := fmt.Sprintf(`
Your task is to generate a brief and concise description for a database column based on the provided context.
The context might be irrelevant, so you need to firstly read through the context and decide if there is any relevant information for the target table.column.

********** Knowledge Context **********
%s

********** End Knowledge Context **********

**Instructions:**
- Response starting with your analysis. Then output the description in between <result></result> tags.
- Focus on the column's purpose and meaning within the database.
- Be concise and informative, no more than 50 words.
- Important: Only provide a description for the column if there is information related to this column in additional context. Otherwise in all other cases, return empty <result></result> tags.

The target table and column is:
Column Name: %s in Table: %s

Now start your response. Remember, only give description when the knowledge context provides useful information about the column.
	`, mc.AdditionalContext, metadata.Column, metadata.Table)

	client, err := genai.NewClient(ctx, option.WithAPIKey(mc.GeminiAPIKey))
	if err != nil {
		return "", fmt.Errorf("failed to create Gemini client: %w", err)
	}
	defer client.Close()

	model_name := mc.Model
	if model_name == "" {
		model_name = "gemini-1.5-pro-002"
	}
	model := client.GenerativeModel(model_name)
	model.SetTemperature(0.4)
	model.SetMaxOutputTokens(500)
	model.SetTopP(0.8)
	model.SetTopK(40)

	resp, err := model.GenerateContent(ctx, genai.Text(prompt))
	if err != nil {
		return "", fmt.Errorf("Gemini API call failed: %w", err)
	}

	description, err := extractTextFromResponse(resp)
	if err != nil {
		return "", err
	}

	return description, nil
}