mirror of
https://ghfast.top/https://github.com/discourse/discourse-ai.git
synced 2026-07-18 11:49:33 +08:00
This re-implements tool support in DiscourseAi::Completions::Llm #generate
Previously tool support was always returned via XML and it would be the responsibility of the caller to parse XML
New implementation has the endpoints return ToolCall objects.
Additionally this simplifies the Llm endpoint interface and gives it more clarity. Llms must implement
decode, decode_chunk (for streaming)
It is the implementers responsibility to figure out how to decode chunks, base no longer implements. To make this easy we ship a flexible json decoder which is easy to wire up.
Also (new)
Better debugging for PMs, we now have a next / previous button to see all the Llm messages associated with a PM
Token accounting is fixed for vllm (we were not correctly counting tokens)
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AiApiAuditLog < ActiveRecord::Base
|
|
belongs_to :post
|
|
belongs_to :topic
|
|
|
|
module Provider
|
|
OpenAI = 1
|
|
Anthropic = 2
|
|
HuggingFaceTextGeneration = 3
|
|
Gemini = 4
|
|
Vllm = 5
|
|
Cohere = 6
|
|
Ollama = 7
|
|
SambaNova = 8
|
|
end
|
|
|
|
def next_log_id
|
|
self.class.where("id > ?", id).where(topic_id: topic_id).order(id: :asc).pluck(:id).first
|
|
end
|
|
|
|
def prev_log_id
|
|
self.class.where("id < ?", id).where(topic_id: topic_id).order(id: :desc).pluck(:id).first
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: ai_api_audit_logs
|
|
#
|
|
# id :bigint not null, primary key
|
|
# provider_id :integer not null
|
|
# user_id :integer
|
|
# request_tokens :integer
|
|
# response_tokens :integer
|
|
# raw_request_payload :string
|
|
# raw_response_payload :string
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# topic_id :integer
|
|
# post_id :integer
|
|
# feature_name :string(255)
|
|
# language_model :string(255)
|
|
# feature_context :jsonb
|