Skip to content

feat(plugin): ai prompt template #12278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

feat(plugin): ai prompt template #12278

wants to merge 5 commits into from

Conversation

ttyS0e
Copy link
Contributor

@ttyS0e ttyS0e commented Jan 2, 2024

Summary

This plugin adds the ability to provide tuned AI prompts to users, who only need to fill in the blanks with variable placeholders (in moustache format: {{variable}} )

It is to be used in conjunction with ai-proxy plugin, as with other AI Family plugins.

AI-Proxy plugin

This allows prompt tuning to be started, or performed, by the experience LLM users in an organisation, and then consumed by anyone.

When activated, it looks for template references in the following forms:

Chat:

{
	"messages": "{template://developer-chat}",
	"properties": {
		"language": "python",
		"program": "flask web server"
	}
}

Prompt:

{
	"prompt": "{template://developer-prompt}",
	"properties": {
		"language": "python",
		"program": "flask web server"
	}
}

Based on this gateway configuration:

_format_version: "3.0"

services:
- name: default
  host: localhost
  path: "/"
  port: 9900
  protocol: https
  routes:
  - name: openai-chat
    paths:
    - "~/openai/chat$"
    methods:
    - POST
    plugins:
    - name: ai-proxy
      config:
        route_type: "llm/v1/chat"
        auth:
          header_name: "Authorization"
          header_value: "Bearer REDACT"
        logging:
          log_statistics: true
          log_payloads: false
        model:
          provider: "openai"
          name: "gpt-3.5-turbo"
          options:
            max_tokens: 512
            temperature: 1.0
    plugins:
    - name: ai-prompt-template
      config:
        allow_untemplated_requests: true
        templates:
        - name: "developer-chat"
          template:  |-
            {
              "messages": [
                {
                  "role": "system",
                  "content": "You are a {{program}} expert, in {{language}} programming language."
                },
                {
                  "role": "user",
                  "content": "Write me a {{program}} program."
                }
              ]
            }
        - name: "developer-prompt"
          template:  |-
            {
              "prompt": "You are a {{language}} programming language expert. Write me a {{program}} program."
            }

It has been designed to work with other formats as soon as they are supported.

It also sanitises string inputs to ensure that json control characters are escaped, preventing arbitrary prompt injection.

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - docs PR for all four "AI Family" pluigins is still being worked on separately.

Issue reference

Internal project.

@github-actions github-actions bot added chore Not part of the core functionality of kong, but still needed schema-change-noteworthy labels Jan 2, 2024
@tysoekong tysoekong changed the title Feat/plugin ai prompt template feat(plugin): ai prompt template Jan 2, 2024
@team-eng-enablement team-eng-enablement added the author/community PRs from the open-source community (not Kong Inc) label Jan 2, 2024
@locao locao requested a review from brentos January 2, 2024 17:46
@ttyS0e
Copy link
Contributor Author

ttyS0e commented Jan 12, 2024

All addressed in #12340

@ttyS0e ttyS0e closed this Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author/community PRs from the open-source community (not Kong Inc) chore Not part of the core functionality of kong, but still needed schema-change-noteworthy size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants