@promptline/sdk
v0.1.1
Published
Official SDK for building PromptLine applications
Maintainers
Readme
@promptline/sdk
Official SDK for building PromptLine applications.
Installation
npm install @promptline/sdkUsage
Vanilla JavaScript/TypeScript
import { createClient } from '@promptline/sdk'
const client = createClient({
apiKey: 'your-api-key'
})
// Initialize the client
await client.init()
// Execute an AI binding
const result = await client.execute('review_analyzer', {
variables: { review_text: 'Great product!' }
})
console.log(result.content)React
import { PromptLineProvider, usePromptLine } from '@promptline/sdk/react'
// Wrap your app with the provider
function App() {
return (
<PromptLineProvider
config={{ apiKey: process.env.PROMPTLINE_API_KEY! }}
loading={<div>Loading...</div>}
>
<MyComponent />
</PromptLineProvider>
)
}
// Use the hook in your components
function MyComponent() {
const { execute, content, isLoading, error } = usePromptLine({
binding: 'review_analyzer',
stream: true
})
const handleClick = async () => {
await execute({ review_text: 'Great product!' })
}
return (
<div>
<button onClick={handleClick} disabled={isLoading}>
Analyze
</button>
{content && <p>{content}</p>}
{error && <p>Error: {error.message}</p>}
</div>
)
}API Reference
createClient(config)
Creates a new PromptLine client.
config.apiKey(required): Your PromptLine API keyconfig.baseUrl(optional): Custom API base URLconfig.timeout(optional): Request timeout in milliseconds
client.init()
Initializes the client and fetches instance configuration. Must be called before using other methods.
client.execute(binding, options, signal?)
Executes an AI binding.
binding: The binding keyoptions.variables: Variables to pass to the bindingoptions.provider: Override the AI provideroptions.model: Override the modelsignal: Optional AbortSignal for cancellation
client.executeStream(binding, options, onChunk, signal?)
Executes an AI binding with streaming.
onChunk: Callback function called for each chunk
React Hooks
usePromptLine(options): Main hook for executing bindingsusePromptLineContext(): Access the PromptLine contextusePromptLineClient(): Get the client instance directly
License
MIT
