refactor: get rid of unnecessary serialization and deserialization
This commit is contained in:
@@ -78,18 +78,17 @@ class Captain::BaseEditorService
|
||||
"#{endpoint}/v1"
|
||||
end
|
||||
|
||||
def make_api_call(body)
|
||||
parsed_body = JSON.parse(body)
|
||||
instrumentation_params = build_instrumentation_params(parsed_body)
|
||||
def make_api_call(payload)
|
||||
instrumentation_params = build_instrumentation_params(payload)
|
||||
|
||||
instrument_llm_call(instrumentation_params) do
|
||||
execute_ruby_llm_request(parsed_body)
|
||||
execute_ruby_llm_request(payload)
|
||||
end
|
||||
end
|
||||
|
||||
def execute_ruby_llm_request(parsed_body)
|
||||
messages = parsed_body['messages']
|
||||
model = parsed_body['model']
|
||||
def execute_ruby_llm_request(payload)
|
||||
messages = payload['messages']
|
||||
model = payload['model']
|
||||
|
||||
Llm::Config.with_api_key(api_key, api_base: api_base) do |context|
|
||||
chat = context.chat(model: model)
|
||||
|
||||
@@ -33,7 +33,7 @@ class Captain::LabelSuggestionService < Captain::BaseEditorService
|
||||
},
|
||||
{ role: 'user', content: content }
|
||||
]
|
||||
}.to_json
|
||||
}
|
||||
end
|
||||
|
||||
def labels_with_messages
|
||||
|
||||
@@ -11,7 +11,7 @@ class Captain::ReplySuggestionService < Captain::BaseEditorService
|
||||
messages: [
|
||||
{ role: 'system', content: prompt_from_file('reply') }
|
||||
].concat(conversation_messages(in_array_format: true))
|
||||
}.to_json
|
||||
}
|
||||
end
|
||||
|
||||
def conversation_messages(in_array_format: false)
|
||||
|
||||
@@ -37,14 +37,14 @@ class Captain::RewriteService < Captain::BaseEditorService
|
||||
private
|
||||
|
||||
def call_llm_with_prompt(system_content, user_content = event['data']['content'])
|
||||
body = {
|
||||
payload = {
|
||||
model: GPT_MODEL,
|
||||
messages: [
|
||||
{ role: 'system', content: system_content },
|
||||
{ role: 'user', content: user_content }
|
||||
]
|
||||
}.to_json
|
||||
make_api_call(body)
|
||||
}
|
||||
make_api_call(payload)
|
||||
end
|
||||
|
||||
def render_liquid_template(template_content, variables = {})
|
||||
|
||||
@@ -12,7 +12,7 @@ class Captain::SummaryService < Captain::BaseEditorService
|
||||
{ role: 'system', content: prompt_from_file('summary') },
|
||||
{ role: 'user', content: conversation_messages }
|
||||
]
|
||||
}.to_json
|
||||
}
|
||||
end
|
||||
|
||||
def conversation_messages(in_array_format: false)
|
||||
|
||||
Reference in New Issue
Block a user