XU XUv0.16.0

#github.com/xulang-org/packages/prompt

import: prompt #github.com/xulang-org/packages/prompt

counts: 6 functions, 4 methods, 3 types, 0 constants, 0 method sets

External package `prompt #github.com/xulang-org/packages/prompt`, provided by github.com/xulang-org/packages.

github.com/xulang-org/packages · 1.17.2 · Install and use

struct PromptTemplate

XuAPI
pub struct PromptTemplate {
    pub name string
    pub version string
    pub system_template string
    pub user_template string
    pub required_vars []string
}

Purpose

Structure encapsulating name, version, system_template, user_template, required_vars.

Public fields

name string
name
version string
field (string)
system_template string
field (string)
user_template string
field (string)
required_vars []string
field ([]string)

struct PromptRegistry

XuAPI
pub struct PromptRegistry {

}

Purpose

PromptRegistry context or state structure.

Public fields

This type has no public fields.

struct FewShotExample

XuAPI
pub struct FewShotExample {
    pub input string
    pub output string
    pub embedding []f32
}

Purpose

Structure encapsulating input, output, embedding.

Public fields

input string
field (string)
output string
field (string)
embedding []f32
field ([]f32)

new_template

XuAPI
pub fn new_template(name string, version string, system_template string, user_template string, required_vars &[]string) PromptTemplate

Purpose

Construct template.

Parameters

name string
name (string)
version string
version (string)
system_template string
system_template (string)
user_template string
user_template (string)
required_vars &[]string
required_vars (read-only borrow; caller keeps the original; type &[]string)

Returns

PromptTemplate — a value of this type

render_template

XuAPI
pub fn render_template(tpl &string, vars &map[string]string, required &[]string) string

Purpose

Render template. Throws on failure; handle the error or propagate it to the caller.

Parameters

tpl &string
tpl (read-only borrow; caller keeps the original; type &string)
vars &map[string]string
vars (read-only borrow; caller keeps the original; type &map[string]string)
required &[]string
required (read-only borrow; caller keeps the original; type &[]string)

Returns

string — result string

new_registry

XuAPI
pub fn new_registry() PromptRegistry

Purpose

Construct registry.

Parameters

No arguments are required.

Returns

PromptRegistry — a value of this type

($&PromptRegistry) register

XuAPI
pub fn (r $&PromptRegistry) register(t PromptTemplate)

Purpose

Execute register on $&PromptRegistry.

Parameters

r $&PromptRegistry
The PromptRegistry instance used by this call (exclusive borrow).
t PromptTemplate
t (PromptTemplate)

Returns

This call does not return a value.

(&PromptRegistry) get

XuAPI
pub fn (r &PromptRegistry) get(name &string, version &string) PromptTemplate

Purpose

Execute get on &PromptRegistry. Throws on failure; handle the error or propagate it to the caller.

Parameters

r &PromptRegistry
The PromptRegistry instance used by this call (borrow).
name &string
name (read-only borrow; caller keeps the original; type &string)
version &string
version (read-only borrow; caller keeps the original; type &string)

Returns

PromptTemplate — a value of this type

(&PromptRegistry) render_messages

XuAPI
pub fn (r &PromptRegistry) render_messages(name &string, version &string, vars &map[string]string) []openai.Message

Purpose

Operation on &PromptRegistry: render messages. Throws on failure; handle the error or propagate it to the caller.

Parameters

r &PromptRegistry
The PromptRegistry instance used by this call (borrow).
name &string
name (read-only borrow; caller keeps the original; type &string)
version &string
version (read-only borrow; caller keeps the original; type &string)
vars &map[string]string
vars (read-only borrow; caller keeps the original; type &map[string]string)

Returns

[]openai.Message — slice result

(&PromptRegistry) list_names

XuAPI
pub fn (r &PromptRegistry) list_names() []string

Purpose

Operation on &PromptRegistry: list names.

Parameters

r &PromptRegistry
The PromptRegistry instance used by this call (borrow).

Returns

[]string — slice result

select_few_shot

XuAPI
pub fn select_few_shot(examples &[]FewShotExample, query_emb &[]f32, k int) []FewShotExample

Purpose

Select few shot.

Parameters

examples &[]FewShotExample
examples (read-only borrow; caller keeps the original; type &[]FewShotExample)
query_emb &[]f32
query_emb (read-only borrow; caller keeps the original; type &[]f32)
k int
key or index (int)

Returns

[]FewShotExample — slice result

format_few_shot_messages

XuAPI
pub fn format_few_shot_messages(system_prompt string, examples &[]FewShotExample, user_query string) []openai.Message

Purpose

Format as few shot messages.

Parameters

system_prompt string
system_prompt (string)
examples &[]FewShotExample
examples (read-only borrow; caller keeps the original; type &[]FewShotExample)
user_query string
user_query (string)

Returns

[]openai.Message — slice result

extract_json_block

XuAPI
pub fn extract_json_block(raw &string) string

Purpose

Extract json block. Throws on failure; handle the error or propagate it to the caller.

Parameters

raw &string
raw (read-only borrow; caller keeps the original; type &string)

Returns

string — result string