clients.openrouter #
openrouter
To get started
import freeflowuniverse.crystallib.clients. openrouter
mut client:= openrouter.get()!
client...
example heroscript
!!openrouter.configure
secret: '...'
host: 'localhost'
port: 8888
fn get #
fn get(args_ ArgsGet) !&OpenRouterClient
fn heroscript_default #
fn heroscript_default() !string
fn play #
fn play(args_ PlayArgs) !
fn play_openrouter #
fn play_openrouter(mut plbook playbook.PlayBook) !
fn switch #
fn switch(name string)
switch instance to be used for openrouter
fn (OpenAIClient[Config]) chat_completion #
fn (mut f OpenAIClient[Config]) chat_completion(model_type ModelType, msgs Messages) !ChatCompletion
creates a new chat completion given a list of messages each message consists of message content and the role of the author
struct ArgsGet #
@[params]
struct ArgsGet {
pub mut:
name string = 'default'
}
///////FACTORY
struct ChatCompletion #
struct ChatCompletion {
pub mut:
id string
object string
created u32
choices []Choice
usage Usage
}
struct Choice #
struct Choice {
pub mut:
index int
message MessageRaw
finish_reason string
}
struct CompletionRequest #
struct CompletionRequest {
pub mut:
model string
messages []Message
temperature f64 = 0.7
max_tokens int
// OpenRouter specific fields
transforms []string // optional
route string // optional
// Site info for rankings (optional)
http_referer string
http_user_agent string
}
CompletionRequest represents the request body for chat completions
struct CompletionResponse #
struct CompletionResponse {
pub mut:
id string
choices []Choice
created int
model string
usage Usage
system_fingerprint string
}
CompletionResponse represents the API response for chat completions
struct Message #
struct Message {
pub mut:
role RoleType
content string
}
struct MessageRaw #
struct MessageRaw {
pub mut:
role string
content string
}
struct Messages #
struct Messages {
pub mut:
messages []Message
}
struct OpenRouterClient #
@[heap]
struct OpenRouterClient {
pub mut:
name string = 'default'
openrouter_apikey string @[secret]
your_site_url string
your_site_name string
}
fn (OpenRouterClient) connection #
fn (mut client OpenRouterClient) connection() !&httpconnection.HTTPConnection
fn (OpenRouterClient) create_completion #
fn (mut client OpenRouterClient) create_completion(req CompletionRequest) !CompletionResponse
create_completion sends a completion request to OpenRouter API
struct PlayArgs #
@[params]
struct PlayArgs {
pub mut:
name string = 'default'
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
start bool
stop bool
restart bool
delete bool
configure bool // make sure there is at least one installed
}
struct Usage #
struct Usage {
pub mut:
prompt_tokens int
completion_tokens int
total_tokens int
}
- README
- fn get
- fn heroscript_default
- fn play
- fn play_openrouter
- fn switch
- type OpenAIClient[Config]
- struct ArgsGet
- struct ChatCompletion
- struct Choice
- struct CompletionRequest
- struct CompletionResponse
- struct Message
- struct MessageRaw
- struct Messages
- struct OpenRouterClient
- struct PlayArgs
- struct Usage