Git Product home page Git Product logo

claude-sdk's Introduction

Claude API PHP SDK

This is a simple but useful PHP Class that you can use to communicate with Anthropic's Claude via API.

Installation

composer require dikki/claude-sdk

Usage

Creating an Instance

First, create an instance of the Claude class. Pass the API key as the first parameter. You can pass the model name as the second parameter or keep it empty to use the default model (claude-2.1).

$claude = new \Dikki\Claude\Claude($apiKey, 'claude-2.1');

Methods

getResponse

To get the whole response from Claude, use the getResponse() method. It accepts the following parameters:

  • string $prompt: The prompt to send to the API.
  • array $messages: Optional. The messages to send to the API.
  • string|null $model: Optional. The model to use for the API request.
  • int $maxTokens: Optional. The maximum number of tokens to generate (default is 4000).
  • string $method: Optional. The HTTP method to use for the request (default is 'POST').

Returns an array containing the full response, including text, model used, etc.

$response = $claude->getResponse("Write an essay on AI.");

getTextResponse

To get only the string response, use the getTextResponse() method. It accepts the same parameters as getResponse().

Returns a string response.

$response = $claude->getTextResponse("Write an essay on AI.");

Example Usage

// Create an instance of Claude
$claude = new \Dikki\Claude\Claude($apiKey, 'claude-2.1');

// Get full response
$response = $claude->getResponse("Write an essay on AI.");

// Get only text response
$textResponse = $claude->getTextResponse("Write an essay on AI.");

Class Overview

  • Class: Claude
  • Namespace: Dikki\Claude
  • Constructor Parameters:
    • string $apiKey: The API key for authentication.
    • string $model: The model to use for the API requests (default is 'claude-2.1').
    • string $modelVersion: The version of the model to use (default is '2023-06-01').

Additional Information

  • getEndpoint(): Returns the API endpoint URL.
  • prepareMessages(): Prepares the messages for the API request.
  • getHeaders(): Returns the headers for the API request.
  • getRequestBody(): Returns the request body for the API request.

claude-sdk's People

Contributors

namankumar80510 avatar

Stargazers

Nguyen Viet Hoang avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.