FEATURE: basic support for GPT-o models (#804)

Caveats

- No streaming, by design
- No tool support (including no XML tools)
- No vision

Open AI will revamt the model and more of these features may
become available.

This solution is a bit hacky for now
This commit is contained in:
Sam 2024-09-17 09:41:00 +10:00 committed by GitHub
parent 493d65af1f
commit 4b21eb7974
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -39,6 +39,11 @@ module DiscourseAi
llm_model.max_prompt_tokens - buffer
end
# no support for streaming or tools or system messages
def is_gpt_o?
llm_model.provider == "open_ai" && llm_model.name.include?("o1-")
end
private
def tools_dialect
@ -46,7 +51,11 @@ module DiscourseAi
end
def system_msg(msg)
{ role: "system", content: msg[:content] }
if is_gpt_o?
{ role: "user", content: msg[:content] }
else
{ role: "system", content: msg[:content] }
end
end
def model_msg(msg)

View File

@ -27,6 +27,17 @@ module DiscourseAi
AiApiAuditLog::Provider::OpenAI
end
def perform_completion!(dialect, user, model_params = {}, feature_name: nil, &blk)
if dialect.respond_to?(:is_gpt_o?) && dialect.is_gpt_o? && block_given?
# we need to disable streaming and simulate it
blk.call "", lambda { |*| }
response = super(dialect, user, model_params, feature_name: feature_name, &nil)
blk.call response, lambda { |*| }
else
super
end
end
private
def model_uri