module LLM
Defined in:
llm/general/client.crllm/ollama/ollama.cr
llm/prompt.cr
Constant Summary
-
ANALYZE_FORMAT =
"{\n \"type\": \"json_schema\",\n \"json_schema\": {\n \"name\": \"analyze_endpoints\",\n \"schema\": {\n \"type\": \"object\",\n \"properties\": {\n \"endpoints\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"url\": {\n \"type\": \"string\"\n },\n \"method\": {\n \"type\": \"string\"\n },\n \"params\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n },\n \"param_type\": {\n \"type\": \"string\"\n },\n \"value\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\"name\", \"param_type\", \"value\"],\n \"additionalProperties\": false\n }\n }\n },\n \"required\": [\"url\", \"method\", \"params\"],\n \"additionalProperties\": false\n }\n }\n },\n \"required\": [\"endpoints\"],\n \"additionalProperties\": false\n },\n \"strict\": true\n }\n}"
-
ANALYZE_PROMPT =
"Analyze the provided source code to extract details about the endpoints and their parameters.\n\nGuidelines:\n- The \"method\" field should strictly use one of these values: \"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\", \"HEAD\".\n- The \"param_type\" must strictly use one of these values: \"query\", \"json\", \"form\", \"header\", \"cookie\", \"path\".\n- Do not include any explanations, comments, or additional text.\n- Output only the JSON result.\n- Return the result strictly in valid JSON format according to the schema provided below.\n\nInput Code:"
-
BUNDLE_ANALYZE_PROMPT =
"Analyze the following bundle of source code files to extract details about the endpoints and their parameters.\n\nGuidelines:\n- The \"method\" field should strictly use one of these values: \"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\", \"HEAD\".\n- The \"param_type\" must strictly use one of these values: \"query\", \"json\", \"form\", \"header\", \"cookie\", \"path\".\n- Include endpoints from ALL files in the bundle.\n- Do not include any explanations, comments, or additional text.\n- Output only the JSON result.\n- Return the result strictly in valid JSON format according to the schema provided below.\n\nBundle of files:"
-
FILTER_FORMAT =
"{\n \"type\": \"json_schema\",\n \"json_schema\": {\n \"name\": \"filter_files\",\n \"schema\": {\n \"type\": \"object\",\n \"properties\": {\n \"files\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n },\n \"required\": [\"files\"],\n \"additionalProperties\": false\n },\n \"strict\": true\n }\n}"
-
FILTER_PROMPT =
"Analyze the following list of file paths and identify which files are likely to represent endpoints, including API endpoints, web pages, or static resources.\n\nGuidelines:\n- Focus only on individual files.\n- Do not include directories.\n- Do not include any explanations, comments, or additional text.\n- Output only the JSON result.\n- Return the result strictly in valid JSON format according to the schema provided below.\n\nInput Files:"
-
MODEL_TOKEN_LIMITS =
{"openai" => {"gpt-3.5-turbo" => 16385, "gpt-3.5-turbo-16k" => 16385, "gpt-4" => 8192, "gpt-4-32k" => 32768, "gpt-4o" => 128000, "gpt-4o-mini" => 128000, "default" => 8000}, "xai" => {"grok-1" => 8192, "grok-2" => 131072, "grok-3" => 131072, "default" => 8000}, "anthropic" => {"claude-3-opus" => 200000, "claude-3-sonnet" => 200000, "claude-3-haiku" => 200000, "claude-2" => 100000, "default" => 100000}, "azure" => {"default" => 8000}, "github" => {"default" => 8000}, "ollama" => {"llama3" => 8192, "phi3" => 8192, "mistral" => 8192, "phi2" => 2048, "default" => 4000}, "vllm" => {"default" => 4000}, "lmstudio" => {"default" => 4000}, "default" => 4000}
-
Map of LLM providers and their models to their max token limits This helps determine how many files can be bundled together
Class Method Summary
-
.bundle_files(files : Array(Tuple(String, String)), max_tokens : Int32, safety_margin : Float64 = 0.8) : Array(Tuple(String, Int32))
Create a bundle of files that fits within token limits Returns the bundle content and the estimated token count
-
.estimate_tokens(text : String) : Int32
Estimate the number of tokens in a string This is a rough estimate using 1 token ≈ 4 characters for English text
-
.get_max_tokens(provider : String, model : String) : Int32
Get the maximum token limit for a given provider and model
Class Method Detail
def self.bundle_files(files : Array(Tuple(String, String)), max_tokens : Int32, safety_margin : Float64 = 0.8) : Array(Tuple(String, Int32))
#
Create a bundle of files that fits within token limits Returns the bundle content and the estimated token count
Estimate the number of tokens in a string This is a rough estimate using 1 token ≈ 4 characters for English text
Get the maximum token limit for a given provider and model