Repository navigation
feat(genvm): update to v0.1.3 #1212
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
Changes from all commits
316e48f
18b583a
2144d91
5ae5dc8
46abfb2
50ab705
b79b70c
f7d4e95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "recommendations": [ | ||
| "sumneko.lua" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from enum import IntEnum | ||
| from enum import IntEnum, StrEnum | ||
| import typing | ||
|
|
||
|
|
||
| class Methods(IntEnum): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| local lib = require("lib-greyboxing") | ||
| local inspect = require("inspect") | ||
| local lib = require("lib-genvm") | ||
| local llm = require("lib-llm") | ||
|
|
||
| -- check https://github.com/genlayerlabs/genvm/blob/v0.1.2/executor/modules/implementation/scripting/llm-default.lua | ||
|
|
||
| -- Used to look up mock responses for testing | ||
| -- It returns the response that is linked to a substring of the message | ||
| function get_mock_response_from_table(table, message) | ||
| local function get_mock_response_from_table(table, message) | ||
| for key, value in pairs(table) do | ||
| if string.find(message, key) then | ||
| return value | ||
|
|
@@ -13,79 +14,97 @@ function get_mock_response_from_table(table, message) | |
| return "no match" | ||
| end | ||
|
|
||
| function just_in_backend(args, prompt, format) | ||
| local search_in = lib.select_backends_for(args, format) | ||
|
|
||
| lib.log{ args = args, prompt = prompt, format = format, search_in = search_in } | ||
|
|
||
| local handler = args.handler | ||
| local function just_in_backend(ctx, args, mapped_prompt) | ||
| ---@cast mapped_prompt MappedPrompt | ||
| ---@cast args LLMExecPromptPayload | LLMExecPromptTemplatePayload | ||
|
|
||
| -- Return mock response if it exists | ||
| if args.host_data and args.host_data.mock_response then | ||
| if args.payload then | ||
| if args.payload.principle then | ||
| -- Return the matching response to gl.eq_principle_prompt_comparative request which contains a principle key in the payload | ||
| result = get_mock_response_from_table(args.host_data.mock_response.eq_principle_prompt_comparative, prompt.user_message) | ||
| elseif args.payload.output then | ||
| -- Return the matching response to gl.eq_principle_prompt_non_comparative request which contains an output key in the payload | ||
| result = get_mock_response_from_table(args.host_data.mock_response.eq_principle_prompt_non_comparative, prompt.user_message) | ||
| else | ||
| -- Return the matching response to gl.exec_prompt request which does not contain any specific key in the payload | ||
| result = get_mock_response_from_table(args.host_data.mock_response.response, prompt.user_message) | ||
| end | ||
| if ctx.host_data.mock_response then | ||
|
kp2pml30 marked this conversation as resolved.
Resolved
|
||
| local result | ||
|
|
||
| if args.template == "EqComparative" then | ||
| -- Return the matching response to gl.eq_principle_prompt_comparative request which contains a principle key in the payload | ||
| result = get_mock_response_from_table(ctx.host_data.mock_response.eq_principle_prompt_comparative, mapped_prompt.prompt.user_message) | ||
| elseif args.template == "EqNonComparativeValidator" then | ||
| -- Return the matching response to gl.eq_principle_prompt_non_comparative request which contains an output key in the payload | ||
| result = get_mock_response_from_table(ctx.host_data.mock_response.eq_principle_prompt_non_comparative, mapped_prompt.prompt.user_message) | ||
| else | ||
| -- Return the matching response to gl.exec_prompt request which does not contain any specific key in the payload | ||
| -- EqNonComparativeLeader is essentially just exec_prompt | ||
| result = get_mock_response_from_table(ctx.host_data.mock_response.response, mapped_prompt.prompt.user_message) | ||
| end | ||
|
Comment on lines
+22
to
35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nil-guard optional mock-response tables
local sub = ctx.host_data.mock_response.eq_principle_prompt_comparative
if sub then
result = get_mock_response_from_table(sub, mapped_prompt.prompt.user_message)
endReplicate for the other branches. 🤖 Prompt for AI Agents |
||
| lib.log{level = "debug", message = "executed with", type = type(result), res = result} | ||
| return result | ||
| end | ||
|
|
||
| local provider_id = args.host_data.studio_llm_id | ||
| local model = lib.get_first_from_table(greyboxing.available_backends[provider_id].models).key | ||
| local provider_id = ctx.host_data.studio_llm_id | ||
| local model = lib.get_first_from_table(llm.providers[provider_id].models).key | ||
|
|
||
| prompt.use_max_completion_tokens = false | ||
| mapped_prompt.prompt.use_max_completion_tokens = false | ||
|
|
||
|
Comment on lines
+40
to
44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate provider / model resolution
assert(provider_id, "studio_llm_id not set in host data")
local provider = assert(llm.providers[provider_id], "unknown provider "..provider_id)
local first_model = lib.get_first_from_table(provider.models)
assert(first_model, "no models configured for provider "..provider_id)
local model = first_model.key🤖 Prompt for AI Agents |
||
| for i = 1,3 do | ||
| local request = { | ||
| provider = provider_id, | ||
| model = model, | ||
| prompt = mapped_prompt.prompt, | ||
| format = mapped_prompt.format, | ||
| } | ||
|
|
||
| local success, result = pcall(function () | ||
| return lib.exec_in_backend( | ||
| args.handler, | ||
| { | ||
| provider = provider_id, | ||
| model = model, | ||
| prompt = prompt, | ||
| format = format, | ||
| } | ||
| return llm.rs.exec_prompt_in_provider( | ||
| ctx, | ||
| request | ||
| ) | ||
| end) | ||
|
|
||
| lib.log{level = "debug", message = "executed with", type = type(result), res = result} | ||
| lib.log{level = "debug", message = "executed with", success = success, type = type(result), res = result} | ||
| if success then | ||
| return result | ||
| elseif result.kind == "Overloaded" then | ||
| -- nothing/continue | ||
| lib.log{level = "warning", message = "service is overloaded", result = result} | ||
| else | ||
| lib.log{level = "error", message = "provider failed", result = result} | ||
| end | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| local as_user_error = lib.rs.as_user_error(result) | ||
| if as_user_error == nil then | ||
| error(result) | ||
| end | ||
|
|
||
| lib.log{level = "error", message = "sleeping before retry"} | ||
| if llm.overloaded_statuses[as_user_error.ctx.status] then | ||
| lib.log{level = "warning", message = "service is overloaded", error = as_user_error, request = request} | ||
| else | ||
| lib.log{level = "error", message = "provider failed", error = as_user_error, request = request} | ||
| as_user_error.fatal = true | ||
|
|
||
| lib.rs.user_error(as_user_error) | ||
| end | ||
|
|
||
| lib.log{level = "warning", message = "sleeping before retry"} | ||
|
|
||
| lib.sleep_seconds(1.5) | ||
| lib.rs.sleep_seconds(1.5) | ||
| end | ||
|
|
||
| lib.rs.user_error({ | ||
| causes = {"NO_PROVIDER_FOR_PROMPT"}, | ||
| fatal = true, | ||
| ctx = { | ||
| prompt = mapped_prompt, | ||
| host_data = ctx.host_data, | ||
| } | ||
| }) | ||
| end | ||
|
|
||
| function exec_prompt(args) | ||
| local handler = args.handler | ||
| function ExecPrompt(ctx, args) | ||
| ---@cast args LLMExecPromptPayload | ||
|
|
||
| local mapped = lib.exec_prompt_transform(args) | ||
| local mapped = llm.exec_prompt_transform(args) | ||
|
|
||
| return just_in_backend(args, mapped.prompt, mapped.format) | ||
| return just_in_backend(ctx, args, mapped) | ||
| end | ||
|
|
||
| function exec_prompt_template(args) | ||
| local handler = args.handler | ||
| function ExecPromptTemplate(ctx, args) | ||
| ---@cast args LLMExecPromptTemplatePayload | ||
|
|
||
| local mapped = lib.exec_prompt_template_transform(args) | ||
| local template = args.template -- workaround by kp2pml30 (Kira) GVM-86 | ||
| local mapped = llm.exec_prompt_template_transform(args) | ||
| args.template = template | ||
|
|
||
| return just_in_backend(args, mapped.prompt, mapped.format) | ||
| return just_in_backend(ctx, args, mapped) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # { "Depends": "py-genlayer:test" } | ||
| # v0.1.0 | ||
| # { "Depends": "py-genlayer:latest" } | ||
|
|
||
| from genlayer import * | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # { "Depends": "py-genlayer:test" } | ||
| # v0.1.0 | ||
| # { "Depends": "py-genlayer:latest" } | ||
|
|
||
| from genlayer import * | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.