package ocaml-ai-sdk

  1. Overview
  2. Docs
OCaml AI SDK - Provider abstraction for AI models

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ocaml-ai-sdk-0.3.tbz
sha256=636d458cb1564ed88ca8c0250c432e91c2f822fd49ad2b923819e762bda10be6
sha512=361e476423ebc0f9cf561cc28ccd4531cf08e424e95eea43a67d6b8dbb457a49a25b418625ffa99f6327fc5df14e540e502d1aa8ed606111c5c010fe498eec2a

doc/ocaml-ai-sdk.ai_provider_anthropic/Ai_provider_anthropic/Convert_prompt/index.html

Module Ai_provider_anthropic.Convert_promptSource

Convert SDK prompts to Anthropic Messages API format.

Anthropic message content types.

Sourcetype image_source =
  1. | Base64_image of {
    1. media_type : string;
    2. data : string;
    }
  2. | Url_image of {
    1. url : string;
    }
Sourcetype document_source =
  1. | Base64_document of {
    1. media_type : string;
    2. data : string;
    }
Sourcetype anthropic_tool_result_content =
  1. | Tool_text of string
  2. | Tool_image of {
    1. source : image_source;
    }
Sourcetype anthropic_content =
  1. | A_text of {
    1. text : string;
    2. cache_control : Cache_control.t option;
    }
  2. | A_image of {
    1. source : image_source;
    2. cache_control : Cache_control.t option;
    }
  3. | A_document of {
    1. source : document_source;
    2. cache_control : Cache_control.t option;
    }
  4. | A_tool_use of {
    1. id : string;
    2. name : string;
    3. input : Yojson.Basic.t;
    }
  5. | A_tool_result of {
    1. tool_use_id : string;
    2. content : anthropic_tool_result_content list;
    3. is_error : bool;
    }
  6. | A_thinking of {
    1. thinking : string;
    2. signature : string;
    }
Sourcetype anthropic_message = {
  1. role : [ `User | `Assistant ];
  2. content : anthropic_content list;
}
Sourceval extract_system : Ai_provider.Prompt.message list -> string option * Ai_provider.Prompt.message list

Extract system messages (concatenated) and return remaining messages.

Sourceval convert_messages : Ai_provider.Prompt.message list -> anthropic_message list

Convert SDK messages to Anthropic format with message grouping for alternating user/assistant roles.

Sourceval anthropic_content_to_json : anthropic_content -> Yojson.Basic.t

Serialize a content block to JSON.

Sourceval anthropic_message_to_json : anthropic_message -> Yojson.Basic.t

Serialize a message to JSON.