-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename base executor to llama.cpp and added default config
- Loading branch information
Showing
11 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module ModelVersionsHelper | ||
DEFAULT_CONFIGURATION = { | ||
'openai' => '{"model":"gpt-3.5-turbo","temperature":0.5}', | ||
'ollama' => '{"model":"llama3.1"}', | ||
'llama' => '{"n_predict":500,"temperature":0.5,"stop":["<|end|>","<|user|>","<|assistant|>","<|endoftext|>","<|system|>"]}' | ||
}.freeze | ||
|
||
def default_configuration(executor_type) | ||
DEFAULT_CONFIGURATION[executor_type] || {}.to_json | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
const DEFAULT_CONFIGURATION = { | ||
openai: '{"model":"gpt-3.5-turbo","temperature":0.5}', | ||
ollama: '{"model":"llama3.1"}', | ||
llama: '{"n_predict":500,"temperature":0.5,"stop":["<|end|>","<|user|>","<|assistant|>","<|endoftext|>","<|system|>"]}' | ||
} | ||
|
||
export default class extends Controller { | ||
static targets = ["configurationField", "apiKeyField"] | ||
|
||
connect() { | ||
this.toggleConfiguration() | ||
} | ||
|
||
toggleConfiguration() { | ||
const executorType = this.element.querySelector('#executor_type_selector').value | ||
if (this.hasConfigurationFieldTarget) | ||
this.configurationFieldTarget.value = DEFAULT_CONFIGURATION[executorType] | ||
|
||
if (executorType == 'openai') | ||
this.apiKeyFieldTarget.style.display = "block" | ||
else | ||
this.apiKeyFieldTarget.style.display = "none" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
module Executors | ||
class Llama < Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'webmock/rspec' | ||
|
||
RSpec.describe Executors::Llama do | ||
describe '#call' do | ||
let(:model) { create(:model, url: 'http://example.com/model_endpoint') } | ||
let(:model_version) { create(:model_version, model:, configuration: { param: 'value' }) } | ||
let(:executor) { Executors::Base.new(model_version) } | ||
let(:prompt) { 'Test prompt' } | ||
|
||
context 'when HTTP request is successful' do | ||
before do | ||
stub_request(:post, 'http://example.com/model_endpoint') | ||
.with( | ||
body: '{"param":"value","prompt":"Test prompt"}', | ||
headers: { | ||
'Accept' => '*/*', | ||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type' => 'application/json', | ||
'User-Agent' => 'Ruby' | ||
} | ||
) | ||
.to_return(status: 200, body: '{"response": "Test response"}', headers: {}) | ||
end | ||
|
||
it 'returns a completed status with result on successful response' do | ||
expect(executor.call(prompt)).to eq({ status: :completed, result: '{"response": "Test response"}' }) | ||
end | ||
end | ||
|
||
context 'when HTTP request fails' do | ||
before do | ||
stub_request(:post, 'http://example.com/model_endpoint') | ||
.to_return(status: 500, body: 'Internal Server Error') | ||
end | ||
|
||
it 'returns a failed status' do | ||
expect(executor.call(prompt)).to eq({ status: :failed, result: 'Internal Server Error' }) | ||
end | ||
end | ||
|
||
context 'when HTTP request times out' do | ||
before do | ||
stub_request(:post, 'http://example.com/model_endpoint') | ||
.to_timeout | ||
end | ||
|
||
it 'returns a failed status' do | ||
expect(executor.call(prompt)).to eq({ result: { error: { message: 'execution expired' } }.to_json, status: :failed }) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters