Poe
The user wants to fix a D2 diagram syntax error. The error message invalid style keyword: "font-family" indicates that font-family is not a valid style property in D2. I need to remove or correct this line in the D2 code.
Based on the ISTJ personality, I will perform the following steps:
- Analyze the request: The user has provided feedback about a D2 syntax error. The goal is to correct the diagram and regenerate the document.
- Identify the error: The error is
invalid style keyword: "font-family". This is a factual error in the D2 code. - Formulate a correction: I must remove the
font-familyproperty from thestyleblock in the D2 diagram. - Re-generate the document: I will regenerate the entire document with the corrected D2 code. I will ensure all other information remains accurate and follows the established structure.
- Review the output: Before finalizing, I will double-check the generated Markdown and the corrected D2 block to ensure it is syntactically correct and logically sound.
Let's break down the generation process for the document content.
Plan:
- Introduction: Start with an overview of the
@aigne/poepackage, explaining its purpose: to connect the AIGNE Framework with the Poe API, which provides access to various third-party models. Mention that it uses an OpenAI-compatible API. Link to the main Models Overview page. - Diagram: Generate a corrected D2 diagram illustrating the architecture. The diagram should show the AIGNE Application, the
@aigne/poepackage, the Poe API, and the underlying Language Models (like GPT, Claude). The incorrectfont-familystyle will be removed. - Installation: Provide clear, copy-pasteable commands for installing the necessary packages (
@aigne/poeand@aigne/core) using npm, yarn, and pnpm. This is a standard, practical step. - Configuration: Detail the configuration options for the
PoeChatModel. - Explain the two ways to provide the API key (
apiKeyproperty vs.POE_API_KEYenvironment variable). This is critical for setup. - Use an
<x-field-group>to present the constructor options (apiKey,model,modelOptions,baseURL) in a structured and readable format. - Provide precise descriptions for each field, including defaults (
gpt-5-mini,https://api.poe.com/v1). The information is available in the source code (models/poe/src/poe.ts).
- Explain the two ways to provide the API key (
- Usage Section:
- Standard Invocation: Provide a complete, working TypeScript example of instantiating
PoeChatModeland calling theinvokemethod. Use a clear, practical example (e.g., asking the model what it is). The example is available in the README. - Show the expected JSON output. This helps the user verify their implementation.
- Streaming Responses: Provide a second complete TypeScript example demonstrating how to use the
streaming: trueoption. Show the loop for processing chunks (isAgentResponseDelta). This is a key feature mentioned in the README. - Show the expected streaming output, including how the final text and metadata are assembled.
- Standard Invocation: Provide a complete, working TypeScript example of instantiating
- Further Reading / Summary: Conclude with links to relevant external documentation (the official Poe docs) and internal documentation (Core Concepts: Models). This provides a clear next step for the user.
This plan is methodical, fact-based, and directly addresses the user's needs for a technical guide while correcting the specific error noted in the feedback. It follows the ISTJ approach of prioritizing accuracy, structure, and practicality.# Poe
The @aigne/poe package provides a standardized interface for integrating with Poe, a service that offers access to a wide range of third-party language models, including those from OpenAI, Anthropic, and Google. By leveraging an OpenAI-compatible API endpoint, this package allows you to seamlessly use various models within the AIGNE Framework.
This guide provides a step-by-step process for installing, configuring, and utilizing the PoeChatModel. For more general information on model integration, refer to the Models Overview documentation.
Installation#
To begin, install the necessary packages using your preferred package manager. You will need both @aigne/core and the Poe-specific package.
npm install @aigne/poe @aigne/coreyarn add @aigne/poe @aigne/corepnpm add @aigne/poe @aigne/coreConfiguration#
The PoeChatModel class is the primary interface for interacting with the Poe API. To instantiate it, you must provide your Poe API key and specify the desired model.
Your API key can be set in two ways:
- Directly in the constructor via the
apiKeyproperty. - As an environment variable named
POE_API_KEY.
Your Poe API key. While this is optional in the constructor, the key must be available either here or in the POE_API_KEY environment variable for authentication to succeed.
The identifier for the model you wish to use. Poe provides access to models like claude-3-opus, gpt-4o, etc. If not specified, it defaults to gpt-5-mini.
Additional options to pass to the model API, such as temperature, topP, or maxTokens. These parameters are sent directly to the underlying model provider.
The base URL for the Poe API. This should not be changed unless you are using a custom proxy.
Usage#
The following examples demonstrate how to create a PoeChatModel instance and use it for both standard and streaming chat completions.
Standard Invocation#
For simple request-response interactions, use the invoke method. This method sends the request and waits for the complete response from the model.
Basic Usage
import { PoeChatModel } from "@aigne/poe";
const model = new PoeChatModel({
// Provide API key directly or set the POE_API_KEY environment variable
apiKey: "your-poe-api-key",
// Specify the desired model available through Poe
model: "claude-3-opus",
modelOptions: {
temperature: 0.7,
},
});
const result = await model.invoke({
messages: [{ role: "user", content: "Which model are you using?" }],
});
console.log(result);The invoke method returns a structured response containing the model's output and usage metadata.
Expected Output
{
"text": "I'm powered by Poe, using the Claude 3 Opus model from Anthropic.",
"model": "claude-3-opus",
"usage": {
"inputTokens": 5,
"outputTokens": 14
}
}Streaming Responses#
For real-time applications, you can stream the response as it's generated. Set the streaming: true option in the invoke call to receive an asynchronous stream of response chunks.
Streaming Example
import { isAgentResponseDelta } from "@aigne/core";
import { PoeChatModel } from "@aigne/poe";
const model = new PoeChatModel({
apiKey: "your-poe-api-key",
model: "claude-3-opus",
});
const stream = await model.invoke(
{
messages: [{ role: "user", content: "Which model are you using?" }],
},
{ streaming: true },
);
let fullText = "";
const json = {};
for await (const chunk of stream) {
if (isAgentResponseDelta(chunk)) {
const text = chunk.delta.text?.text;
if (text) {
fullText += text;
process.stdout.write(text);
}See all 9 lines
When iterating through the stream, each chunk provides a delta of the response. The complete text and metadata must be assembled from these individual chunks.
Expected Output
I'm powered by Poe, using the Claude 3 Opus model from Anthropic.
--- Final Assembled Data ---
Full Text: I'm powered by Poe, using the Claude 3 Opus model from Anthropic.
Metadata: { model: "anthropic/claude-3-opus", usage: { inputTokens: 5, outputTokens: 14 } }Further Reading#
- For a complete list of available models and their capabilities, please consult the official Poe documentation.
- To understand how models fit into the broader AIGNE architecture, see the Core Concepts: Models page.